public static double projectIndex(Geometry g, Geometry g2) { LengthIndexedLine ll = new LengthIndexedLine(g); return ll.project(g2.getCoordinate()); }
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)
public void testProjectPointWithDuplicateCoords() { Geometry linearGeom = read("LINESTRING (0 0, 10 0, 10 0, 20 0)"); LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom); double projIndex = indexedLine.project(new Coordinate(10, 1)); assertTrue(projIndex == 10.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))); }