protected Geometry indicesOfThenExtract(Geometry input, Geometry subLine) { LocationIndexedLine indexedLine = new LocationIndexedLine(input); LinearLocation[] loc = indexedLine.indicesOf(subLine); Geometry result = indexedLine.extractLine(loc[0], loc[1]); return result; }
/** * Constructs an object which allows linear referencing along * a given linear {@link Geometry}. * * @param linearGeom the linear geometry to reference along */ public LocationIndexedLine(Geometry linearGeom) { this.linearGeom = linearGeom; checkGeometryType(); }
protected Coordinate extractOffsetAt(Geometry linearGeom, Coordinate testPt, double offsetDistance) { LocationIndexedLine indexedLine = new LocationIndexedLine(linearGeom); LinearLocation index = indexedLine.indexOf(testPt); return indexedLine.extractPoint(index, offsetDistance); }
protected boolean indexOfAfterCheck(Geometry linearGeom, Coordinate testPt, Coordinate afterPt) { LocationIndexedLine indexedLine = new LocationIndexedLine(linearGeom); // check that computed location is after check location LinearLocation afterLoc = indexedLine.indexOf(afterPt); LinearLocation testLoc = indexedLine.indexOfAfter(testPt, afterLoc); if (testLoc.compareTo(afterLoc) < 0 ) return false; return true; }
protected boolean indexOfAfterCheck(Geometry linearGeom, Coordinate testPt) { LocationIndexedLine indexedLine = new LocationIndexedLine(linearGeom); // check locations are consecutive LinearLocation loc1 = indexedLine.indexOf(testPt); LinearLocation loc2 = indexedLine.indexOfAfter(testPt, loc1); if (loc2.compareTo(loc1) <= 0 ) return false; // check extracted points are the same as the input Coordinate pt1 = indexedLine.extractPoint(loc1); Coordinate pt2 = indexedLine.extractPoint(loc2); if (! pt1.equals2D(testPt)) return false; if (! pt2.equals2D(testPt)) return false; return true; }
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 void runExtractLine(String wkt, LinearLocation start, LinearLocation end, String expected) { Geometry geom = read(wkt); LocationIndexedLine lil = new LocationIndexedLine(geom); Geometry result = lil.extractLine(start, end); //System.out.println(result); checkExpected(result, expected); }
public void testRepeatedCoordsLineString() throws Exception { Geometry line = reader.read("LINESTRING (10 0, 10 0, 20 0)"); LocationIndexedLine indexedLine = new LocationIndexedLine(line); LinearLocation loc0 = indexedLine.indexOf(new Coordinate(11, 0)); assertTrue(loc0.compareTo(new LinearLocation(1, 0.1)) == 0); }
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)); }
public void testSameSegmentLineString() throws Exception 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 loc2_5 = indexedLine.indexOf(new Coordinate (25, 0)); LinearLocation loc3 = indexedLine.indexOf(new Coordinate (30, 0));
public void testSameSegmentMultiLineString() throws Exception 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));