public Geometry createGeometry ( Geometry geometry ) { if ( geometry instanceof Point ) { return createPoint ( geometry . getCoordinate ( ) ) ; } else if ( geometry instanceof LinearRing ) { return createLinearRing ( geometry . getCoordinates ( ) ) ; } else if ( geometry instanceof LineString ) { return createLineString ( geometry . getCoordinates ( ) ) ; } else if ( geometry instanceof Polygon ) { Polygon polygon = ( Polygon ) geometry ; LinearRing exteriorRing = createLinearRing ( polygon . getExteriorRing ( ) . getCoordinates ( ) ) ; LinearRing [ ] interiorRings = new LinearRing [ polygon . getNumInteriorRing ( ) ] ; for ( int n = 0 ; n < polygon . getNumInteriorRing ( ) ; n ++ ) { interiorRings [ n ] = createLinearRing ( polygon . getInteriorRingN ( n ) . getCoordinates ( ) ) ; } return new Polygon ( srid , precision , exteriorRing , interiorRings ) ; } else if ( geometry instanceof MultiPoint ) { Point [ ] clones = new Point [ geometry . getNumGeometries ( ) ] ; for ( int n = 0 ; n < geometry . getNumGeometries ( ) ; n ++ ) { clones [ n ] = createPoint ( geometry . getGeometryN ( n ) . getCoordinate ( ) ) ; } return new MultiPoint ( srid , precision , clones ) ; } else if ( geometry instanceof MultiLineString ) { LineString [ ] clones = new LineString [ geometry . getNumGeometries ( ) ] ; for ( int n = 0 ; n < geometry . getNumGeometries ( ) ; n ++ ) { clones [ n ] = createLineString ( geometry . getGeometryN ( n ) . getCoordinates ( ) ) ; } return new MultiLineString ( srid , precision , clones ) ; } else if ( geometry instanceof MultiPolygon ) { Polygon [ ] clones = new Polygon [ geometry . getNumGeometries ( ) ] ; for ( int n = 0 ; n < geometry . getNumGeometries ( ) ; n ++ ) { clones [ n ] = ( Polygon ) createGeometry ( geometry . getGeometryN ( n ) ) ; } return new MultiPolygon ( srid , precision , clones ) ; } return null ; }
Create a new geometry from an existing geometry . This will basically create a clone .