/** * Finds all {@link PreparedGeometry}s which intersect a given {@link Geometry} * * @param g the geometry to query by * @return a list of intersecting PreparedGeometrys */ public List intersects(Geometry g) { List result = new ArrayList(); List candidates = query(g); for (Iterator it = candidates.iterator(); it.hasNext(); ) { PreparedGeometry prepGeom = (PreparedGeometry) it.next(); if (prepGeom.intersects(g)) { result.add(prepGeom); } } return result; } }
public static void main(String[] args) throws Exception { Geometry circle = createCircle(); PreparedGeometry prepCircle = PreparedGeometryFactory.prepare(circle); int count = 0; int inCount = 0; for (int i = 0; i < MAX_ITER; i++) { count++; Point randPt = createRandomPoint(); if (prepCircle.intersects(randPt)) { inCount++; } //System.out.println("Approximation to PI: " + (4.0 * inCount / (double) count)); } double approxPi = 4.0 * inCount / (double) count; double approxDiffPct = 1.0 - approxPi/Math.PI; System.out.println("Approximation to PI: " + approxPi + " ( % difference from actual = " + 100 * approxDiffPct + " )" ); }
@Override public boolean evaluateInternal(Geometry left, Geometry right) { switch (literals) { case BOTH: return cacheValue; case RIGHT: { return rightPreppedGeom.intersects(left); } case LEFT: { return leftPreppedGeom.intersects(right); } default: { return basicEvaluate(left, right); } } }
/** * Tests if the given rectangle intersects with this ROI. * * @param rect the rectangle * @return {@code true} if there is an intersection; {@code false} otherwise */ @Override public boolean intersects(Rectangle rect) { setTestRect(rect.x, rect.y, rect.width, rect.height); return theGeom.intersects(testRect); }
/** * Tests if the given rectangle intersects with this ROI. * * @param rect the rectangle * @return {@code true} if there is an intersection; {@code false} otherwise */ @Override public boolean intersects(Rectangle2D rect) { setTestRect(rect.getMinX(), rect.getMinY(), rect.getWidth(), rect.getHeight()); return theGeom.intersects(testRect); }
@Override public boolean getCreateFeature(GridElement gridElement) { return boundary.intersects(gridElement.toGeometry()); } }
/** * Tests if the given rectangle intersects with this ROI. * * @param x rectangle origin X ordinate * @param y rectangle origin Y ordinate * @param w rectangle width * @param h rectangle height * @return {@code true} if there is an intersection; {@code false} otherwise */ @Override public boolean intersects(double x, double y, double w, double h) { setTestRect(x, y, w, h); return theGeom.intersects(testRect); }
/** * Tests if the given rectangle intersects with this ROI. * * @param x rectangle origin X ordinate * @param y rectangle origin Y ordinate * @param w rectangle width * @param h rectangle height * @return {@code true} if there is an intersection; {@code false} otherwise */ @Override public boolean intersects(int x, int y, int w, int h) { setTestRect(x, y, w, h); return theGeom.intersects(testRect); }
/** * Finds all {@link PreparedGeometry}s which intersect a given {@link Geometry} * * @param g the geometry to query by * @return a list of intersecting PreparedGeometrys */ public List intersects(Geometry g) { List result = new ArrayList(); List candidates = query(g); for (Iterator it = candidates.iterator(); it.hasNext(); ) { PreparedGeometry prepGeom = (PreparedGeometry) it.next(); if (prepGeom.intersects(g)) { result.add(prepGeom); } } return result; } }
public static void main(String[] args) throws Exception { Geometry circle = createCircle(); PreparedGeometry prepCircle = PreparedGeometryFactory.prepare(circle); int count = 0; int inCount = 0; for (int i = 0; i < MAX_ITER; i++) { count++; Point randPt = createRandomPoint(); if (prepCircle.intersects(randPt)) { inCount++; } //System.out.println("Approximation to PI: " + (4.0 * inCount / (double) count)); } double approxPi = 4.0 * inCount / (double) count; double approxDiffPct = 1.0 - approxPi/Math.PI; System.out.println("Approximation to PI: " + approxPi + " ( % difference from actual = " + 100 * approxDiffPct + " )" ); }
private boolean preppedEvaluate(PreparedGeometry prepped, Geometry other) { Envelope envLeft = prepped.getGeometry().getEnvelopeInternal(); Envelope envRight = other.getEnvelopeInternal(); if(envRight.intersects(envLeft)) { return prepped.intersects(other); } else { return false; } // Note that this is a pretty permissive logic // if the type has somehow been mis-set (can't happen externally) // then true is returned in all cases }
private boolean covers(BoundaryCortage up, PreparedGeometry preparedUpGeometry, PreparedGeometry preparedUpGeometryBuffer, BoundaryCortage dwn) { try { // fast if(preparedUpGeometry.covers(dwn.getGeometry())) { return true; } if(preparedUpGeometryBuffer == null) { Envelope env = dwn.getGeometry().getEnvelopeInternal(); double hypot = Math.hypot(env.getWidth(), env.getHeight()); double buffer = -(hypot * 0.005); return preparedUpGeometry.intersects(dwn.getGeometry().buffer(buffer)); } else { return preparedUpGeometryBuffer.intersects(dwn.getGeometry()); } } catch (Exception e) { return false; } }
protected SpatialRelation relate(Geometry oGeom) { //see http://docs.geotools.org/latest/userguide/library/jts/dim9.html#preparedgeometry if (oGeom instanceof com.vividsolutions.jts.geom.Point) { if (preparedGeometry != null) return preparedGeometry.disjoint(oGeom) ? SpatialRelation.DISJOINT : SpatialRelation.CONTAINS; return geom.disjoint(oGeom) ? SpatialRelation.DISJOINT : SpatialRelation.CONTAINS; } if (preparedGeometry == null) return intersectionMatrixToSpatialRelation(geom.relate(oGeom)); else if (preparedGeometry.covers(oGeom)) return SpatialRelation.CONTAINS; else if (preparedGeometry.coveredBy(oGeom)) return SpatialRelation.WITHIN; else if (preparedGeometry.intersects(oGeom)) return SpatialRelation.INTERSECTS; return SpatialRelation.DISJOINT; }
protected SpatialRelation relate(Geometry oGeom) { //see http://docs.geotools.org/latest/userguide/library/jts/dim9.html#preparedgeometry if (oGeom instanceof com.vividsolutions.jts.geom.Point) { if (preparedGeometry != null) return preparedGeometry.disjoint(oGeom) ? SpatialRelation.DISJOINT : SpatialRelation.CONTAINS; return geom.disjoint(oGeom) ? SpatialRelation.DISJOINT : SpatialRelation.CONTAINS; } if (preparedGeometry == null) return intersectionMatrixToSpatialRelation(geom.relate(oGeom)); else if (preparedGeometry.covers(oGeom)) return SpatialRelation.CONTAINS; else if (preparedGeometry.coveredBy(oGeom)) return SpatialRelation.WITHIN; else if (preparedGeometry.intersects(oGeom)) return SpatialRelation.INTERSECTS; return SpatialRelation.DISJOINT; }
private void writeFeature(IFeatureInserter featureWriter, Geometry geometry) throws IOException { if (boundsGeometry != null) { if (!boundsGeometry.intersects(geometry)) { return; } } if (boundsSource != null) { Filter filter = getIntersectsFilter(the_geom, geometry); if (boundsSource.subCollection(filter).isEmpty()) { return; } } SimpleFeature newFeature = featureWriter.buildFeature(); newFeature.setAttribute(UID, featureID); newFeature.setDefaultGeometry(geometry); featureWriter.write(newFeature); } }
if (preparedGeom.intersects(pixel)){ // pixel is at least partly inside the feature Geometry intersection = pixel.intersection(geometry); double denominator = relativeToPixels ? pixelAreaAtLat : area;
if (preparedGeom.intersects(pixel)){ // pixel is at least partly inside the feature Geometry intersection = pixel.intersection(geometry); double denominator = relativeToPixels ? pixelAreaAtLat : area;
geometry.getEnvelopeInternal()).iterator(); iter.hasNext();) { final NearFeature sample = iter.next(); if (prepared.intersects(sample.location)) { Geometry intersections = geometry.intersection(sample.location); intersections.apply(new GeometryComponentFilter() {
if (!boundsGeometry.intersects(geometry)) { currentX += diameter; continue;
if (!boundsGeometry.intersects(cellGeom)) { xpos += width; continue;