Refine search
public static LinearLocation getEndLocation(Geometry linear) { //the version in LinearLocation is broken int lastComponentIndex = linear.getNumGeometries() - 1; LineString lastLine = (LineString) linear.getGeometryN(lastComponentIndex); int lastSegmentIndex = lastLine.getNumPoints() - 1; return new LinearLocation(lastComponentIndex, lastSegmentIndex, 0.0); } }
private static FeatureStats pointStats(Geometry geom) { final FeatureStats featureStats = new FeatureStats(); final HashSet<Point> pointSet = new HashSet<>(geom.getNumPoints()); featureStats.totalPts = geom.getNumPoints(); for(int i = 0; i < geom.getNumGeometries(); ++i) { final Point p = (Point) geom.getGeometryN(i); featureStats.repeatedPts += pointSet.add(p) ? 0 : 1; } return featureStats; }
nextGeomCount = nextGeom.getNumGeometries(); for(int i = 0; i < nextGeomCount; ++i) { geomStack.push(nextGeom.getGeometryN(i));
private static FeatureStats lineStats(Geometry geom) { final FeatureStats featureStats = new FeatureStats(); for(int i = 0; i < geom.getNumGeometries(); ++i) { final LineString lineString = (LineString) geom.getGeometryN(i); featureStats.totalPts += lineString.getNumPoints(); featureStats.repeatedPts += checkRepeatedPoints2d(lineString); } return featureStats; }
public void setGeom(Geometry geom) throws EmptyPolygonException, UnsupportedGeometryException { if (geom instanceof MultiPolygon) { if (geom.isEmpty()) { throw new EmptyPolygonException(); } if (geom.getNumGeometries() > 1) { // LOG.warn("Multiple polygons in MultiPolygon, using only the first."); // TODO percolate this warning up somehow } this.geom = geom.getGeometryN(0); } else if( geom instanceof Point || geom instanceof Polygon){ this.geom = geom; } else { throw new UnsupportedGeometryException( "Non-point, non-polygon Geometry, not supported." ); } // cache a representative point Point point = geom.getCentroid(); this.lat = point.getY(); this.lon = point.getX(); }
/** * Computes the angle of the last segment of a LineString or MultiLineString in radians clockwise from North * in the range (-PI, PI). * @param geometry a LineString or a MultiLineString */ public static synchronized double getLastAngle(Geometry geometry) { LineString line; if (geometry instanceof MultiLineString) { line = (LineString) geometry.getGeometryN(geometry.getNumGeometries() - 1); } else { assert geometry instanceof LineString; line = (LineString) geometry; } int numPoints = line.getNumPoints(); Coordinate coord0 = line.getCoordinateN(numPoints - 2); Coordinate coord1 = line.getCoordinateN(numPoints - 1); int i = numPoints - 3; int minDistance = 10; // Meters while (SphericalDistanceLibrary.fastDistance(coord0, coord1) < minDistance && i >= 0) { coord0 = line.getCoordinateN(i--); } double az = getAzimuth(coord0, coord1); return az * Math.PI / 180; }
private static FeatureStats polyStats(Geometry geom) { final FeatureStats featureStats = new FeatureStats(); for(int i = 0; i < geom.getNumGeometries(); ++i) { final Polygon nextPoly = (Polygon) geom.getGeometryN(i); // Stats: exterior ring final LineString exteriorRing = nextPoly.getExteriorRing(); featureStats.totalPts += exteriorRing.getNumPoints(); featureStats.repeatedPts += checkRepeatedPoints2d(exteriorRing); // Stats: interior rings for(int ringIndex = 0; ringIndex < nextPoly.getNumInteriorRing(); ++ringIndex) { final LineString nextInteriorRing = nextPoly.getInteriorRingN(ringIndex); featureStats.totalPts += nextInteriorRing.getNumPoints(); featureStats.repeatedPts += checkRepeatedPoints2d(nextInteriorRing); } } return featureStats; }
for (int i = 0; i < geom.getNumGeometries(); ++i) { mvtGeom.addAll(linesToGeomCmds(geom.getGeometryN(i), mvtClosePath, cursor, 1)); for(int i = 0; i < geom.getNumGeometries(); ++i) { final Polygon nextPoly = (Polygon) geom.getGeometryN(i); final List<Integer> nextPolyGeom = new ArrayList<>(); boolean valid = true;
/** * Computes the angle from the first point to the last point of a LineString or MultiLineString. TODO: put this method into * org.opentripplanner.common.geometry.DirectionUtils * * @param geometry a LineString or a MultiLineString * * @return */ public synchronized double getFirstToLastSegmentAngle(Geometry geometry) { LineString line; if (geometry instanceof MultiLineString) { line = (LineString) geometry.getGeometryN(geometry.getNumGeometries() - 1); } else { assert geometry instanceof LineString; line = (LineString) geometry; } int numPoints = line.getNumPoints(); Coordinate coord0 = line.getCoordinateN(0); Coordinate coord1 = line.getCoordinateN(numPoints - 1); int i = numPoints - 3; while (SphericalDistanceLibrary.fastDistance(coord0, coord1) < 10 && i >= 0) { coord1 = line.getCoordinateN(i--); } geodeticCalculator.setStartingGeographicPoint(coord0.x, coord0.y); geodeticCalculator.setDestinationGeographicPoint(coord1.x, coord1.y); return geodeticCalculator.getAzimuth() * Math.PI / 180; } }
private void computeInteracting() { for (int i = 0; i < g0.getNumGeometries(); i++) { Geometry elem = g0.getGeometryN(i); interacts0[i] = computeInteracting(elem); } }
private Geometry extractElements(Geometry geom, boolean[] interacts, boolean isInteracting) { List extractedGeoms = new ArrayList(); for (int i = 0; i < geom.getNumGeometries(); i++) { Geometry elem = geom.getGeometryN(i); if (interacts[i] == isInteracting) extractedGeoms.add(elem); } return geomFactory.buildGeometry(extractedGeoms); }
private void extractElements(Geometry geom, List elems) { if (geom == null) return; for (int i = 0; i < geom.getNumGeometries(); i++) { Geometry elemGeom = geom.getGeometryN(i); if (skipEmpty && elemGeom.isEmpty()) continue; elems.add(elemGeom); } }
/** * Sets the value of this location to * refer to the end of a linear geometry. * * @param linear the linear geometry to use to set the end */ public void setToEnd(Geometry linear) { componentIndex = linear.getNumGeometries() - 1; LineString lastLine = (LineString) linear.getGeometryN(componentIndex); segmentIndex = lastLine.getNumPoints() - 1; segmentFraction = 1.0; }
/** * Tests whether a geometry consists of a single polygon with no holes. * * @return true if the geometry is a single polygon with no holes */ private boolean isSingleShell(Geometry geom) { // handles single-element MultiPolygons, as well as Polygons if (geom.getNumGeometries() != 1) return false; Polygon poly = (Polygon) geom.getGeometryN(0); int numHoles = poly.getNumInteriorRing(); if (numHoles == 0) return true; return false; }
/** * Semantics for GeometryCollection is * simple iff all components are simple. * * @param geom * @return true if the geometry is simple */ private boolean isSimpleGeometryCollection(Geometry geom) { for (int i = 0; i < geom.getNumGeometries(); i++ ) { Geometry comp = geom.getGeometryN(i); if (! computeSimple(comp)) return false; } return true; }
private void computeMinDistanceOneMulti(Geometry g0, Geometry g1, boolean flip) { if (g1 instanceof GeometryCollection) { int n = g1.getNumGeometries(); for (int i = 0; i < n; i++) { Geometry g = g1.getGeometryN(i); computeMinDistanceOneMulti(g0, g, flip); if (isDone) return; } } else { computeMinDistance(g0, g1, flip); } }
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); }
private LinearLocation resolveHigher(LinearLocation loc) { if (! loc.isEndpoint(linearGeom)) return loc; int compIndex = loc.getComponentIndex(); // if last component can't resolve any higher if (compIndex >= linearGeom.getNumGeometries() - 1) return loc; do { compIndex++; } while (compIndex < linearGeom.getNumGeometries() - 1 && linearGeom.getGeometryN(compIndex).getLength() == 0); // resolve to next higher location return new LinearLocation(compIndex, 0, 0.0); }
/** * Input is assumed to be a multiGeometry * in which every component has its userData * set to be a Coordinate which is the key to the output data. * The Coordinate is used to determine * the output data object to be written back into the component. * * @param targetGeom */ public void transferData(Geometry targetGeom) { for (int i = 0; i < targetGeom.getNumGeometries(); i++) { Geometry geom = targetGeom.getGeometryN(i); Coordinate vertexKey = (Coordinate) geom.getUserData(); if (vertexKey == null) continue; geom.setUserData(coordDataMap.get(vertexKey)); } } }
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; }