GeometryClean { public static Geometry removeDuplicateCoordinates(Geometry geom) { if (geom.isEmpty()) { return geom; } else if (geom instanceof Point || geom instanceof MultiPoint) { return geom; } else if (geom instanceof LineString) { return removeDuplicateCoordinates((LineString) geom); } else if (geom instanceof Polygon) { return removeDuplicateCoordinates((Polygon) geom); } else if (geom instanceof GeometryCollection) { return removeDuplicateCoordinates((GeometryCollection) geom); } return null; } private  GeometryClean(); static Polygon makeGoodShapePolygon(Polygon p); static MultiPolygon makeGoodShapeMultiPolygon(MultiPolygon mp); static Geometry removeDuplicateCoordinates(Geometry geom); static LineString removeDuplicateCoordinates(LineString g); static LinearRing removeDuplicateCoordinates(LinearRing g); static MultiLineString removeDuplicateCoordinates(MultiLineString g); static Polygon removeDuplicateCoordinates(Polygon poly); static MultiPolygon removeDuplicateCoordinates(MultiPolygon g); static GeometryCollection removeDuplicateCoordinates(GeometryCollection g);  }
@Test public void testRemoveDuplicateCoordinates() throws Exception { Geometry geom = wKTReader.read("LINESTRING(0 8, 1 8 , 3 8, 8 8, 10 8, 20 8)"); Geometry result = GeometryClean.removeDuplicateCoordinates(geom); assertEquals(result.getCoordinates().length, 6); geom = wKTReader.read("LINESTRING(0 8, 1 8 ,1 8, 3 8, 8 8, 10 8, 10 8, 20 8, 0 8)"); result = GeometryClean.removeDuplicateCoordinates(geom); assertEquals(result.getCoordinates().length, 7); geom = wKTReader.read("POINT(0 8)"); result = GeometryClean.removeDuplicateCoordinates(geom); assertEquals(result.getCoordinates().length, 1); geom = wKTReader.read("MULTIPOINT((0 8), (1 8))"); result = GeometryClean.removeDuplicateCoordinates(geom); assertEquals(result.getCoordinates().length, 2); geom = wKTReader.read("POLYGON (( 0 0, 10 0, 10 10 , 0 10, 0 0), (2 2, 7 2, 7 2, 7 7, 2 7, 2 2))"); result = GeometryClean.removeDuplicateCoordinates(geom); assertEquals(result.getCoordinates().length, 10); }