SFSProfiler { public Geometry simplify( Geometry geometry ) { Geometry simplified = null; switch ( geometry.getGeometryType() ) { case COMPOSITE_GEOMETRY: { throw new UnsupportedOperationException( "Simplifying of composites is not implemented yet." ); } case ENVELOPE: { throw new UnsupportedOperationException( "Simplifying of envelopes is not implemented yet." ); } case MULTI_GEOMETRY: { simplified = simplify( (MultiGeometry<?>) geometry ); break; } case PRIMITIVE_GEOMETRY: { simplified = simplify( (GeometricPrimitive) geometry ); break; } } return simplified; } SFSProfiler( LinearizationCriterion crit ); Geometry simplify( Geometry geometry ); Geometry simplify( GeometricPrimitive geometry ); Point simplify( Point geometry ); LineString simplify( Curve geometry ); Geometry simplify( Surface geometry ); Solid simplify( Solid geometry ); @SuppressWarnings("unchecked") MultiGeometry<?> simplify( MultiGeometry<?> geometry );  }
@Test public void simplifyPoint() { Point original = fac.createPoint( null, 47.11, 23.09, CRSUtils.EPSG_4326 ); Point simplified = simplifier.simplify( original ); assertEquals( original.get0(), simplified.get0() ); assertEquals( original.get1(), simplified.get1() ); assertEquals( original.getCoordinateSystem(), simplified.getCoordinateSystem() ); }
@Test public void simplifyLineString() { Point p0 = fac.createPoint( null, 0.0, 0.0, CRSUtils.EPSG_4326 ); Point p1 = fac.createPoint( null, 1.0, 1.0, CRSUtils.EPSG_4326 ); Point p2 = fac.createPoint( null, 5.0, 5.0, CRSUtils.EPSG_4326 ); Point p3 = fac.createPoint( null, 10.0, 10.0, CRSUtils.EPSG_4326 ); LineString ls = fac.createLineString( null, CRSUtils.EPSG_4326, new PointsArray( p0, p1, p2, p3 ) ); LineString simplified = simplifier.simplify( ls ); assertEquals( 4, simplified.getControlPoints().size() ); assertEquals( 0.0, simplified.getControlPoints().get( 0 ).get0() ); assertEquals( 0.0, simplified.getControlPoints().get( 0 ).get1() ); assertEquals( 1.0, simplified.getControlPoints().get( 1 ).get0() ); assertEquals( 1.0, simplified.getControlPoints().get( 1 ).get1() ); assertEquals( 5.0, simplified.getControlPoints().get( 2 ).get0() ); assertEquals( 5.0, simplified.getControlPoints().get( 2 ).get1() ); assertEquals( 10.0, simplified.getControlPoints().get( 3 ).get0() ); assertEquals( 10.0, simplified.getControlPoints().get( 3 ).get1() ); }
@Test public void simplifyCurve1() { Point p0 = fac.createPoint( null, 0.0, 0.0, CRSUtils.EPSG_4326 ); Point p1 = fac.createPoint( null, 1.0, 1.0, CRSUtils.EPSG_4326 ); Point p2 = fac.createPoint( null, 5.0, 5.0, CRSUtils.EPSG_4326 ); Point p3 = fac.createPoint( null, 10.0, 10.0, CRSUtils.EPSG_4326 ); LineStringSegment segment = fac.createLineStringSegment( new PointsArray( p0, p1, p2, p3 ) ); Curve curve = fac.createCurve( null, CRSUtils.EPSG_4326, segment ); LineString simplified = simplifier.simplify( curve ); assertEquals( 4, simplified.getControlPoints().size() ); assertEquals( 0.0, simplified.getControlPoints().get( 0 ).get0() ); assertEquals( 0.0, simplified.getControlPoints().get( 0 ).get1() ); assertEquals( 1.0, simplified.getControlPoints().get( 1 ).get0() ); assertEquals( 1.0, simplified.getControlPoints().get( 1 ).get1() ); assertEquals( 5.0, simplified.getControlPoints().get( 2 ).get0() ); assertEquals( 5.0, simplified.getControlPoints().get( 2 ).get1() ); assertEquals( 10.0, simplified.getControlPoints().get( 3 ).get0() ); assertEquals( 10.0, simplified.getControlPoints().get( 3 ).get1() ); }
@Test public void simplifyCurve2() { Point p0 = fac.createPoint( null, 0.0, 0.0, CRSUtils.EPSG_4326 ); Point p1 = fac.createPoint( null, 1.0, 1.0, CRSUtils.EPSG_4326 ); Point p2 = fac.createPoint( null, 5.0, 5.0, CRSUtils.EPSG_4326 ); Point p3 = fac.createPoint( null, 10.0, 10.0, CRSUtils.EPSG_4326 ); Point p4 = fac.createPoint( null, 20.0, 20.0, CRSUtils.EPSG_4326 ); Point p5 = fac.createPoint( null, 30.0, 30.0, CRSUtils.EPSG_4326 ); LineStringSegment segment1 = fac.createLineStringSegment( new PointsArray( p0, p1, p2, p3 ) ); LineStringSegment segment2 = fac.createLineStringSegment( new PointsArray( p3, p4, p5 ) ); LineStringSegment segment3 = fac.createLineStringSegment( new PointsArray( p5, p0 ) ); Curve curve = fac.createCurve( null, CRSUtils.EPSG_4326, segment1, segment2, segment3 ); LineString simplified = simplifier.simplify( curve ); assertEquals( 7, simplified.getControlPoints().size() ); assertEquals( 0.0, simplified.getControlPoints().get( 0 ).get0() ); assertEquals( 0.0, simplified.getControlPoints().get( 0 ).get1() ); assertEquals( 1.0, simplified.getControlPoints().get( 1 ).get0() ); assertEquals( 1.0, simplified.getControlPoints().get( 1 ).get1() ); assertEquals( 5.0, simplified.getControlPoints().get( 2 ).get0() ); assertEquals( 5.0, simplified.getControlPoints().get( 2 ).get1() ); assertEquals( 10.0, simplified.getControlPoints().get( 3 ).get0() ); assertEquals( 10.0, simplified.getControlPoints().get( 3 ).get1() ); assertEquals( 20.0, simplified.getControlPoints().get( 4 ).get0() ); assertEquals( 20.0, simplified.getControlPoints().get( 4 ).get1() ); assertEquals( 30.0, simplified.getControlPoints().get( 5 ).get0() ); assertEquals( 30.0, simplified.getControlPoints().get( 5 ).get1() ); assertEquals( 0.0, simplified.getControlPoints().get( 6 ).get0() ); assertEquals( 0.0, simplified.getControlPoints().get( 6 ).get1() ); }
@Test public void simplifyCurve3() { Point p0 = fac.createPoint( null, 0.0, 0.0, CRSUtils.EPSG_4326 ); Point p1 = fac.createPoint( null, 1.0, 1.0, CRSUtils.EPSG_4326 ); Point p2 = fac.createPoint( null, 5.0, 5.0, CRSUtils.EPSG_4326 ); Point p3 = fac.createPoint( null, 10.0, 10.0, CRSUtils.EPSG_4326 ); Point p4 = fac.createPoint( null, 20.0, 22.0, CRSUtils.EPSG_4326 ); Point p5 = fac.createPoint( null, 30.0, 35.0, CRSUtils.EPSG_4326 ); LineStringSegment segment1 = fac.createLineStringSegment( new PointsArray( p0, p1, p2, p3 ) ); Arc segment2 = fac.createArc( p3, p4, p5 ); Curve curve = fac.createCurve( null, CRSUtils.EPSG_4326, segment1, segment2 ); LineString simplified = simplifier.simplify( curve ); assertEquals( POINTS_PER_ARC + 3, simplified.getControlPoints().size() ); assertEquals( 0.0, simplified.getControlPoints().get( 0 ).get0() ); assertEquals( 0.0, simplified.getControlPoints().get( 0 ).get1() ); assertEquals( 1.0, simplified.getControlPoints().get( 1 ).get0() ); assertEquals( 1.0, simplified.getControlPoints().get( 1 ).get1() ); assertEquals( 5.0, simplified.getControlPoints().get( 2 ).get0() ); assertEquals( 5.0, simplified.getControlPoints().get( 2 ).get1() ); assertEquals( 10.0, simplified.getControlPoints().get( 3 ).get0() ); assertEquals( 10.0, simplified.getControlPoints().get( 3 ).get1() ); assertEquals( 30.0, simplified.getEndPoint().get0() ); assertEquals( 35.0, simplified.getEndPoint().get1() ); }
@Test public void simplifyPolygon() { Point p0 = fac.createPoint( null, 0.0, 0.0, CRSUtils.EPSG_4326 ); Point p1 = fac.createPoint( null, 10.0, 0.0, CRSUtils.EPSG_4326 ); Point p2 = fac.createPoint( null, 10.0, 10.0, CRSUtils.EPSG_4326 ); Point p3 = fac.createPoint( null, 10.0, 10.0, CRSUtils.EPSG_4326 ); Point p4 = fac.createPoint( null, 0.0, 10.0, CRSUtils.EPSG_4326 ); Point p5 = fac.createPoint( null, 1.0, 1.0, CRSUtils.EPSG_4326 ); Point p6 = fac.createPoint( null, 1.0, 9.0, CRSUtils.EPSG_4326 ); Point p7 = fac.createPoint( null, 9.0, 9.0, CRSUtils.EPSG_4326 ); Point p8 = fac.createPoint( null, 9.0, 1.0, CRSUtils.EPSG_4326 ); Point p9 = fac.createPoint( null, 1.0, 10.0, CRSUtils.EPSG_4326 ); Ring exterior = fac.createLinearRing( null, CRSUtils.EPSG_4326, new PointsArray( p0, p1, p2, p3, p4 ) ); Ring interior = fac.createLinearRing( null, CRSUtils.EPSG_4326, new PointsArray( p5, p6, p7, p8, p9 ) ); Polygon polygon = fac.createPolygon( null, CRSUtils.EPSG_4326, exterior, Collections.singletonList( interior ) ); Polygon simplified = (Polygon) simplifier.simplify( polygon ); assertEquals( "POLYGON ((0.000000 0.000000,10.000000 0.000000,10.000000 10.000000,10.000000 10.000000,0.000000 10.000000),(1.000000 1.000000,1.000000 9.000000,9.000000 9.000000,9.000000 1.000000,1.000000 10.000000))", simplified.toString() ); }
@Test public void simplifySurface1() { Point p0 = fac.createPoint( null, 0.0, 0.0, CRSUtils.EPSG_4326 ); Point p1 = fac.createPoint( null, 10.0, 0.0, CRSUtils.EPSG_4326 ); Point p2 = fac.createPoint( null, 10.0, 10.0, CRSUtils.EPSG_4326 ); Point p3 = fac.createPoint( null, 10.0, 10.0, CRSUtils.EPSG_4326 ); Point p4 = fac.createPoint( null, 0.0, 10.0, CRSUtils.EPSG_4326 ); Point p5 = fac.createPoint( null, 1.0, 1.0, CRSUtils.EPSG_4326 ); Point p6 = fac.createPoint( null, 1.0, 9.0, CRSUtils.EPSG_4326 ); Point p7 = fac.createPoint( null, 9.0, 9.0, CRSUtils.EPSG_4326 ); Point p8 = fac.createPoint( null, 9.0, 1.0, CRSUtils.EPSG_4326 ); Point p9 = fac.createPoint( null, 1.0, 10.0, CRSUtils.EPSG_4326 ); LineStringSegment seg0 = fac.createLineStringSegment( new PointsArray( p0, p1, p2, p3, p4 ) ); LineStringSegment seg1 = fac.createLineStringSegment( new PointsArray( p5, p6, p7, p8, p9 ) ); Curve curve0 = fac.createCurve( null, CRSUtils.EPSG_4326, seg0 ); Curve curve1 = fac.createCurve( null, CRSUtils.EPSG_4326, seg1 ); Ring exteriorRing = fac.createRing( null, CRSUtils.EPSG_4326, Collections.singletonList( curve0 ) ); Ring interiorRing = fac.createRing( null, CRSUtils.EPSG_4326, Collections.singletonList( curve1 ) ); SurfacePatch patch0 = fac.createPolygonPatch( exteriorRing, Collections.singletonList( interiorRing ) ); Surface surface = fac.createSurface( null, Collections.singletonList( patch0 ), CRSUtils.EPSG_4326 ); Polygon simplified = (Polygon) simplifier.simplify( surface ); assertEquals( "POLYGON ((0.000000 0.000000,10.000000 0.000000,10.000000 10.000000,10.000000 10.000000,0.000000 10.000000),(1.000000 1.000000,1.000000 9.000000,9.000000 9.000000,9.000000 1.000000,1.000000 10.000000))", simplified.toString() ); }
@Test public void simplifySurface2() { Point p0 = fac.createPoint( null, 0.0, 0.0, CRSUtils.EPSG_4326 ); Point p1 = fac.createPoint( null, 10.0, 0.0, CRSUtils.EPSG_4326 ); Point p2 = fac.createPoint( null, 10.0, 10.0, CRSUtils.EPSG_4326 ); Point p3 = fac.createPoint( null, 10.0, 10.0, CRSUtils.EPSG_4326 ); Point p4 = fac.createPoint( null, 0.0, 10.0, CRSUtils.EPSG_4326 ); Point p5 = fac.createPoint( null, 1.0, 1.0, CRSUtils.EPSG_4326 ); Point p6 = fac.createPoint( null, 1.0, 9.0, CRSUtils.EPSG_4326 ); Point p7 = fac.createPoint( null, 9.0, 9.0, CRSUtils.EPSG_4326 ); Point p8 = fac.createPoint( null, 9.0, 1.0, CRSUtils.EPSG_4326 ); Point p9 = fac.createPoint( null, 1.0, 10.0, CRSUtils.EPSG_4326 ); Point p10 = fac.createPoint( null, 10.0, 0.0, CRSUtils.EPSG_4326 ); Point p11 = fac.createPoint( null, 20.0, 0.0, CRSUtils.EPSG_4326 ); Point p12 = fac.createPoint( null, 20.0, 10.0, CRSUtils.EPSG_4326 ); Point p13 = fac.createPoint( null, 20.0, 10.0, CRSUtils.EPSG_4326 ); Point p14 = fac.createPoint( null, 10.0, 10.0, CRSUtils.EPSG_4326 ); LineStringSegment seg0 = fac.createLineStringSegment( new PointsArray( p0, p1, p2, p3, p4 ) ); LineStringSegment seg1 = fac.createLineStringSegment( new PointsArray( p5, p6, p7, p8, p9 ) ); LineStringSegment seg2 = fac.createLineStringSegment( new PointsArray( p10, p11, p12, p13, p14 ) ); Curve curve0 = fac.createCurve( null, CRSUtils.EPSG_4326, seg0 ); Curve curve1 = fac.createCurve( null, CRSUtils.EPSG_4326, seg1 ); Curve curve2 = fac.createCurve( null, CRSUtils.EPSG_4326, seg2 ); Ring exteriorRing = fac.createRing( null, CRSUtils.EPSG_4326, Collections.singletonList( curve0 ) ); Ring interiorRing = fac.createRing( null, CRSUtils.EPSG_4326, Collections.singletonList( curve1 ) ); Ring exteriorRing2 = fac.createRing( null, CRSUtils.EPSG_4326, Collections.singletonList( curve2 ) ); SurfacePatch patch0 = fac.createPolygonPatch( exteriorRing, Collections.singletonList( interiorRing ) ); SurfacePatch patch1 = fac.createPolygonPatch( exteriorRing2, null ); List<SurfacePatch> patches = new ArrayList<SurfacePatch>(); patches.add( patch0 ); patches.add( patch1 ); Surface surface = fac.createSurface( null, patches, CRSUtils.EPSG_4326 ); MultiPolygon simplified = (MultiPolygon) simplifier.simplify( surface ); System.out.println( simplified ); assertEquals( "MULTIPOLYGON (((0.000000 0.000000,10.000000 0.000000,10.000000 10.000000,10.000000 10.000000,0.000000 10.000000),(1.000000 1.000000,1.000000 9.000000,9.000000 9.000000,9.000000 1.000000,1.000000 10.000000)),((10.000000 0.000000,20.000000 0.000000,20.000000 10.000000,20.000000 10.000000,10.000000 10.000000)))", simplified.toString() ); }
@Test public void simplifyMultiCurve() { Point p0 = fac.createPoint( null, 0.0, 0.0, CRSUtils.EPSG_4326 ); Point p1 = fac.createPoint( null, 1.0, 1.0, CRSUtils.EPSG_4326 ); Point p2 = fac.createPoint( null, 5.0, 5.0, CRSUtils.EPSG_4326 ); Point p3 = fac.createPoint( null, 10.0, 10.0, CRSUtils.EPSG_4326 ); Point p4 = fac.createPoint( null, 20.0, 22.0, CRSUtils.EPSG_4326 ); Point p5 = fac.createPoint( null, 30.0, 35.0, CRSUtils.EPSG_4326 ); LineString ls = fac.createLineString( null, CRSUtils.EPSG_4326, new PointsArray( p0, p1, p2, p3 ) ); LineStringSegment segment1 = fac.createLineStringSegment( new PointsArray( p0, p1, p2, p3 ) ); Arc segment2 = fac.createArc( p3, p4, p5 ); Curve curve = fac.createCurve( null, CRSUtils.EPSG_4326, segment1, segment2 ); List<Curve> memberCurves = new ArrayList<Curve>(); memberCurves.add( ls ); memberCurves.add( curve ); MultiCurve<?> multiCurve = fac.createMultiCurve( null, CRSUtils.EPSG_4326, memberCurves ); MultiLineString simplified = (MultiLineString) simplifier.simplify( multiCurve ); assertEquals( "MULTILINESTRING ((0.000000 0.000000,1.000000 1.000000,5.000000 5.000000,10.000000 10.000000),(0.000000 0.000000,1.000000 1.000000,5.000000 5.000000,10.000000 10.000000,12.317848 12.699677,14.612186 15.419362,16.882842 18.158850,19.129644 20.917935,21.352424 23.696410,23.551014 26.494065,25.725249 29.310690,27.874965 32.146073,30.000000 35.000000))", simplified.toString() ); }
@Test public void simplifyMultiSurface() { Point p0 = fac.createPoint( null, 0.0, 0.0, CRSUtils.EPSG_4326 ); Point p1 = fac.createPoint( null, 10.0, 0.0, CRSUtils.EPSG_4326 ); Point p2 = fac.createPoint( null, 10.0, 10.0, CRSUtils.EPSG_4326 ); Point p3 = fac.createPoint( null, 10.0, 10.0, CRSUtils.EPSG_4326 ); Point p4 = fac.createPoint( null, 0.0, 10.0, CRSUtils.EPSG_4326 ); Point p5 = fac.createPoint( null, 1.0, 1.0, CRSUtils.EPSG_4326 ); Point p6 = fac.createPoint( null, 1.0, 9.0, CRSUtils.EPSG_4326 ); Point p7 = fac.createPoint( null, 9.0, 9.0, CRSUtils.EPSG_4326 ); Point p8 = fac.createPoint( null, 9.0, 1.0, CRSUtils.EPSG_4326 ); Point p9 = fac.createPoint( null, 1.0, 10.0, CRSUtils.EPSG_4326 ); Point p10 = fac.createPoint( null, 10.0, 0.0, CRSUtils.EPSG_4326 ); Point p11 = fac.createPoint( null, 20.0, 0.0, CRSUtils.EPSG_4326 ); Point p12 = fac.createPoint( null, 20.0, 10.0, CRSUtils.EPSG_4326 ); Point p13 = fac.createPoint( null, 20.0, 10.0, CRSUtils.EPSG_4326 ); Point p14 = fac.createPoint( null, 10.0, 10.0, CRSUtils.EPSG_4326 ); LineStringSegment seg0 = fac.createLineStringSegment( new PointsArray( p0, p1, p2, p3, p4 ) ); LineStringSegment seg1 = fac.createLineStringSegment( new PointsArray( p5, p6, p7, p8, p9 ) ); LineStringSegment seg2 = fac.createLineStringSegment( new PointsArray( p10, p11, p12, p13, p14 ) ); Curve curve0 = fac.createCurve( null, CRSUtils.EPSG_4326, seg0 ); Curve curve1 = fac.createCurve( null, CRSUtils.EPSG_4326, seg1 ); Curve curve2 = fac.createCurve( null, CRSUtils.EPSG_4326, seg2 ); Ring exteriorRing = fac.createRing( null, CRSUtils.EPSG_4326, Collections.singletonList( curve0 ) ); Ring interiorRing = fac.createRing( null, CRSUtils.EPSG_4326, Collections.singletonList( curve1 ) ); Ring exteriorRing2 = fac.createRing( null, CRSUtils.EPSG_4326, Collections.singletonList( curve2 ) ); SurfacePatch patch0 = fac.createPolygonPatch( exteriorRing, Collections.singletonList( interiorRing ) ); SurfacePatch patch1 = fac.createPolygonPatch( exteriorRing2, null ); List<SurfacePatch> patches = new ArrayList<SurfacePatch>(); patches.add( patch0 ); patches.add( patch1 ); Surface surface = fac.createSurface( null, patches, CRSUtils.EPSG_4326 ); List<Surface> surfaces = new ArrayList<Surface>(); surfaces.add( surface ); surfaces.add( surface ); MultiSurface<?> multiSurface = fac.createMultiSurface( null, CRSUtils.EPSG_4326, surfaces ); MultiPolygon simplified = (MultiPolygon) simplifier.simplify( multiSurface ); System.out.println( simplified ); assertEquals( "MULTIPOLYGON (((0.000000 0.000000,10.000000 0.000000,10.000000 10.000000,10.000000 10.000000,0.000000 10.000000),(1.000000 1.000000,1.000000 9.000000,9.000000 9.000000,9.000000 1.000000,1.000000 10.000000)),((10.000000 0.000000,20.000000 0.000000,20.000000 10.000000,20.000000 10.000000,10.000000 10.000000)),((0.000000 0.000000,10.000000 0.000000,10.000000 10.000000,10.000000 10.000000,0.000000 10.000000),(1.000000 1.000000,1.000000 9.000000,9.000000 9.000000,9.000000 1.000000,1.000000 10.000000)),((10.000000 0.000000,20.000000 0.000000,20.000000 10.000000,20.000000 10.000000,10.000000 10.000000)))", simplified.toString() ); }