/** * JTS 1.14 does not support intersection on a {@link GeometryCollection}. This function works around this * by performing intersection on a flat list of geometry. The resulting list is pre-filtered for invalid * or empty geometry (outside of bounds). Invalid geometry are logged as errors. * * @param envelope non-list geometry defines bounding area * @param dataGeoms geometry pre-passed through {@link #flatFeatureList(Geometry)} * @return list of geometry from {@code data} intersecting with {@code envelope}. */ private static List<Geometry> flatIntersection(Geometry envelope, List<Geometry> dataGeoms) { final List<Geometry> intersectedGeoms = new ArrayList<>(dataGeoms.size()); Geometry nextIntersected; for(Geometry nextGeom : dataGeoms) { try { // AABB intersection culling if(envelope.getEnvelopeInternal().intersects(nextGeom.getEnvelopeInternal())) { nextIntersected = envelope.intersection(nextGeom); if(!nextIntersected.isEmpty()) { nextIntersected.setUserData(nextGeom.getUserData()); intersectedGeoms.add(nextIntersected); } } } catch (TopologyException e) { //LoggerFactory.getLogger(JtsAdapter.class).error(e.getMessage(), e); } } return intersectedGeoms; }
STRtree createIndex() { STRtree edgeIndex = new STRtree(); for (Vertex v : graph.getVertices()) { for (Edge e : v.getOutgoing()) { if (e instanceof StreetEdge) { Envelope envelope; Geometry geometry = e.getGeometry(); envelope = geometry.getEnvelopeInternal(); edgeIndex.insert(envelope, e); } } } log.debug("Created index"); return edgeIndex; }
/** * The function is run periodically by the update manager. * The extending class should provide the getNote method. It is not implemented here * as the requirements for different updaters can be vastly different dependent on the data source. */ @Override protected void runPolling() throws IOException{ LOG.info("Run WFS polling updater with hashcode: {}", this.hashCode()); notesForEdge = HashMultimap.create(); uniqueMatchers = new HashMap<>(); FeatureIterator<SimpleFeature> features = featureSource.getFeatures(query).features(); while ( features.hasNext()){ SimpleFeature feature = features.next(); if (feature.getDefaultGeometry() == null) continue; Alert alert = getNote(feature); if (alert == null) continue; Geometry geom = (Geometry) feature.getDefaultGeometry(); Geometry searchArea = geom.buffer(SEARCH_RADIUS_DEG); Collection<Edge> edges = graph.streetIndex.getEdgesForEnvelope(searchArea.getEnvelopeInternal()); for(Edge edge: edges){ if (edge instanceof StreetEdge && !searchArea.disjoint(edge.getGeometry())) { addNote(edge, alert, NOTE_MATCHER); } } } updaterManager.execute(new WFSGraphWriter()); }
/** * Determines whether a Geometry g interacts with * this geometry by testing the geometry envelopes. * * @param g a Geometry * @return true if the envelopes intersect */ protected boolean envelopesIntersect(Geometry g) { if (! baseGeom.getEnvelopeInternal().intersects(g.getEnvelopeInternal())) return false; return true; }
/** * Determines whether the envelope of * this geometry covers the Geometry g. * * * @param g a Geometry * @return true if g is contained in this envelope */ protected boolean envelopeCovers(Geometry g) { if (! baseGeom.getEnvelopeInternal().covers(g.getEnvelopeInternal())) return false; return true; }
/** * Default implementation. */ public boolean containsProperly(Geometry g) { // since raw relate is used, provide some optimizations // short-circuit test if (! baseGeom.getEnvelopeInternal().contains(g.getEnvelopeInternal())) return false; // otherwise, compute using relate mask return baseGeom.relate(g, "T**FF*FF*"); }
/** * Gets a hash code for the Geometry. * * @return an integer value suitable for use as a hashcode */ public int hashCode() { return getEnvelopeInternal().hashCode(); }
/** * Finds all {@link PreparedGeometry}s which might * interact with a query {@link Geometry}. * * @param g the geometry to query by * @return a list of candidate PreparedGeometrys */ public List query(Geometry g) { return index.query(g.getEnvelopeInternal()); }
/** * Inserts a collection of Geometrys into the index. * * @param geoms a collection of Geometrys to insert */ public void insert(Collection geoms) { for (Iterator i = geoms.iterator(); i.hasNext(); ) { Geometry geom = (Geometry) i.next(); index.insert(geom.getEnvelopeInternal(), PreparedGeometryFactory.prepare(geom)); } }
private boolean computeInteracting(Geometry elem0) { boolean interactsWithAny = false; for (int i = 0; i < g1.getNumGeometries(); i++) { Geometry elem1 = g1.getGeometryN(i); boolean interacts = elem1.getEnvelopeInternal().intersects(elem0.getEnvelopeInternal()); if (interacts) interacts1[i] = true; if (interacts) interactsWithAny = true; } return interactsWithAny; }
private static double OLDprecisionScaleFactor(Geometry g, double distance, int maxPrecisionDigits) { Envelope env = g.getEnvelopeInternal(); double envSize = Math.max(env.getHeight(), env.getWidth()); double expandByDistance = distance > 0.0 ? distance : 0.0; double bufEnvSize = envSize + 2 * expandByDistance; // the smallest power of 10 greater than the buffer envelope int bufEnvLog10 = (int) (Math.log(bufEnvSize) / Math.log(10) + 1.0); int minUnitLog10 = bufEnvLog10 - maxPrecisionDigits; // scale factor is inverse of min Unit size, so flip sign of exponent double scaleFactor = Math.pow(10.0, -minUnitLog10); return scaleFactor; }
public static double computeSizeBasedSnapTolerance(Geometry g) { Envelope env = g.getEnvelopeInternal(); double minDimension = Math.min(env.getHeight(), env.getWidth()); double snapTol = minDimension * SNAP_PRECISION_FACTOR; return snapTol; }
/** * Sets a polygonal mask. * * @param mask * @throws IllegalArgumentException if the mask is not polygonal */ public void setExtent(Geometry mask) { if (! (mask instanceof Polygonal)) throw new IllegalArgumentException("Only polygonal extents are supported"); this.maskPoly = mask; setExtent(mask.getEnvelopeInternal()); extentLocator = new IndexedPointInAreaLocator(mask); }
protected Envelope computeEnvelopeInternal() { Envelope envelope = new Envelope(); for (int i = 0; i < geometries.length; i++) { envelope.expandToInclude(geometries[i].getEnvelopeInternal()); } return envelope; }
public double measure(Geometry g1, Geometry g2) { double distance = DiscreteHausdorffDistance.distance(g1, g2, DENSIFY_FRACTION); Envelope env = new Envelope(g1.getEnvelopeInternal()); env.expandToInclude(g2.getEnvelopeInternal()); double envSize = diagonalSize(env); // normalize so that more similarity produces a measure closer to 1 double measure = 1 - distance / envSize; //System.out.println("Hausdorff distance = " + distance + ", measure = " + measure); return measure; }
public boolean contains(Geometry geom) { // the test geometry must be wholly contained in the rectangle envelope if (! rectEnv.contains(geom.getEnvelopeInternal())) return false; /** * Check that geom is not contained entirely in the rectangle boundary. * According to the somewhat odd spec of the SFS, if this * is the case the geometry is NOT contained. */ if (isContainedInBoundary(geom)) return false; return true; }
private Geometry extractByEnvelope(Envelope env, Geometry geom, List disjointGeoms) { List intersectingGeoms = new ArrayList(); for (int i = 0; i < geom.getNumGeometries(); i++) { Geometry elem = geom.getGeometryN(i); if (elem.getEnvelopeInternal().intersects(env)) intersectingGeoms.add(elem); else disjointGeoms.add(elem); } return geomFactory.buildGeometry(intersectingGeoms); }
/** * Finds a reasonable point at which to label a Geometry. * @param geometry the geometry to analyze */ public void addPolygon(Geometry geometry) { LineString bisector = horizontalBisector(geometry); Geometry intersections = bisector.intersection(geometry); Geometry widestIntersection = widestGeometry(intersections); double width = widestIntersection.getEnvelopeInternal().getWidth(); if (interiorPoint == null || width > maxWidth) { interiorPoint = centre(widestIntersection.getEnvelopeInternal()); maxWidth = width; } }
protected LineString horizontalBisector(Geometry geometry) { Envelope envelope = geometry.getEnvelopeInternal(); // Assert: for areas, minx <> maxx double avgY = avg(envelope.getMinY(), envelope.getMaxY()); return factory.createLineString(new Coordinate[] { new Coordinate(envelope.getMinX(), avgY), new Coordinate(envelope.getMaxX(), avgY) }); }
private Geometry widestGeometry(GeometryCollection gc) { if (gc.isEmpty()) { return gc; } Geometry widestGeometry = gc.getGeometryN(0); for (int i = 1; i < gc.getNumGeometries(); i++) { //Start at 1 if (gc.getGeometryN(i).getEnvelopeInternal().getWidth() > widestGeometry.getEnvelopeInternal().getWidth()) { widestGeometry = gc.getGeometryN(i); } } return widestGeometry; }