private Geometry cloneRecursively ( Geometry geometry ) { Geometry clone = new Geometry ( geometry . geometryType , geometry . srid , geometry . precision ) ; if ( geometry . getGeometries ( ) != null ) { Geometry [ ] geometryClones = new Geometry [ geometry . getGeometries ( ) . length ] ; for ( int i = 0 ; i < geometry . getGeometries ( ) . length ; i ++ ) { geometryClones [ i ] = cloneRecursively ( geometry . getGeometries ( ) [ i ] ) ; } clone . setGeometries ( geometryClones ) ; } if ( geometry . getCoordinates ( ) != null ) { Coordinate [ ] coordinateClones = new Coordinate [ geometry . getCoordinates ( ) . length ] ; for ( int i = 0 ; i < geometry . getCoordinates ( ) . length ; i ++ ) { coordinateClones [ i ] = ( Coordinate ) geometry . getCoordinates ( ) [ i ] . clone ( ) ; } clone . setCoordinates ( coordinateClones ) ; } return clone ; }
Recursive cloning of geometries .