/** * Tests whether there are any vertices left to iterator over. * * @return <code>true</code> if there are more vertices to scan */ public boolean hasNext() { if (componentIndex >= numLines) return false; if (componentIndex == numLines - 1 && vertexIndex >= currentLine.getNumPoints() - 1) return false; return true; }
public boolean isValidIndex() { if (componentIndex >= numLines) return false; if (componentIndex == numLines - 1 && vertexIndex >= currentLine.getNumPoints()) return false; return true; }
/** * Checks whether the iterator cursor is pointing to the endpoint of a linestring. * * @return <code>true</true> if the iterator is at an endpoint */ public boolean isEndOfLine() { if (componentIndex >= numLines) return false; // LineString currentLine = (LineString) linear.getGeometryN(componentIndex); if (vertexIndex < currentLine.getNumPoints() - 1) return false; return true; }
/** * Gets the second {@link Coordinate} of the current segment. (the coordinate of the next * vertex). If the iterator is at the end of a line, <code>null</code> is returned. * * @return a {@link Coordinate} or <code>null</code> */ public Coordinate getSegmentEnd() { if (vertexIndex < getLine().getNumPoints() - 1) return currentLine.getCoordinateN(vertexIndex + 1); return null; }
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); } }
/** project this linestring to an equirectangular projection */ private static LineString equirectangularProject(LineString geometry, double xscale) { Coordinate[] coords = new Coordinate[geometry.getNumPoints()]; for (int i = 0; i < coords.length; i++) { Coordinate c = geometry.getCoordinateN(i); c = (Coordinate) c.clone(); c.x *= xscale; coords[i] = c; } return geometryFactory.createLineString(coords); }
/** * Moves the iterator ahead to the next vertex and (possibly) linear component. */ public void next() { if (!hasNext()) return; segmentFraction = 0.0; vertexIndex++; if (vertexIndex >= currentLine.getNumPoints()) { componentIndex++; if (componentIndex < linearGeom.getNumGeometries() - 1) { loadCurrentLine(); vertexIndex = 0; } } }
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; }
/** calculate the length of this street segement from its geometry */ protected void calculateLengthFromGeometry () { double accumulatedMeters = 0; LineString geom = getGeometry(); for (int i = 1; i < geom.getNumPoints(); i++) { accumulatedMeters += SphericalDistanceLibrary.distance(geom.getCoordinateN(i - 1), geom.getCoordinateN(i)); } length_mm = (int) (accumulatedMeters * 1000); }
if (v instanceof StreetVertex) { LineString ls = ((StreetVertex)v).getOutgoing().iterator().next().getGeometry(); int numPoints = ls.getNumPoints(); LocationIndexedLine lil = new LocationIndexedLine(ls); int seg = random.nextInt(numPoints);
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; }
if (ls.getNumPoints() <= 3) { // first filter since u-shapes need at least 4 pts
for (int i = 0 ; i < shape.getNumPoints() - 1; ++i) { segments.add(new IndexedLineSegment(i, shape.getCoordinateN(i), shape.getCoordinateN(i + 1)));
/** * Computes the angle of the first 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 getFirstAngle(Geometry geometry) { LineString line; if (geometry instanceof MultiLineString) { line = (LineString) geometry.getGeometryN(0); } else { assert geometry instanceof LineString; line = (LineString) geometry; } Coordinate coord0 = line.getCoordinateN(0); Coordinate coord1 = line.getCoordinateN(1); int i = 2; int minDistance = 10; // Meters while (SphericalDistanceLibrary.fastDistance(coord0, coord1) < minDistance && i < line.getNumPoints()) { coord1 = line.getCoordinateN(i++); } double az = getAzimuth(coord0, coord1); return az * Math.PI / 180; }
/** * 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; }
if (e.getGeometry() != null) { LineString geometry = e.getGeometry(); geomSizeDistribution.add(new NumberQuantifiable<Integer>(geometry.getNumPoints())); double lenMeters = SphericalDistanceLibrary.fastLength(geometry); geomLenDistribution.add(new LogQuantifiable<Double>(lenMeters, 5.0));
/** * 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; } }
else if (ll.getSegmentIndex() == orig.getNumPoints() - 1) { makeLinkEdges(tstop, (StreetVertex) edge.getToVertex()); else if (ll.getSegmentIndex() == orig.getNumPoints() - 2 && ll.getSegmentFraction() > 1 - 1e-8) { makeLinkEdges(tstop, (StreetVertex) edge.getToVertex());
Coordinate start; if (geomRemaining.isEmpty()) { start = geometry.getCoordinateN(geometry.getNumPoints() - 1); } else { start = geomRemaining.getCoordinateN(0);
public Point getEndPoint() { if (isEmpty()) { return null; } return getPointN(getNumPoints() - 1); }