Refine search
public static Point getRandomPointInGeometry(final PreparedGeometry geometry) { return getRandomPointInEnvelope(p -> geometry.contains(p), geometry.getGeometry().getEnvelopeInternal()); }
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 }
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; }
for (int index = 0; index < triangleGeoms.getNumGeometries(); index++) { Geometry triangle = triangleGeoms.getGeometryN(index); if (triangle == null || triangle.isEmpty()) { continue; if (praparedGeom.disjoint(triangle)) { continue; } else {
clipPolygon = gf.toGeometry(clipEnvelope); } else { clipEnvelope = new ReferencedEnvelope(clipArea.getEnvelopeInternal(), crs); for (int k = 0; k < thiessenGeoms.getNumGeometries(); k++) { Geometry geometry = thiessenGeoms.getGeometryN(k); spatialIndex.insert(geometry.getEnvelopeInternal(), geometry); Geometry finalVoronoi = voronoiPolygon; if (praparedGeom.disjoint(voronoiPolygon)) { continue; } else if (!praparedGeom.contains(voronoiPolygon)) { finalVoronoi = voronoiPolygon.intersection(clipPolygon); if (finalVoronoi == null || finalVoronoi.isEmpty()) {
GeometryFactory factory = source.getFactory(); for (@SuppressWarnings("unchecked") Iterator<NeighborFeature> iter = (Iterator<NeighborFeature>) spatialIndex.query( source.getEnvelopeInternal()).iterator(); iter.hasNext();) { NeighborFeature sample = iter.next(); if (sample.id.equals(id) || prepared.disjoint(sample.location)) { continue; for (int index = 0; index < sample.location.getNumGeometries(); index++) { Polygon poly = (Polygon) sample.location.getGeometryN(index); if (prepared.disjoint(poly)) { continue;
GeometryFactory factory = source.getFactory(); Geometry union = source.union(CascadedPolygonUnion.union(neighbors)); for (int index = 0; index < union.getNumGeometries(); index++) { Polygon poly = (Polygon) union.getGeometryN(index); for (int i = 0; i < poly.getNumInteriorRing(); i++) { LinearRing hole = (LinearRing) poly.getInteriorRingN(i); if (prepared.disjoint(hole)) { continue;
double area = geometry.getArea(); if (area < 1e-12) { throw new IllegalArgumentException("Feature geometry is too small"); Envelope env = geometry.getEnvelopeInternal(); if (pixelAreaAtLat == -1) pixelAreaAtLat = pixel.getArea(); //Recalculate for a new latitude. if (preparedGeom.intersects(pixel)){ // pixel is at least partly inside the feature Geometry intersection = pixel.intersection(geometry); double denominator = relativeToPixels ? pixelAreaAtLat : area;
Geometry geometry = (Geometry) feature.getDefaultGeometry(); if (isPolygon) { geometry = geometry.getBoundary(); 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() { @Override
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; } }
/** * Gets the enclosing rectangle of this ROI. * * @return a new rectangle */ @Override public Rectangle getBounds() { Envelope env = theGeom.getGeometry().getEnvelopeInternal(); return new Rectangle((int)env.getMinX(), (int)env.getMinY(), (int)env.getWidth(), (int)env.getHeight()); }
Geometry multi = (Geometry) feature.getDefaultGeometry(); if (isPolygon) { multi = multi.getBoundary(); for (int index = 0; index < multi.getNumGeometries(); index++) { LineString source = (LineString) multi.getGeometryN(index); PreparedGeometry prepared = PreparedGeometryFactory.prepare(source); neighbors.clear(); source.getEnvelopeInternal()).iterator(); iter.hasNext();) { NearFeature sample = iter.next(); if (sample.id.equals(id) || prepared.disjoint(sample.location)) { continue;
/** * Returns a new ROI created by applying the given transform to * this ROI. * * @param at the transform * * @return the new ROI */ @Override public ROI transform(AffineTransform at) { Geometry cloned = (Geometry) theGeom.getGeometry().clone(); cloned.apply(new AffineTransformation(at.getScaleX(), at.getShearX(), at.getTranslateX(), at.getShearY(), at.getScaleY(), at.getTranslateY())); if (useFixedPrecision){ Geometry fixed = PRECISE_FACTORY.createGeometry(cloned); Coordinate[] coords = fixed.getCoordinates(); for (Coordinate coord : coords) { Coordinate precise = coord; PRECISION.makePrecise(precise); } cloned = fixed; } return new ROIGeometry(cloned); }
public Rect mbr() { // TODO assumes that shapefile is using WGS84? load(); Rect r = null; for (PreparedGeometry g : geometries) { Coordinate[] v = g.getGeometry().getEnvelope().getCoordinates(); System.out.println(Arrays.toString(v)); Rect rect = new Rect(v[0].y, v[0].x, v[2].y, v[2].x); if (r == null) r = rect; else r = r.add(rect); } return r; }
if (representativeGeom.getGeometry() instanceof Point) { return 1.0; if (representativeGeom.getGeometry() instanceof LineString) { return 1.0; if (representativeGeom.getGeometry() instanceof Polygon) { Rectangle2D glyphBounds = painter.getFullLabelBounds(); try { if (representativeGeom.contains(pp)) { count++; Geometry g = representativeGeom.getGeometry(); g.geometryChanged(); Envelope ePoly = g.getEnvelopeInternal(); Envelope eglyph = toEnvelope(transform.createTransformedShape(glyphBounds).getBounds2D()); Envelope inter = intersection(ePoly, eglyph);
public double getCoverage(Cell cell, boolean simpleIntersection) { checkPreparedShape(); if (preparedShape == null) { if (simpleIntersection) { Geometry gm = makePoint(cell); return gm.intersects(value) ? 1.0 : 0.0; } Geometry gm = makeCell(cell.getMinX(), cell.getMinY(), cell.getMaxX(), cell .getMaxY()); return gm.covers(value) ? 1.0 : (gm.intersection(value).getArea() / gm.getArea()); } if (simpleIntersection) { return preparedShape.covers(makePoint(cell)) ? 1 : 0; } Geometry gm = makeCell(cell.getMinX(), cell.getMinY(), cell.getMaxX(), cell .getMaxY()); return preparedShape.covers(gm) ? 1.0 : (gm.intersection(value).getArea() / gm.getArea()); }
geometry.getEnvelopeInternal()).iterator(); iter.hasNext();) { NearFeature sample = iter.next(); if (processedMap.contains(sample.id) || sample.id.equals(featureID)) { if (prepared.disjoint(sample.location)) { continue; if (sample.location.equals(geometry)) { processedMap.add(sample.id);
System.out.println("geometry.coordinates.length = " + length); Geometry envelope = geometry.getEnvelope(); if (envelope instanceof Polygon) { Polygon polygon = (Polygon) envelope; geoCoding.getGeoPos(pixelPos, geoPos); Point point = geometryFactory.createPoint(new Coordinate(geoPos.lon, geoPos.lat)); if (envelope.contains(point)) { matches++; geoCoding.getGeoPos(pixelPos, geoPos); Point point = geometryFactory.createPoint(new Coordinate(geoPos.lon, geoPos.lat)); if (preparedGeometry.contains(point)) { matches++; geoCoding.getGeoPos(pixelPos, geoPos); Point point = geometryFactory.createPoint(new Coordinate(geoPos.lon, geoPos.lat)); if (preparedGeometry.containsProperly(point)) { matches++; geoCoding.getGeoPos(pixelPos, geoPos); Point point = geometryFactory.createPoint(new Coordinate(geoPos.lon, geoPos.lat)); if (geometry.contains(point)) { matches++;
/** * Returns a new instance which is the intersection of this ROI and {@code roi}. * This is only possible if {@code roi} is an instance of ROIGeometry * or {@link ROIShape}. * * @param roi the ROI to intersect with * @return the intersection as a new instance * @throws UnsupportedOperationException if {@code roi} is not an instance * of ROIGeometry or {@link ROIShape} */ @Override public ROI intersect(ROI roi) { final Geometry geom = getGeometry(roi); if (geom != null) { Geometry intersect = geom.intersection(theGeom.getGeometry()); // Geometry fixed = PRECISE_FACTORY.createGeometry(intersect); // Coordinate[] coords = fixed.getCoordinates(); // for (Coordinate coord : coords) { // Coordinate cc1 = coord; // PRECISION.makePrecise(cc1); // } // intersect = fixed; return new ROIGeometry(intersect); } throw new UnsupportedOperationException(UNSUPPORTED_ROI_TYPE); }