/** * Copies this location * * @return a copy of this location */ public LinearLocation copy() { return new LinearLocation(componentIndex, segmentIndex, segmentFraction); }
/** * Computes the {@link Coordinate} for the point * on the line at the given index, offset by the given distance. * If the index is out of range the first or last point on the * line will be returned. * The computed point is offset to the left of the line if the offset distance is * positive, to the right if negative. * * The Z-ordinate of the computed point will be interpolated from * the Z-ordinates of the line segment containing it, if they exist. * * @param index the index of the desired point * @param offsetDistance the distance the point is offset from the segment * (positive is to the left, negative is to the right) * @return the Coordinate at the given index */ public Coordinate extractPoint(LinearLocation index, double offsetDistance) { LinearLocation indexLow = index.toLowest(linearGeom); return indexLow.getSegment(linearGeom).pointAlongOffset(indexLow.getSegmentFraction(), offsetDistance); }
/** * Gets a location which refers to the end of a linear {@link Geometry}. * @param linear the linear geometry * @return a new <tt>LinearLocation</tt> */ public static LinearLocation getEndLocation(Geometry linear) { // assert: linear is LineString or MultiLineString LinearLocation loc = new LinearLocation(); loc.setToEnd(linear); return loc; }
private static int segmentEndVertexIndex(LinearLocation loc) { if (loc.getSegmentFraction() > 0.0) return loc.getSegmentIndex() + 1; return loc.getSegmentIndex(); }
public void testZeroLengthLineString() throws Exception { Geometry line = reader.read("LINESTRING (10 0, 10 0)"); LocationIndexedLine indexedLine = new LocationIndexedLine(line); LinearLocation loc0 = indexedLine.indexOf(new Coordinate(11, 0)); assertTrue(loc0.compareTo(new LinearLocation(1, 0.0)) == 0); }
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); }
CoordinateList newCoordinates = new CoordinateList(); int startSegmentIndex = start.getSegmentIndex(); if (start.getSegmentFraction() > 0.0) startSegmentIndex += 1; int lastSegmentIndex = end.getSegmentIndex(); if (end.getSegmentFraction() == 1.0) lastSegmentIndex += 1; if (lastSegmentIndex >= coordinates.length) if (! start.isVertex()) newCoordinates.add(start.getCoordinate(line)); for (int i = startSegmentIndex; i <= lastSegmentIndex; i++) { newCoordinates.add(coordinates[i]); if (! end.isVertex()) newCoordinates.add(end.getCoordinate(line)); newCoordinates.add(start.getCoordinate(line));
public void testGetSegmentMultiLineString() throws Exception { Geometry line = reader.read("MULTILINESTRING ((0 0, 10 0, 20 0), (20 0, 30 0))"); LocationIndexedLine indexedLine = new LocationIndexedLine(line); LinearLocation loc0 = indexedLine.indexOf(new Coordinate(0, 0)); LinearLocation loc0_5 = indexedLine.indexOf(new Coordinate(5, 0)); LinearLocation loc1 = indexedLine.indexOf(new Coordinate (10, 0)); LinearLocation loc2 = indexedLine.indexOf(new Coordinate (20, 0)); LinearLocation loc2B = new LinearLocation(1, 0, 0.0); LinearLocation loc2_5 = indexedLine.indexOf(new Coordinate (25, 0)); LinearLocation loc3 = indexedLine.indexOf(new Coordinate (30, 0)); LineSegment seg0 = new LineSegment(new Coordinate(0,0), new Coordinate(10, 0)); LineSegment seg1 = new LineSegment(new Coordinate(10,0), new Coordinate(20, 0)); LineSegment seg2 = new LineSegment(new Coordinate(20,0), new Coordinate(30, 0)); assertTrue(loc0.getSegment(line).equals(seg0)); assertTrue(loc0_5.getSegment(line).equals(seg0)); assertTrue(loc1.getSegment(line).equals(seg1)); assertTrue(loc2.getSegment(line).equals(seg1)); assertTrue(loc2_5.getSegment(line).equals(seg2)); assertTrue(loc3.getSegment(line).equals(seg2)); }
/** * Extracts a subline of the input. * If <code>end < start</code> the linear geometry computed will be reversed. * * @param start the start location * @param end the end location * @return a linear geometry */ public Geometry extract(LinearLocation start, LinearLocation end) { if (end.compareTo(start) < 0) { return reverse(computeLinear(end, start)); } return computeLinear(start, end); }
LinearLocation endLoc = LinearLocation.getEndLocation(linearGeom); if (endLoc.compareTo(minIndex) <= 0) return endLoc; Assert.isTrue(closestAfter.compareTo(minIndex) >= 0, "computed location is before specified minimum location"); return closestAfter;
public double getLength(LinearLocation loc) { double totalLength = 0.0; LinearIterator it = new LinearIterator(linearGeom); while (it.hasNext()) { if (! it.isEndOfLine()) { Coordinate p0 = it.getSegmentStart(); Coordinate p1 = it.getSegmentEnd(); double segLen = p1.distance(p0); // length falls in this segment if (loc.getComponentIndex() == it.getComponentIndex() && loc.getSegmentIndex() == it.getVertexIndex()) { return totalLength + segLen * loc.getSegmentFraction(); } totalLength += segLen; } it.next(); } return totalLength; } }
/** * Assumes input is valid (e.g. start <= end) * * @param start * @param end * @return a linear geometry */ private Geometry computeLinear(LinearLocation start, LinearLocation end) { LinearGeometryBuilder builder = new LinearGeometryBuilder(line.getFactory()); builder.setFixInvalidLines(true); if (! start.isVertex()) builder.add(start.getCoordinate(line)); for (LinearIterator it = new LinearIterator(line, start); it.hasNext(); it.next()) { if (end.compareLocationValues(it.getComponentIndex(), it.getVertexIndex(), 0.0) < 0) break; Coordinate pt = it.getSegmentStart(); builder.add(pt); if (it.isEndOfLine()) builder.endLine(); } if (! end.isVertex()) builder.add(end.getCoordinate(line)); return builder.getGeometry(); }
private LinearLocation getLocationForward(double length) return new LinearLocation(); int compIndex = it.getComponentIndex(); int segIndex = it.getVertexIndex(); return new LinearLocation(compIndex, segIndex, 0.0); int compIndex = it.getComponentIndex(); int segIndex = it.getVertexIndex(); return new LinearLocation(compIndex, segIndex, frac); return LinearLocation.getEndLocation(linearGeom);
minIndex.compareLocationValues( candidateComponentIndex, candidateSegmentIndex, segFrac) < 0 return new LinearLocation(minIndex); LinearLocation loc = new LinearLocation(minComponentIndex, minSegmentIndex, minFrac); return loc;
LinearLocation loc1 = indexedLine.indexOf(new Coordinate (10, 0)); LinearLocation loc2 = indexedLine.indexOf(new Coordinate (20, 0)); LinearLocation loc2B = new LinearLocation(1, 0, 0.0); assertTrue(loc0.isOnSameSegment(loc0)); assertTrue(loc0.isOnSameSegment(loc0_5)); assertTrue(loc0.isOnSameSegment(loc1)); assertTrue(! loc0.isOnSameSegment(loc2)); assertTrue(! loc0.isOnSameSegment(loc2_5)); assertTrue(! loc0.isOnSameSegment(loc3)); assertTrue(loc0_5.isOnSameSegment(loc0)); assertTrue(loc0_5.isOnSameSegment(loc1)); assertTrue(! loc0_5.isOnSameSegment(loc2)); assertTrue(! loc0_5.isOnSameSegment(loc3)); assertTrue(! loc2.isOnSameSegment(loc0)); assertTrue(loc2.isOnSameSegment(loc1)); assertTrue(loc2.isOnSameSegment(loc2)); assertTrue(! loc2.isOnSameSegment(loc3)); assertTrue(loc2B.isOnSameSegment(loc3)); assertTrue(loc2_5.isOnSameSegment(loc3)); assertTrue(! loc3.isOnSameSegment(loc0)); assertTrue(! loc3.isOnSameSegment(loc2)); assertTrue(loc3.isOnSameSegment(loc2B)); assertTrue(loc3.isOnSameSegment(loc2_5)); assertTrue(loc3.isOnSameSegment(loc3));
/** * Copies this location * * @return a copy of this location * @deprecated */ public Object clone() { return copy(); }
/** * Computes the {@link Coordinate} for the point * on the line at the given index. * If the index is out of range the first or last point on the * line will be returned. * The Z-ordinate of the computed point will be interpolated from * the Z-ordinates of the line segment containing it, if they exist. * * @param index the index of the desired point * @return the Coordinate at the given index */ public Coordinate extractPoint(LinearLocation index) { return index.getCoordinate(linearGeom); }
/** * Returns the index of the end of the line * @return the location index */ public LinearLocation getEndIndex() { return LinearLocation.getEndLocation(linearGeom); }
/** * Creates an iterator starting at * a {@link LinearLocation} on a linear {@link Geometry} * * @param linear the linear geometry to iterate over * @param start the location to start at * @throws IllegalArgumentException if linearGeom is not lineal */ public LinearIterator(Geometry linear, LinearLocation start) { this(linear, start.getComponentIndex(), segmentEndVertexIndex(start)); }