@SuppressWarnings("unchecked") @Override public Collection<Edge> getEdgesForEnvelope(Envelope envelope) { List<Edge> edges = edgeTree.query(envelope); for (Iterator<Edge> ie = edges.iterator(); ie.hasNext();) { Edge e = ie.next(); Envelope eenv = e.getGeometry().getEnvelopeInternal(); //Envelope eenv = e.getEnvelope(); if (!envelope.intersects(eenv)) ie.remove(); } return edges; }
public GeometryIndex(Graph graph) { if (graph == null) { String message = "Could not retrieve default Graph from GraphService. Check its configuration."; LOG.error(message); throw new IllegalStateException(message); } Map<ReversibleLineStringWrapper, StreetEdge> edges = Maps.newHashMap(); for (StreetVertex vertex : Iterables.filter(graph.getVertices(), StreetVertex.class)) { for (StreetEdge e: Iterables.filter(vertex.getOutgoing(), StreetEdge.class)) { LineString geom = e.getGeometry(); if (e.getPermission().allows(StreetTraversalPermission.PEDESTRIAN)) { edges.put(new ReversibleLineStringWrapper(geom), e); } } } // insert unique edges pedestrianIndex = new STRtree(); for (StreetEdge e : edges.values()) { LineString geom = e.getGeometry(); pedestrianIndex.insert(geom.getEnvelopeInternal(), e); } pedestrianIndex.build(); LOG.debug("spatial index size: {}", pedestrianIndex.size()); }
public synchronized void buildSpatialIndex() { vertexIndex = new STRtree(); edgeIndex = new STRtree(); Envelope env; // int xminx, xmax, ymin, ymax; for (Vertex v : graph.getVertices()) { Coordinate c = v.getCoordinate(); env = new Envelope(c); vertexIndex.insert(env, v); for (Edge e : v.getOutgoing()) { if (e.getGeometry() == null) continue; if (e instanceof PatternEdge || e instanceof StreetTransitLink || e instanceof StreetEdge || e instanceof PathwayEdge || e instanceof SimpleTransfer) { env = e.getGeometry().getEnvelopeInternal(); edgeIndex.insert(env, e); } } } vertexIndex.build(); edgeIndex.build(); }
continue; Envelope env = geometry.getEnvelopeInternal(); if (edgeTree instanceof HashGridSpatialIndex) ((HashGridSpatialIndex)edgeTree).insert(geometry, e);
private void computeMinDistance(LineString line0, LineString line1, GeometryLocation[] locGeom) { if (line0.getEnvelopeInternal().distance(line1.getEnvelopeInternal()) > minDistance) return; Coordinate[] coord0 = line0.getCoordinates(); Coordinate[] coord1 = line1.getCoordinates(); // brute force approach! for (int i = 0; i < coord0.length - 1; i++) { for (int j = 0; j < coord1.length - 1; j++) { double dist = CGAlgorithms.distanceLineLine( coord0[i], coord0[i + 1], coord1[j], coord1[j + 1] ); if (dist < minDistance) { minDistance = dist; LineSegment seg0 = new LineSegment(coord0[i], coord0[i + 1]); LineSegment seg1 = new LineSegment(coord1[j], coord1[j + 1]); Coordinate[] closestPt = seg0.closestPoints(seg1); locGeom[0] = new GeometryLocation(line0, i, closestPt[0]); locGeom[1] = new GeometryLocation(line1, j, closestPt[1]); } if (minDistance <= terminateDistance) return; } } }
private int locate(Coordinate p, LineString l) { // bounding-box check if (! l.getEnvelopeInternal().intersects(p)) return Location.EXTERIOR; Coordinate[] pt = l.getCoordinates(); if (! l.isClosed()) { if (p.equals(pt[0]) || p.equals(pt[pt.length - 1]) ) { return Location.BOUNDARY; } } if (CGAlgorithms.isOnLine(p, pt)) return Location.INTERIOR; return Location.EXTERIOR; }
public Envelope getEnvelopeInternal() { return str_.getEnvelopeInternal(); }
public Envelope getEnvelopeInternal() { return lineString.getEnvelopeInternal(); }
public Envelope getEnvelope() { return geom.getEnvelopeInternal(); }
private void computeMinDistance(LineString line, Point pt, GeometryLocation[] locGeom) { if (line.getEnvelopeInternal().distance(pt.getEnvelopeInternal()) > minDistance) return; Coordinate[] coord0 = line.getCoordinates(); Coordinate coord = pt.getCoordinate(); // brute force approach! for (int i = 0; i < coord0.length - 1; i++) { double dist = CGAlgorithms.distancePointLine( coord, coord0[i], coord0[i + 1] ); if (dist < minDistance) { minDistance = dist; LineSegment seg = new LineSegment(coord0[i], coord0[i + 1]); Coordinate segClosestPoint = seg.closestPoint(coord); locGeom[0] = new GeometryLocation(line, i, segClosestPoint); locGeom[1] = new GeometryLocation(pt, 0, coord); } if (minDistance <= terminateDistance) return; } }
/** * * @param coords * @param factory * @param strtree */ public static void addSegments(final Coordinate[] coords, GeometryFactory factory, STRtree strtree) { for (int j = 0; j < coords.length - 1; j++) { Coordinate startCoord = coords[j]; Coordinate endCoord = coords[j + 1]; if (!(Double.isNaN(startCoord.z) || Double.isNaN(endCoord.z))) { LineString lineString = factory.createLineString( new Coordinate[]{startCoord, endCoord}); strtree.insert(lineString.getEnvelopeInternal(), lineString); } } }
@Override public void handleHighway(LineString geometry, Way way) { if(w2n.containsKey(way.id)) { Envelope env = geometry.getEnvelopeInternal(); short n = new Double((env.getMinX() + 180.0) * 10.0).shortValue(); int fromto = n << 16; n = new Double((env.getMaxX() + 180.0) * 10.0).shortValue(); fromto |= n; w2n.put(way.id, fromto); } highwaysHandler.handleHighway(geometry, way); }
private Rectangle2D getCurvedLabelBounds(LineStringCursor cursor, double startOrdinate, double endOrdinate, double bufferSize) { LineString cut = cursor.getSubLineString(startOrdinate, endOrdinate); Envelope e = cut.getEnvelopeInternal(); e.expandBy(bufferSize); return new Rectangle2D.Double(e.getMinX(), e.getMinY(), e.getWidth(), e.getHeight()); }
private int locate(Coordinate p, LineString l) { // bounding-box check if (! l.getEnvelopeInternal().intersects(p)) return Location.EXTERIOR; Coordinate[] pt = l.getCoordinates(); if (! l.isClosed()) { if (p.equals(pt[0]) || p.equals(pt[pt.length - 1]) ) { return Location.BOUNDARY; } } if (CGAlgorithms.isOnLine(p, pt)) return Location.INTERIOR; return Location.EXTERIOR; }
public void write(final EndianOutput out, final Geometry geometry) throws IOException { if (geometry instanceof LineString) { final LineString line = (LineString)geometry; final Envelope envelope = line.getEnvelopeInternal(); final CoordinateSequence coordinates = line.getCoordinateSequence(); final int recordLength = (4 * MathUtil.BYTES_IN_INT + (4 + 2 * coordinates.size()) * MathUtil.BYTES_IN_DOUBLE) / 2; out.writeInt(recordLength); out.writeLEInt(getShapeType()); ShapefileGeometryUtil.writeEnvelope(out, envelope); out.writeLEInt(1); out.writeLEInt(coordinates.size()); out.writeLEInt(0); for (int i = 0; i < coordinates.size(); i++) { out.writeLEDouble(coordinates.getOrdinate(i, 0)); out.writeLEDouble(coordinates.getOrdinate(i, 1)); } } else { throw new IllegalArgumentException("Expecting " + LineString.class + " geometry got " + geometry.getClass()); } } }
private void computeMinDistance(LineString line, Point pt, GeometryLocation[] locGeom) { if (line.getEnvelopeInternal().distance(pt.getEnvelopeInternal()) > minDistance) return; Coordinate[] coord0 = line.getCoordinates(); Coordinate coord = pt.getCoordinate(); // brute force approach! for (int i = 0; i < coord0.length - 1; i++) { double dist = CGAlgorithms.distancePointLine( coord, coord0[i], coord0[i + 1] ); if (dist < minDistance) { minDistance = dist; LineSegment seg = new LineSegment(coord0[i], coord0[i + 1]); Coordinate segClosestPoint = seg.closestPoint(coord); locGeom[0] = new GeometryLocation(line, i, segClosestPoint); locGeom[1] = new GeometryLocation(pt, 0, coord); } if (minDistance <= terminateDistance) return; } }
private void addOSMOpenWays(OSMDataSet ds) { List<OSMWay> openWays = ds.getOpenWays(); for (OSMWay w : openWays) { if (!w.isModified() && OSMWay.containsModifiedWay(w.getId())) { continue; } // Don't render or index ways that do not have all of their referenced nodes. if (w.incomplete()) { continue; } List<OSMNode> nodes = w.getNodes(); Coordinate[] coords = coordArrayFromNodeList(nodes); LineString line = geometryFactory.createLineString(coords); w.setJTSGeom(line); Envelope envelope = line.getEnvelopeInternal(); spatialIndex.insert(envelope, w); } }
private void buildSpatialIndex(SimpleFeatureCollection features) { spatialIndex = new STRtree(); SimpleFeatureIterator featureIter = features.features(); try { while (featureIter.hasNext()) { SimpleFeature feature = featureIter.next(); Geometry multiPart = (Geometry) feature.getDefaultGeometry(); for (int index = 0; index < multiPart.getNumGeometries(); index++) { LineString part = (LineString) multiPart.getGeometryN(index); NearFeature nearFeature = new NearFeature(part, feature.getID()); spatialIndex.insert(part.getEnvelopeInternal(), nearFeature); } } } finally { featureIter.close(); } }
private void buildSpatialIndex(SimpleFeatureCollection features) { spatialIndex = new STRtree(); SimpleFeatureIterator featureIter = features.features(); try { while (featureIter.hasNext()) { SimpleFeature feature = featureIter.next(); Geometry geometry = (Geometry) feature.getDefaultGeometry(); if (isPolygon) { geometry = geometry.getBoundary(); } for (int index = 0; index < geometry.getNumGeometries(); index++) { LineString part = (LineString) geometry.getGeometryN(index); NearFeature nearFeature = new NearFeature(part, feature.getID()); spatialIndex.insert(part.getEnvelopeInternal(), nearFeature); } } } finally { featureIter.close(); } }
private void buildSpatialIndex(SimpleFeatureCollection features) { spatialIndex = new STRtree(); SimpleFeatureIterator featureIter = features.features(); try { while (featureIter.hasNext()) { SimpleFeature feature = featureIter.next(); Geometry multiPart = (Geometry) feature.getDefaultGeometry(); for (int index = 0; index < multiPart.getNumGeometries(); index++) { LineString part = (LineString) multiPart.getGeometryN(index); if (extendTo) { part = exendLine(part, length, length); } NearFeature nearFeature = new NearFeature(part, feature.getID()); spatialIndex.insert(part.getEnvelopeInternal(), nearFeature); } } } finally { featureIter.close(); } }