@Override public String toString(Geometry value) { return value.toText(); }
@Override public int compare(Polygon o1, Polygon o2) { return o2.getNumPoints() - o1.getNumPoints(); } });
/** * Converts the specified {@code Envelope} to a {@code Polygon} having the specified srid. * * @param env The envelope to convert * @param srid The srid for the polygon * * @return The Polygon */ public static Polygon toPolygon(Envelope env, int srid) { final Coordinate[] coords = new Coordinate[5]; coords[0] = new Coordinate( env.getMinX(), env.getMinY() ); coords[1] = new Coordinate( env.getMinX(), env.getMaxY() ); coords[2] = new Coordinate( env.getMaxX(), env.getMaxY() ); coords[3] = new Coordinate( env.getMaxX(), env.getMinY() ); coords[4] = new Coordinate( env.getMinX(), env.getMinY() ); final LinearRing shell = geomFactory.createLinearRing( coords ); final Polygon pg = geomFactory.createPolygon( shell, null ); pg.setSRID( srid ); return pg; }
private static void writeEnvelope(Geometry geometry, SliceOutput output) { if (geometry.isEmpty()) { for (int i = 0; i < 4; i++) { output.writeDouble(NaN); } return; } Envelope envelope = geometry.getEnvelopeInternal(); output.writeDouble(envelope.getMinX()); output.writeDouble(envelope.getMinY()); output.writeDouble(envelope.getMaxX()); output.writeDouble(envelope.getMaxY()); }
/** * Get the union. * * @param r the other geometry * @return the union of this geometry envelope and another geometry envelope */ public Value getEnvelopeUnion(ValueGeometry r) { GeometryFactory gf = new GeometryFactory(); Envelope mergedEnvelope = new Envelope(getGeometryNoCopy().getEnvelopeInternal()); mergedEnvelope.expandToInclude(r.getGeometryNoCopy().getEnvelopeInternal()); return get(gf.toGeometry(mergedEnvelope)); }
private static Geometry readEnvelope(SliceInput input) { verify(input.available() > 0); double xMin = input.readDouble(); double yMin = input.readDouble(); double xMax = input.readDouble(); double yMax = input.readDouble(); Coordinate[] coordinates = new Coordinate[5]; coordinates[0] = new Coordinate(xMin, yMin); coordinates[1] = new Coordinate(xMin, yMax); coordinates[2] = new Coordinate(xMax, yMax); coordinates[3] = new Coordinate(xMax, yMin); coordinates[4] = coordinates[0]; return GEOMETRY_FACTORY.createPolygon(coordinates); }
private boolean testVerticesEquality(Geometry geom1, Geometry geom2) { if ( geom1.getNumPoints() != geom2.getNumPoints() ) { return false; } for ( int i = 0; i < geom1.getNumPoints(); i++ ) { Coordinate cn1 = geom1.getCoordinates()[i]; Coordinate cn2 = geom2.getCoordinates()[i]; if ( !cn1.equals2D( cn2 ) ) { return false; } } return true; } }
private static Point readPoint(SliceInput input) { Coordinate coordinates = readCoordinate(input); if (isNaN(coordinates.x) || isNaN(coordinates.y)) { return GEOMETRY_FACTORY.createPoint(); } return GEOMETRY_FACTORY.createPoint(coordinates); }
/** * Test if this geometry envelope intersects with the other geometry * envelope. * * @param r the other geometry * @return true if the two overlap */ public boolean intersectsBoundingBox(ValueGeometry r) { // the Geometry object caches the envelope return getGeometryNoCopy().getEnvelopeInternal().intersects( r.getGeometryNoCopy().getEnvelopeInternal()); }
private static Geometry readMultiPoint(SliceInput input) { skipEsriType(input); skipEnvelope(input); int pointCount = input.readInt(); Point[] points = new Point[pointCount]; for (int i = 0; i < pointCount; i++) { points[i] = readPoint(input); } return GEOMETRY_FACTORY.createMultiPoint(points); }
/** * Two geometries are equal iff both have the same SRID, or both are unknown (i.e. a SRID of 0 or -1). * * @param geom1 * @param geom2 * * @return */ private boolean equalSRID(Geometry geom1, Geometry geom2) { return geom1.getSRID() == geom2.getSRID() || ( geom1.getSRID() < 1 && geom2.getSRID() < 1 ); }
/** * Performs an operation on a coordinate in a CoordinateSequence. * * @param coordinateSequence the object to which the filter is applied * @param i the index of the coordinate to apply the filter to */ @Override public void filter(CoordinateSequence coordinateSequence, int i) { if (!Double.isNaN(coordinateSequence.getOrdinate(i, 2))) { foundZ = true; } }
private boolean testVerticesEquality(Geometry geom1, Geometry geom2) { if ( geom1.getNumPoints() != geom2.getNumPoints() ) { return false; } for ( int i = 0; i < geom1.getNumPoints(); i++ ) { Coordinate cn1 = geom1.getCoordinates()[i]; Coordinate cn2 = geom2.getCoordinates()[i]; if ( !cn1.equals2D( cn2 ) ) { return false; } } return true; } }
@Override protected NativeSQLStatement createNativeCrossesStatement(Geometry geom) { return createNativeSQLStatementAllWKTParams( "select t.id, ST_Crosses(t.geom, ST_GeomFromText(?, 4326)) from GEOMTEST t where ST_Crosses(t.geom, ST_GeomFromText(?, 4326)) = 1 and ST_SRID(t.geom) = 4326", geom.toText() ); }
@Override protected NativeSQLStatement createNativeGeomUnionStatement(Geometry geom) { return createNativeSQLStatementAllWKTParams( "select t.id, ST_Union(t.geom, ST_GeomFromText(?, 4326)) from GEOMTEST t where ST_SRID(t.geom) = 4326", geom.toText() ); }
@Override protected NativeSQLStatement createNativeTouchesStatement(Geometry geom) { return createNativeSQLStatementAllWKTParams( "select t.id, DB2GSE.ST_touches(t.geom, DB2GSE.ST_GeomFromText(?, 4326)) from GeomTest t where DB2GSE.ST_touches(t.geom, DB2GSE.ST_geomFromText(?, 4326)) = 1 and db2gse.st_srid(t.geom) = 4326", geom.toText() ); }
@Override protected NativeSQLStatement createNativeOverlapsStatement(Geometry geom) { return createNativeSQLStatementAllWKTParams( "select t.id, DB2GSE.ST_overlaps(t.geom, DB2GSE.ST_GeomFromText(?, 4326)) from GeomTest t where DB2GSE.ST_overlaps(t.geom, DB2GSE.ST_GeomFromText(?, 4326)) = 1 and db2gse.st_srid(t.geom) = 4326", geom.toText() ); }
@Override protected NativeSQLStatement createNativeDifferenceStatement(Geometry geom) { return createNativeSQLStatementAllWKTParams( "select t.id, DB2GSE.ST_difference(t.geom, DB2GSE.ST_GeomFromText(?, 4326)) from GeomTest t where DB2GSE.ST_SRID(t.geom) = 4326", geom.toText() ); }
@Override protected NativeSQLStatement createNativeWithinStatement(Geometry geom) { return createNativeSQLStatementAllWKTParams( "select t.id, DB2GSE.ST_within(t.geom, DB2GSE.ST_GeomFromText(?, 4326)) from GeomTest t where DB2GSE.ST_within(t.geom, DB2GSE.ST_GeomFromText(?, 4326)) = 1 and db2gse.st_srid(t.geom) = 4326", geom.toText() ); }