lengthIndexedLine.extractPoint(startOffset * calcLength / featureLength); results.add(createTargetFeature(feature, targetFeatureType, point)); } finally {
public void runExtractedLine(String wkt, double start, double end) throws ParseException { System.out.println("========================="); Geometry g1 = rdr.read(wkt); System.out.println("Input Geometry: " + g1); System.out.println("Indices to extract: " + start + " " + end); LengthIndexedLine indexedLine = new LengthIndexedLine(g1); Geometry subLine = indexedLine.extractLine(start, end); System.out.println("Extracted Line: " + subLine); double[] index = indexedLine.indicesOf(subLine); System.out.println("Indices of extracted line: " + index[0] + " " + index[1]); Coordinate midpt = indexedLine.extractPoint((index[0] + index[1]) / 2); System.out.println("Midpoint of extracted line: " + midpt); } }
public static Geometry extractPoint(Geometry g, double index) { LengthIndexedLine ll = new LengthIndexedLine(g); Coordinate p = ll.extractPoint(index); return g.getFactory().createPoint(p); } public static Geometry extractLine(Geometry g,
protected Coordinate extractOffsetAt(Geometry linearGeom, Coordinate testPt, double offsetDistance) { LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom); double index = indexedLine.indexOf(testPt); return indexedLine.extractPoint(index, offsetDistance); }
public static Geometry project(Geometry g, Geometry g2) { LengthIndexedLine ll = new LengthIndexedLine(g); double index = ll.project(g2.getCoordinate()); Coordinate p = ll.extractPoint(index); return g.getFactory().createPoint(p); } public static double projectIndex(Geometry g, Geometry g2)
protected boolean indexOfAfterCheck(Geometry linearGeom, Coordinate testPt) { LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom); // check locations are consecutive double loc1 = indexedLine.indexOf(testPt); double loc2 = indexedLine.indexOfAfter(testPt, loc1); if (loc2 <= loc1) 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 testExtractPointBeyondRange() { Geometry linearGeom = read("LINESTRING (0 0, 10 10)"); LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom); Coordinate pt = indexedLine.extractPoint(100); assertTrue(pt.equals(new Coordinate(10, 10))); Coordinate pt2 = indexedLine.extractPoint(0); assertTrue(pt2.equals(new Coordinate(0, 0))); }
/** * Project a point on a linestring or multilinestring * @param point * @param geometry * @return */ public static Point projectPoint(Geometry point, Geometry geometry) { if (point == null || geometry==null) { return null; } if (point.getDimension()==0 && geometry.getDimension() == 1) { LengthIndexedLine ll = new LengthIndexedLine(geometry); double index = ll.project(point.getCoordinate()); return geometry.getFactory().createPoint(ll.extractPoint(index)); } else { return null; } }
/** * Tests that if the input does not have Z ordinates, neither does the output. * */ public void testComputeZNaN() { Geometry linearGeom = read("LINESTRING (0 0, 10 10 10)"); LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom); double projIndex = indexedLine.project(new Coordinate(5, 5)); Coordinate projPt = indexedLine.extractPoint(projIndex); assertTrue(Double.isNaN(projPt.getZ() )); }
/** * From GEOS Ticket #323 */ public void testProjectExtractPoint() { Geometry linearGeom = read("MULTILINESTRING ((0 2, 0 0), (-1 1, 1 1))"); LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom); double index = indexedLine.project(new Coordinate(1, 0)); Coordinate pt = indexedLine.extractPoint(index); assertTrue(pt.equals(new Coordinate(0, 0))); }
/** * Tests that z values are interpolated * */ public void testComputeZ() { Geometry linearGeom = read("LINESTRING (0 0 0, 10 10 10)"); LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom); double projIndex = indexedLine.project(new Coordinate(5, 5)); Coordinate projPt = indexedLine.extractPoint(projIndex); // System.out.println(projPt); assertTrue(projPt.equals3D(new Coordinate(5, 5, 5))); }