Geometry clipGeometry( final Geometry geom, Geometry clippingArea ) { if ( clippingArea != null && !clippingArea.contains( geom ) ) { try { Geometry clippedGeometry = clippingArea.getIntersection( geom ); if ( clippedGeometry == null ) { return null; } com.vividsolutions.jts.geom.Geometry jtsOrig = ( (AbstractDefaultGeometry) geom ).getJTSGeometry(); com.vividsolutions.jts.geom.Geometry jtsClipped = ( (AbstractDefaultGeometry) clippedGeometry ).getJTSGeometry(); if ( jtsOrig == jtsClipped ) { return geom; } if ( isInvertedOrientation( jtsOrig ) ) { return clippedGeometry; } return fixOrientation( clippedGeometry, clippedGeometry.getCoordinateSystem() ); } catch ( UnsupportedOperationException e ) { // use original geometry if intersection not supported by JTS return geom; } } return geom; }