@Override public boolean visitGeometry( Geometry geom ) { if ( geom.getCoordinateSystem() != null && geom.getCoordinateDimension() != 1 ) { try { geom.getCoordinateSystem(); } catch ( Exception e ) { throw new IllegalArgumentException( e.getMessage() ); } } return true; }
@Override public ICRS getCoordinateSystem() { return getReferencedObject().getCoordinateSystem(); }
private void evaluateSrsNameForFeature( Feature feature, List<ICRS> queryCRS, String handle ) throws OWSException { Set<Geometry> geometries = new LinkedHashSet<Geometry>(); findFeaturesAndGeometries( feature, geometries, new LinkedHashSet<Feature>(), new LinkedHashSet<String>(), new LinkedHashSet<String>() ); for ( Geometry geometry : geometries ) { ICRS crs = geometry.getCoordinateSystem(); evaluateSrsName( crs, queryCRS, handle ); evaluateValidDomain( crs, geometry, handle ); } }
private static void exportGeometry( Geometry geometry, GMLStreamWriter gmlWriter ) throws XMLStreamException, UnknownCRSException, TransformationException { if ( geometry != null ) { gmlWriter.setOutputCrs( geometry.getCoordinateSystem() ); gmlWriter.write( geometry ); } }
/** * Creates a deep copy of the given {@link Geometry} object. * * @param geom * @return */ public static Geometry copyDeep( Geometry geom ) { // TODO implement this without JTS com.vividsolutions.jts.geom.Geometry jtsGeom = ( (AbstractDefaultGeometry) geom ).getJTSGeometry(); return ( (AbstractDefaultGeometry) geom ).createFromJTS( jtsGeom, geom.getCoordinateSystem() ); }
/** * Sets the {@link CRS} for all geometries contained in the given {@link Filter} that do not have crs information. * * @param filter * filter to process, must not be <code>null</code> * @param crs * crs to set, must not be <code>null</code> */ public static void setDefaultCRS( Filter filter, ICRS crs ) { for ( Geometry geom : getGeometries( filter ) ) { if ( geom.getCoordinateSystem() == null ) { // TODO propagate to deeper levels / change behavior of setCoordinateSystem() geom.setCoordinateSystem( crs ); } } }
private Geometry transformGeometry( Geometry value, GeometryTransformer transformer ) throws IllegalArgumentException, TransformationException { Geometry transformed = value; if ( transformed.getCoordinateSystem() == null ) { transformed.setCoordinateSystem( transformer.getTargetCRS() ); } else { transformed = linearizer.linearize( value, crit ); if ( !( transformed instanceof Point && transformed.getCoordinateDimension() == 1 ) ) { transformed = transformer.transform( transformed, transformed.getCoordinateSystem() ); } } return transformed; }
private void startGeometry( String localName, Geometry geometry ) throws XMLStreamException { writeStartElementWithNS( GML21NS, localName ); if ( geometry.getId() != null ) { referenceExportStrategy.addExportedId( geometry.getId() ); writer.writeAttribute( "gid", geometry.getId() ); } if ( outputCRS != null ) { writer.writeAttribute( "srsName", outputCRS.getAlias() ); } else if ( geometry.getCoordinateSystem() != null ) { ICRS coordinateSystem = geometry.getCoordinateSystem(); writer.writeAttribute( "srsName", coordinateSystem.getAlias() ); } }
Geometry inSource = geom; ICRS sourceCRS = validDomain.getCoordinateSystem(); if ( sourceCRS != null && geom.getCoordinateSystem() != null && !sourceCRS.equals( geom.getCoordinateSystem() ) ) { try { GeometryTransformer trans = new GeometryTransformer( sourceCRS );
private Geometry getCompatibleGeometry( Geometry literal ) throws SQLException { if ( crs == null ) { return literal; } Geometry transformedLiteral = literal; if ( literal != null ) { ICRS literalCRS = literal.getCoordinateSystem(); if ( literalCRS != null && !( crs.equals( literalCRS ) ) ) { LOG.debug( "Need transformed literal geometry for evaluation: " + literalCRS.getAlias() + " -> " + crs.getAlias() ); try { GeometryTransformer transformer = new GeometryTransformer( crs ); transformedLiteral = transformer.transform( literal ); } catch ( Throwable e ) { throw new SQLException( e.getMessage() ); } } } return transformedLiteral; }
private Geometry getCompatibleGeometry( Geometry literal ) throws SQLException { if ( crs == null ) { return literal; } Geometry transformedLiteral = literal; if ( literal != null ) { ICRS literalCRS = literal.getCoordinateSystem(); if ( literalCRS != null && !( crs.equals( literalCRS ) ) ) { LOG.debug( "Need transformed literal geometry for evaluation: " + literalCRS.getAlias() + " -> " + crs.getAlias() ); try { GeometryTransformer transformer = new GeometryTransformer( crs ); transformedLiteral = transformer.transform( literal ); } catch ( Exception e ) { throw new SQLException( e.getMessage(), e ); } } } return transformedLiteral; }
@Override public Geometry getIntersection( Geometry geometry ) { JTSGeometryPair jtsGeoms = JTSGeometryPair.createCompatiblePair( this, geometry ); ICRS crs = this.crs; if ( crs == null ) { crs = geometry.getCoordinateSystem(); } com.vividsolutions.jts.geom.Geometry jtsGeom = jtsGeoms.first.intersection( jtsGeoms.second ); return createFromJTS( jtsGeom, crs ); }
throws FilterEvaluationException { Geometry transformedLiteral = literal; ICRS paramCRS = param.getCoordinateSystem(); ICRS literalCRS = literal.getCoordinateSystem(); if ( literalCRS != null && !( paramCRS.equals( literalCRS ) ) ) { LOG.debug( "Need transformed literal geometry for evaluation: " + literalCRS.getAlias() + " -> "
/** * Returns a transformed version of the given {@link Geometry} in the specified CRS. * * @param literal * @param crs * @return transformed version of the geometry, never <code>null</code> * @throws FilterEvaluationException */ public static Geometry getCompatibleGeometry( Geometry literal, ICRS crs ) throws FilterEvaluationException { if ( crs == null ) { return literal; } Geometry transformedLiteral = literal; if ( literal != null ) { ICRS literalCRS = literal.getCoordinateSystem(); if ( literalCRS != null && !( crs.equals( literalCRS ) ) ) { LOG.debug( "Need transformed literal geometry for evaluation: " + literalCRS.getAlias() + " -> " + crs.getAlias() ); try { GeometryTransformer transformer = new GeometryTransformer( crs ); transformedLiteral = transformer.transform( literal ); } catch ( Exception e ) { throw new FilterEvaluationException( e.getMessage() ); } } } return transformedLiteral; }
/** * Calculates the points inside the geometry and inside the view port. First the passed geometry is clipped * by the view port. A multipolygon may result. For each of the polygon in this multipolygon one interior point * is created * * @param geom to create labels for, must not be <code>null</code> and in the same CRS as the viewPort * @return a MultiPoint with all calculated labels */ MultiPoint calculateInteriorPoints( final Geometry geom ) { if ( geom == null ) return null; Geometry clippedGeometry = clipGeometry( geom, viewPort ); List<Point> points = new ArrayList<Point>(); if ( clippedGeometry != null && clippedGeometry instanceof DefaultSurface ) { points.add( ( (DefaultSurface) clippedGeometry ).getInteriorPoint() ); } if ( clippedGeometry != null && clippedGeometry instanceof MultiPolygon ) { for ( Polygon p : ( (MultiPolygon) clippedGeometry ) ) { if ( p instanceof DefaultSurface ) { points.add( ( (DefaultSurface) p ).getInteriorPoint() ); } } } return new GeometryFactory().createMultiPoint( null, geom.getCoordinateSystem(), points ); }
ICRS source = sourceCRS; if ( source == null ) { source = geom.getCoordinateSystem();
private <T extends Geometry> T transformLinearized( T g ) { if ( g instanceof Surface ) { @SuppressWarnings("unchecked") T g2 = (T) transform( linearizer.linearize( (Surface) g, new NumPointsCriterion( 100 ) ) ); g2.setCoordinateSystem( g.getCoordinateSystem() ); return g2; } if ( g instanceof Curve ) { @SuppressWarnings("unchecked") T g2 = (T) transform( linearizer.linearize( (Curve) g, new NumPointsCriterion( 100 ) ) ); g2.setCoordinateSystem( g.getCoordinateSystem() ); return g2; } return null; }
@Override public Geometry inspect( Geometry geom ) throws GeometryInspectionException { ICRS crs = geom.getCoordinateSystem(); if ( crs != null ) { ICRS cs = crs; int csDim = cs.getDimension(); int coordDim = geom.getCoordinateDimension(); if ( csDim != coordDim ) { String msg = "Geometry is invalid. Dimensionality of coordinates (=" + coordDim + ") does not match dimensionality of CRS '" + crs.getAlias() + "' (=" + csDim + ")."; throw new GeometryInspectionException( msg ); } } return geom; }
private void startGeometry( String localName, Geometry geometry ) throws XMLStreamException, UnknownCRSException, TransformationException { GMLObjectType gmlType = geometry.getType(); if ( gmlType == null ) { writeStartElementWithNS( gmlNs, localName ); } else { QName elName = gmlType.getName(); writeStartElementWithNS( elName.getNamespaceURI(), elName.getLocalPart() ); } if ( geometry.getId() != null ) { referenceExportStrategy.addExportedId( geometry.getId() ); writeAttributeWithNS( gmlNs, "id", geometry.getId() ); } else if ( version == GML_32 && geometry.getId() == null ) { // in GML 3.2, a gml:id is required for every geometry writeAttributeWithNS( gmlNs, "id", "GEOMETRY_" + generateNewId() ); } if ( outputCRS != null ) { writer.writeAttribute( "srsName", outputCRS.getAlias() ); } else if ( geometry.getCoordinateSystem() != null ) { writer.writeAttribute( "srsName", geometry.getCoordinateSystem().getAlias() ); } exportStandardProps( geometry ); }
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; }