/** * 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)); }
/** * 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; }
/** * Converts a JTS Envelope into an equivalent {@link Rectangle2D} * * @param envelope The source envelope */ public static Rectangle2D toRectangle2D(Envelope envelope) { if (envelope == null) { return null; } return new Rectangle2D.Double( envelope.getMinX(), envelope.getMinY(), envelope.getWidth(), envelope.getHeight()); }
private boolean testReferencePoint(Envelope probeEnvelope, OGCGeometry buildGeometry, int partition) { Envelope buildEnvelope = getEnvelope(buildGeometry); Envelope intersection = buildEnvelope.intersection(probeEnvelope); if (intersection.isNull()) { return false; } Rectangle extent = partitions.get(partition); double x = intersection.getMinX(); double y = intersection.getMinY(); return x >= extent.getXMin() && x < extent.getXMax() && y >= extent.getYMin() && y < extent.getYMax(); }
Envelope env = g.getEnvelopeInternal(); if (!WORLD.contains(env)) { g = sanitizePolygons(g.intersection(JTS.toGeometry(WORLD))); if (Math.sqrt(env.getWidth() * env.getWidth() + env.getHeight() * env.getHeight()) >= 180) { for (double lon = Math.floor(env.getMinX()); lon < env.getMaxX(); lon += 90) { for (double lat = Math.floor(env.getMinY()); lat < env.getMaxY(); lat += 90) { Geometry quadrant = JTS.toGeometry(new Envelope(lon, lon + 90, lat, lat + 90)); Geometry cut = sanitizePolygons(g.intersection(quadrant)); if (!cut.isEmpty()) {
double maxx = Double.parseDouble(bboxValues[2].toString()); double maxy = Double.parseDouble(bboxValues[3].toString()); bbox = new Envelope(minx, maxx, miny, maxy);
shpWriter.writeHeaders(new Envelope(), shapeType, 0, 0); handler = shapeType.getShapeHandler(gf); guessShapeType = false; Envelope b = g.getEnvelopeInternal(); if (!b.isNull()) { bounds.expandToInclude(b);
Envelope getEnvelope(Filter filter) { Envelope result = originalBounds; if (filter instanceof And) { Envelope bounds = new Envelope(); for (Iterator iter = ((And) filter).getChildren().iterator(); iter.hasNext(); ) { Filter f = (Filter) iter.next(); Envelope e = getEnvelope(f); if (e == null) return null; else bounds.expandToInclude(e); } result = bounds; } else if (filter instanceof BinarySpatialOperator) { BinarySpatialOperator gf = (BinarySpatialOperator) filter; if (supportedFilterTypes.contains(gf.getClass())) { Expression lg = gf.getExpression1(); Expression rg = gf.getExpression2(); if (lg instanceof Literal) { Geometry g = (Geometry) ((Literal) lg).getValue(); if (rg instanceof PropertyName) result = g.getEnvelopeInternal(); } else if (rg instanceof Literal) { Geometry g = (Geometry) ((Literal) rg).getValue(); if (lg instanceof PropertyName) result = g.getEnvelopeInternal(); } } } return result.intersection(originalBounds); }
public SimpleFeatureCollection subCollection(Filter filter) { // split out the spatial part of the filter SpatialIndexFeatureCollection ret = new SpatialIndexFeatureCollection(schema); Envelope env = new Envelope(); env = (Envelope) filter.accept(ExtractBoundsFilterVisitor.BOUNDS_VISITOR, env); if (LOGGER.isLoggable(Level.FINEST) && Double.isInfinite(env.getWidth())) { LOGGER.fine("Found no spatial element in " + filter); LOGGER.fine("Just going to iterate"); } for (Iterator<SimpleFeature> iter = (Iterator<SimpleFeature>) index.query(env).iterator(); iter.hasNext(); ) { SimpleFeature sample = iter.next(); if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("Looking at " + sample); } if (filter.evaluate(sample)) { if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("accepting " + sample); } ret.add(sample); } } return ret; }
if (schema.getGeometryDescriptor() != null) { if (targetBBox != null && !targetBBox.isNull() && !targetBBox.intersects(envelope)) { geometry = SKIP; && envelope.getWidth() < simplificationDistance && envelope.getHeight() < simplificationDistance) { try {
private Envelope intersection(Envelope e1, Envelope e2) { Envelope r = e1.intersection(e2); if (r.getWidth() < 0) return null; if (r.getHeight() < 0) return null; return r; }
/** * Returns {@code true} if lengths along all dimension are zero. * * @since 2.4 */ public boolean isEmpty() { return super.isNull(); }
public BoundingBox getBounds() { // TODO: cache this value CoordinateReferenceSystem crs = featureType.getCoordinateReferenceSystem(); Envelope bounds = ReferencedEnvelope.create(crs); for (Object o : values) { if (o instanceof Geometry) { Geometry g = (Geometry) o; // TODO: check userData for crs... and ensure its of the same // crs as the feature type if (bounds.isNull()) { bounds.init(JTS.bounds(g, crs)); } else { bounds.expandToInclude(JTS.bounds(g, crs)); } } } return (BoundingBox) bounds; }
/** * Include the provided coordinates, expanding as necessary. * * @since 2.4 */ public void include(double x, double y) { super.expandToInclude(x, y); }
if (geomEnvelope.isNull()) { return null; if (bounds.contains(geomEnvelope)) { return g; } else if (!bounds.intersects(geomEnvelope)) { return null;
@Override public void filter(Geometry geom) { int cross; if (geom instanceof LineString) {//note: LinearRing extends LineString if (geom.getEnvelopeInternal().getWidth() < 180) return;//can't possibly cross the dateline cross = unwrapDateline((LineString) geom); } else if (geom instanceof Polygon) { if (geom.getEnvelopeInternal().getWidth() < 180) return;//can't possibly cross the dateline cross = unwrapDateline((Polygon) geom); } else { // The only other JTS subclass of Geometry is a Point, which can't cross anything. // If the geom is something custom, we don't know what else to do but return. return; } crossings[0] = Math.max(crossings[0], cross); } });//geom.apply()
/** Include the provided envelope, expanding as necessary. */ @Override public void expandToInclude(Envelope other) { if (other instanceof BoundingBox) { if (other.isNull()) { return; } BoundingBox bbox = (BoundingBox) other; ensureCompatibleReferenceSystem(bbox); expandToInclude(bbox.getLowerCorner()); expandToInclude(bbox.getUpperCorner()); } else { super.expandToInclude(other); } }