@Test public void testCutGeometryCrossingValidArea() throws Exception { String wkb = "AAAAAAMAAAABAAAAIMBX4dme0ZBrwBBHY3zBphTAV9GcHhAtwMAKRti7qZ+AwFfQgOTrwUTACf2L\n" + "jG5AAMBX0vLFEfX8wAq1GbA7goDAV8UJiMU1/MAHPA1tlZ4AwFeuj65DdMjAAyjMe3bMAMBXc9vp\n" + "X9V8v/XZFFTLswDAVytuJlbfZL/btb3kSQgAwFcQKQ78CxQ9MAAAAAAAAMBZSreoXYG4vowviwAA\n" + "AADAWUvVvOkHnMAD+j4NI0sAwFjlAT80DDjAA9TAl2fugMBYg9muyzeowATuKNtAgoDAWGFB3LdZ\n" + "JMAGMd3VXb+AwFhJc+py+vDACDw/gWQHAMBYMRpZMQ2AwAuBh446e4DAWCkYEYQ22MANF6kb09cA\n" + "wFgg/h0uW3zAD6SUb7kgAMBYF6GYVzWAwBMR+WWpdEDAWBhD/wDaIMAW2xdMREiAwFgKqiyQ+gTA\n" + "Gix578FUgMBYA1s+gKpwwBsTo7wYhYDAV/qZDD5aYMAbwu+JuyoAwFfqj6KbhxTAHIrvGplNAMBX\n" + "4hOw7Jx0wBy+1+x/XkDAV9vVZESR7MAca5H4ZYHAwFfWkK/y7sDAG3TJ1EFXgMBX1+eqod08wBrq\n" + "ABEuC8DAV+jS2XIy3MAYBQgfRHnAwFfslYpsZkDAFphJ8XbhQMBX6mVp0arUwBOSV/ye1QDAV+HZ\n" + "ntGQa8AQR2N8waYU"; Geometry geometry = new WKBReader().read(Base64.decode(wkb)); CoordinateReferenceSystem lambertPolar = getLambertPolar(); ReferencedEnvelope renderingEnvelope = new ReferencedEnvelope( -14542204.652543461, 15480411.404320458, -18705497.11355389, 11278026.995319324, lambertPolar); ReferencedEnvelope validAreaBounds = new ReferencedEnvelope(-180, 180, 0, 90, DefaultGeographicCRS.WGS84); ProjectionHandler ph = new ProjectionHandler( DefaultGeographicCRS.WGS84, validAreaBounds, renderingEnvelope); Geometry preProcessed = ph.preProcess(geometry); assertNull(preProcessed); }
public Geometry preProcess(Geometry geometry) throws TransformException, FactoryException { if (validAreaBounds == null) return densify(geometry); if (noReprojection) { return densify(geometry); } Geometry mask; ReferencedEnvelope ge = new ReferencedEnvelope(geometry.getEnvelopeInternal(), geometryCRS); ReferencedEnvelope geWGS84 = ge.transform(WGS84, true); geWGS84.expandBy(EPS); if (validArea == null) { if (validAreaBounds.contains((Envelope) geWGS84)) { return densify(geometry); } ReferencedEnvelope envIntWgs84 = new ReferencedEnvelope(validAreaBounds.intersection(geWGS84), WGS84); if (envIntWgs84.getHeight() <= 0 || envIntWgs84.getWidth() <= 0) { if (validAreaBounds.contains( 180, (validAreaBounds.getMinY() + validAreaBounds.getMaxY()) / 2)) { ReferencedEnvelope translated = new ReferencedEnvelope(validAreaBounds); translated.translate(-360, 0); if (translated.contains((Envelope) geWGS84)) { return densify(geometry); } envIntWgs84 = translated.intersection(geWGS84); } else if (validAreaBounds.contains( -180, (validAreaBounds.getMinY() + validAreaBounds.getMaxY()) / 2)) { ReferencedEnvelope translated = new ReferencedEnvelope(validAreaBounds); translated.translate(360, 0); if (translated.contains((Envelope) geWGS84)) { return densify(geometry); } envIntWgs84 = translated.intersection(geWGS84); } if (envIntWgs84.getHeight() <= 0 || envIntWgs84.getWidth() <= 0) { return null; } } ReferencedEnvelope envInt = envIntWgs84.transform(geometryCRS, true); mask = JTS.toGeometry((Envelope) envInt); } else { if (validaAreaTester.contains(JTS.toGeometry(geWGS84))) { return densify(geometry); } ReferencedEnvelope envIntWgs84 = new ReferencedEnvelope(validAreaBounds.intersection(geWGS84), WGS84); if (envIntWgs84.isEmpty()) { return null; } Polygon polyIntWgs84 = JTS.toGeometry(envIntWgs84); Geometry maskWgs84 = intersect(validArea, polyIntWgs84, geometryCRS); if (maskWgs84 == null || maskWgs84.isEmpty()) { return null; } mask = JTS.transform(maskWgs84, CRS.findMathTransform(WGS84, geometryCRS)); } return densify(intersect(geometry, mask, geometryCRS)); }
ProjectionHandler { public Geometry preProcess(Geometry geometry) throws TransformException, FactoryException { if (validAreaBounds == null) return densify(geometry); if (noReprojection) { return densify(geometry); } Geometry mask; ReferencedEnvelope ge = new ReferencedEnvelope(geometry.getEnvelopeInternal(), geometryCRS); ReferencedEnvelope geWGS84 = ge.transform(WGS84, true); geWGS84.expandBy(EPS); if (validArea == null) { if (validAreaBounds.contains((Envelope) geWGS84)) { return densify(geometry); } ReferencedEnvelope envIntWgs84 = new ReferencedEnvelope(validAreaBounds.intersection(geWGS84), WGS84); if (envIntWgs84.getHeight() <= 0 || envIntWgs84.getWidth() <= 0) { if (validAreaBounds.contains( 180, (validAreaBounds.getMinY() + validAreaBounds.getMaxY()) / 2)) { ReferencedEnvelope translated = new ReferencedEnvelope(validAreaBounds); translated.translate(-360, 0); if (translated.contains((Envelope) geWGS84)) { return densify(geometry); } envIntWgs84 = translated.intersection(geWGS84); } else if (validAreaBounds.contains( -180, (validAreaBounds.getMinY() + validAreaBounds.getMaxY()) / 2)) { ReferencedEnvelope translated = new ReferencedEnvelope(validAreaBounds); translated.translate(360, 0); if (translated.contains((Envelope) geWGS84)) { return densify(geometry); } envIntWgs84 = translated.intersection(geWGS84); } if (envIntWgs84.getHeight() <= 0 || envIntWgs84.getWidth() <= 0) { return null; } } ReferencedEnvelope envInt = envIntWgs84.transform(geometryCRS, true); mask = JTS.toGeometry((Envelope) envInt); } else { if (validaAreaTester.contains(JTS.toGeometry(geWGS84))) { return densify(geometry); } ReferencedEnvelope envIntWgs84 = new ReferencedEnvelope(validAreaBounds.intersection(geWGS84), WGS84); if (envIntWgs84.isEmpty()) { return null; } Polygon polyIntWgs84 = JTS.toGeometry(envIntWgs84); Geometry maskWgs84 = intersect(validArea, polyIntWgs84, geometryCRS); if (maskWgs84 == null || maskWgs84.isEmpty()) { return null; } mask = JTS.transform(maskWgs84, CRS.findMathTransform(WGS84, geometryCRS)); } return densify(intersect(geometry, mask, geometryCRS)); } }
ProjectionHandler { public Geometry preProcess(Geometry geometry) throws TransformException, FactoryException { if (validAreaBounds == null) return densify(geometry); if (noReprojection) { return densify(geometry); } Geometry mask; ReferencedEnvelope ge = new ReferencedEnvelope(geometry.getEnvelopeInternal(), geometryCRS); ReferencedEnvelope geWGS84 = ge.transform(WGS84, true); geWGS84.expandBy(EPS); if (validArea == null) { if (validAreaBounds.contains((Envelope) geWGS84)) { return densify(geometry); } ReferencedEnvelope envIntWgs84 = new ReferencedEnvelope(validAreaBounds.intersection(geWGS84), WGS84); if (envIntWgs84.getHeight() <= 0 || envIntWgs84.getWidth() <= 0) { if (validAreaBounds.contains( 180, (validAreaBounds.getMinY() + validAreaBounds.getMaxY()) / 2)) { ReferencedEnvelope translated = new ReferencedEnvelope(validAreaBounds); translated.translate(-360, 0); if (translated.contains((Envelope) geWGS84)) { return densify(geometry); } envIntWgs84 = translated.intersection(geWGS84); } else if (validAreaBounds.contains( -180, (validAreaBounds.getMinY() + validAreaBounds.getMaxY()) / 2)) { ReferencedEnvelope translated = new ReferencedEnvelope(validAreaBounds); translated.translate(360, 0); if (translated.contains((Envelope) geWGS84)) { return densify(geometry); } envIntWgs84 = translated.intersection(geWGS84); } if (envIntWgs84.getHeight() <= 0 || envIntWgs84.getWidth() <= 0) { return null; } } ReferencedEnvelope envInt = envIntWgs84.transform(geometryCRS, true); mask = JTS.toGeometry((Envelope) envInt); } else { if (validaAreaTester.contains(JTS.toGeometry(geWGS84))) { return densify(geometry); } ReferencedEnvelope envIntWgs84 = new ReferencedEnvelope(validAreaBounds.intersection(geWGS84), WGS84); if (envIntWgs84.isEmpty()) { return null; } Polygon polyIntWgs84 = JTS.toGeometry(envIntWgs84); Geometry maskWgs84 = intersect(validArea, polyIntWgs84, geometryCRS); if (maskWgs84 == null || maskWgs84.isEmpty()) { return null; } mask = JTS.transform(maskWgs84, CRS.findMathTransform(WGS84, geometryCRS)); } return densify(intersect(geometry, mask, geometryCRS)); } ProjectionHandler(
            CoordinateReferenceSystem sourceCRS,
            Envelope validAreaBounds,
            ReferencedEnvelope renderingEnvelope);  ProjectionHandler(
            CoordinateReferenceSystem sourceCRS,
            Geometry validArea,
            ReferencedEnvelope renderingEnvelope); }
ProjectionHandler { public Geometry preProcess(Geometry geometry) throws TransformException, FactoryException { if (validAreaBounds == null) return densify(geometry); if (noReprojection) { return densify(geometry); } Geometry mask; ReferencedEnvelope ge = new ReferencedEnvelope(geometry.getEnvelopeInternal(), geometryCRS); ReferencedEnvelope geWGS84 = ge.transform(WGS84, true); geWGS84.expandBy(EPS); if (validArea == null) { if (validAreaBounds.contains((Envelope) geWGS84)) { return densify(geometry); } ReferencedEnvelope envIntWgs84 = new ReferencedEnvelope(validAreaBounds.intersection(geWGS84), WGS84); if (envIntWgs84.getHeight() <= 0 || envIntWgs84.getWidth() <= 0) { if (validAreaBounds.contains( 180, (validAreaBounds.getMinY() + validAreaBounds.getMaxY()) / 2)) { ReferencedEnvelope translated = new ReferencedEnvelope(validAreaBounds); translated.translate(-360, 0); if (translated.contains((Envelope) geWGS84)) { return densify(geometry); } envIntWgs84 = translated.intersection(geWGS84); } else if (validAreaBounds.contains( -180, (validAreaBounds.getMinY() + validAreaBounds.getMaxY()) / 2)) { ReferencedEnvelope translated = new ReferencedEnvelope(validAreaBounds); translated.translate(360, 0); if (translated.contains((Envelope) geWGS84)) { return densify(geometry); } envIntWgs84 = translated.intersection(geWGS84); } if (envIntWgs84.getHeight() <= 0 || envIntWgs84.getWidth() <= 0) { return null; } } ReferencedEnvelope envInt = envIntWgs84.transform(geometryCRS, true); mask = JTS.toGeometry((Envelope) envInt); } else { if (validaAreaTester.contains(JTS.toGeometry(geWGS84))) { return densify(geometry); } ReferencedEnvelope envIntWgs84 = new ReferencedEnvelope(validAreaBounds.intersection(geWGS84), WGS84); if (envIntWgs84.isEmpty()) { return null; } Polygon polyIntWgs84 = JTS.toGeometry(envIntWgs84); Geometry maskWgs84 = intersect(validArea, polyIntWgs84, geometryCRS); if (maskWgs84 == null || maskWgs84.isEmpty()) { return null; } mask = JTS.transform(maskWgs84, CRS.findMathTransform(WGS84, geometryCRS)); } return densify(intersect(geometry, mask, geometryCRS)); } ProjectionHandler(
            CoordinateReferenceSystem sourceCRS,
            Envelope validAreaBounds,
            ReferencedEnvelope renderingEnvelope);  ProjectionHandler(
            CoordinateReferenceSystem sourceCRS,
            Geometry validArea,
            ReferencedEnvelope renderingEnvelope); void setProjectionParameters(Map projectionParameters); ReferencedEnvelope getRenderingEnvelope(); CoordinateReferenceSystem getSourceCRS(); List<ReferencedEnvelope> getQueryEnvelopes(); ReferencedEnvelope getProjectedEnvelope(
            ReferencedEnvelope envelope, CoordinateReferenceSystem targetCRS); boolean requiresProcessing(Geometry geometry); Geometry preProcess(Geometry geometry); MathTransform getRenderingTransform(MathTransform mt); Geometry postProcess(MathTransform mt, Geometry geometry); ReferencedEnvelope getValidAreaBounds(); }
ProjectionHandler { public Geometry preProcess(Geometry geometry) throws TransformException, FactoryException { if (validAreaBounds == null) return densify(geometry); if (noReprojection) { return densify(geometry); } Geometry mask; ReferencedEnvelope ge = new ReferencedEnvelope(geometry.getEnvelopeInternal(), geometryCRS); ReferencedEnvelope geWGS84 = ge.transform(WGS84, true); geWGS84.expandBy(EPS); if (validArea == null) { if (validAreaBounds.contains((Envelope) geWGS84)) { return densify(geometry); } ReferencedEnvelope envIntWgs84 = new ReferencedEnvelope(validAreaBounds.intersection(geWGS84), WGS84); if (envIntWgs84.getHeight() <= 0 || envIntWgs84.getWidth() <= 0) { if (validAreaBounds.contains( 180, (validAreaBounds.getMinY() + validAreaBounds.getMaxY()) / 2)) { ReferencedEnvelope translated = new ReferencedEnvelope(validAreaBounds); translated.translate(-360, 0); if (translated.contains((Envelope) geWGS84)) { return densify(geometry); } envIntWgs84 = translated.intersection(geWGS84); } else if (validAreaBounds.contains( -180, (validAreaBounds.getMinY() + validAreaBounds.getMaxY()) / 2)) { ReferencedEnvelope translated = new ReferencedEnvelope(validAreaBounds); translated.translate(360, 0); if (translated.contains((Envelope) geWGS84)) { return densify(geometry); } envIntWgs84 = translated.intersection(geWGS84); } if (envIntWgs84.getHeight() <= 0 || envIntWgs84.getWidth() <= 0) { return null; } } ReferencedEnvelope envInt = envIntWgs84.transform(geometryCRS, true); mask = JTS.toGeometry((Envelope) envInt); } else { if (validaAreaTester.contains(JTS.toGeometry(geWGS84))) { return densify(geometry); } ReferencedEnvelope envIntWgs84 = new ReferencedEnvelope(validAreaBounds.intersection(geWGS84), WGS84); if (envIntWgs84.isEmpty()) { return null; } Polygon polyIntWgs84 = JTS.toGeometry(envIntWgs84); Geometry maskWgs84 = intersect(validArea, polyIntWgs84, geometryCRS); if (maskWgs84 == null || maskWgs84.isEmpty()) { return null; } mask = JTS.transform(maskWgs84, CRS.findMathTransform(WGS84, geometryCRS)); } return densify(intersect(geometry, mask, geometryCRS)); } ProjectionHandler(
            CoordinateReferenceSystem sourceCRS,
            Envelope validAreaBounds,
            ReferencedEnvelope renderingEnvelope);  ProjectionHandler(
            CoordinateReferenceSystem sourceCRS,
            Geometry validArea,
            ReferencedEnvelope renderingEnvelope); void setProjectionParameters(Map projectionParameters); ReferencedEnvelope getRenderingEnvelope(); CoordinateReferenceSystem getSourceCRS(); List<ReferencedEnvelope> getQueryEnvelopes(); ReferencedEnvelope getProjectedEnvelope(
            ReferencedEnvelope envelope, CoordinateReferenceSystem targetCRS); boolean requiresProcessing(Geometry geometry); Geometry preProcess(Geometry geometry); MathTransform getRenderingTransform(MathTransform mt); Geometry postProcess(MathTransform mt, Geometry geometry); ReferencedEnvelope getValidAreaBounds(); static final String ADVANCED_PROJECTION_DENSIFY; }