/** * Gets the first {@link Coordinate} of the current segment. (the coordinate of the current * vertex). * * @return a {@link Coordinate} */ public Coordinate getSegmentStart() { return currentLine.getCoordinateN(vertexIndex); }
/** Create temporary stops associated with the given graph. Note that a given AddTripPattern can be associated only with a single graph. */ public void materialize (Graph graph) { SampleFactory sfac = graph.getSampleFactory(); temporaryStops = new TemporaryStop[stops.cardinality()]; int stop = 0; for (int i = stops.nextSetBit(0); i >= 0; i = stops.nextSetBit(i + 1)) { temporaryStops[stop++] = new TemporaryStop(geometry.getCoordinateN(i), sfac); } }
/** 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); }
/** * 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; }
/** * 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; }
/** 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); }
/** * 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; } }
segments.add(new IndexedLineSegment(i, shape.getCoordinateN(i), shape.getCoordinateN(i + 1))); Coordinate from = shape.getCoordinateN(j); Coordinate to = shape.getCoordinateN(j + 1); double xd = from.x - to.x; double yd = from.y - to.y; Coordinate from = shape.getCoordinateN(j); Coordinate to = shape.getCoordinateN(j + 1); double xd = from.x - to.x; double yd = from.y - to.y;
/** * Gets the first {@link Coordinate} of the current segment. * (the coordinate of the current vertex). * @return a {@link Coordinate} */ public Coordinate getSegmentStart() { return currentLine.getCoordinateN(vertexIndex); }
Coordinate start; if (geomRemaining.isEmpty()) { start = geometry.getCoordinateN(geometry.getNumPoints() - 1); } else { start = geomRemaining.getCoordinateN(0);
public boolean isClosed() { if (isEmpty()) { return false; } return getCoordinateN(0).equals2D(getCoordinateN(getNumPoints() - 1)); }
public static Geometry getEndPoints(Geometry g) { List endPtList = new ArrayList(); if (g instanceof LineString) { LineString line = (LineString) g; endPtList.add(line.getCoordinateN(0)); endPtList.add(line.getCoordinateN(line.getNumPoints() - 1)); } else if (g instanceof MultiLineString) { MultiLineString mls = (MultiLineString) g; for (int i = 0; i < mls.getNumGeometries(); i++) { LineString line = (LineString) mls.getGeometryN(i); endPtList.add(line.getCoordinateN(0)); endPtList.add(line.getCoordinateN(line.getNumPoints() - 1)); } } Coordinate[] endPts = CoordinateArrays.toCoordinateArray(endPtList); return (new GeometryFactory()).createMultiPoint(endPts); }
/** * Gets the {@link Coordinate} along the * given linear {@link Geometry} which is * referenced by this location. * * @param linearGeom the linear geometry referenced by this location * @return the <tt>Coordinate</tt> at the location */ public Coordinate getCoordinate(Geometry linearGeom) { LineString lineComp = (LineString) linearGeom.getGeometryN(componentIndex); Coordinate p0 = lineComp.getCoordinateN(segmentIndex); if (segmentIndex >= lineComp.getNumPoints() - 1) return p0; Coordinate p1 = lineComp.getCoordinateN(segmentIndex + 1); return pointAlongSegmentByFraction(p0, p1, segmentFraction); }
/** * 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; } }
/** * Gets a {@link LineSegment} representing the segment of the * given linear {@link Geometry} which contains this location. * * @param linearGeom a linear geometry * @return the <tt>LineSegment</tt> containing the location */ public LineSegment getSegment(Geometry linearGeom) { LineString lineComp = (LineString) linearGeom.getGeometryN(componentIndex); Coordinate p0 = lineComp.getCoordinateN(segmentIndex); // check for endpoint - return last segment of the line if so if (segmentIndex >= lineComp.getNumPoints() - 1) { Coordinate prev = lineComp.getCoordinateN(lineComp.getNumPoints() - 2); return new LineSegment(prev, p0); } Coordinate p1 = lineComp.getCoordinateN(segmentIndex + 1); return new LineSegment(p0, p1); }
private Coordinate[] computeBoundaryCoordinates(MultiLineString mLine) { List bdyPts = new ArrayList(); endpointMap = new TreeMap(); for (int i = 0; i < mLine.getNumGeometries(); i++) { LineString line = (LineString) mLine.getGeometryN(i); if (line.getNumPoints() == 0) continue; addEndpoint(line.getCoordinateN(0)); addEndpoint(line.getCoordinateN(line.getNumPoints() - 1)); } for (Iterator it = endpointMap.entrySet().iterator(); it.hasNext(); ) { Map.Entry entry = (Map.Entry) it.next(); Counter counter = (Counter) entry.getValue(); int valence = counter.count; if (bnRule.isInBoundary(valence)) { bdyPts.add(entry.getKey()); } } return CoordinateArrays.toCoordinateArray(bdyPts); }
/** * Gets the length of the segment in the given * Geometry containing this location. * * @param linearGeom a linear geometry * @return the length of the segment */ public double getSegmentLength(Geometry linearGeom) { LineString lineComp = (LineString) linearGeom.getGeometryN(componentIndex); // ensure segment index is valid int segIndex = segmentIndex; if (segmentIndex >= lineComp.getNumPoints() - 1) segIndex = lineComp.getNumPoints() - 2; Coordinate p0 = lineComp.getCoordinateN(segIndex); Coordinate p1 = lineComp.getCoordinateN(segIndex + 1); return p0.distance(p1); }
public LinearLocation[] indicesOf(Geometry subLine) { Coordinate startPt = ((LineString) subLine.getGeometryN(0)).getCoordinateN(0); LineString lastLine = (LineString) subLine.getGeometryN(subLine.getNumGeometries() - 1); Coordinate endPt = lastLine.getCoordinateN(lastLine.getNumPoints() - 1); LocationIndexOfPoint locPt = new LocationIndexOfPoint(linearGeom); LinearLocation[] subLineLoc = new LinearLocation[2]; subLineLoc[0] = locPt.indexOf(startPt); // check for case where subline is zero length if (subLine.getLength() == 0.0) { subLineLoc[1] = (LinearLocation) subLineLoc[0].clone(); } else { subLineLoc[1] = locPt.indexOfAfter(endPt, subLineLoc[0]); } return subLineLoc; } }
/** * Adds the area defined by a Geometry to the centroid total. * If the geometry has no area it does not contribute to the centroid. * * @param geom the geometry to add */ public void add(Geometry geom) { if (geom instanceof Polygon) { Polygon poly = (Polygon) geom; setBasePoint(poly.getExteriorRing().getCoordinateN(0)); add(poly); } else if (geom instanceof GeometryCollection) { GeometryCollection gc = (GeometryCollection) geom; for (int i = 0; i < gc.getNumGeometries(); i++) { add(gc.getGeometryN(i)); } } }