@SqlNullable @Description("Returns a float between 0 and 1 representing the location of the closest point on the LineString to the given Point, as a fraction of total 2d line length.") @ScalarFunction("line_locate_point") @SqlType(DOUBLE) public static Double lineLocatePoint(@SqlType(GEOMETRY_TYPE_NAME) Slice lineSlice, @SqlType(GEOMETRY_TYPE_NAME) Slice pointSlice) { Geometry line = JtsGeometrySerde.deserialize(lineSlice); Geometry point = JtsGeometrySerde.deserialize(pointSlice); if (line.isEmpty() || point.isEmpty()) { return null; } GeometryType lineType = GeometryType.getForJtsGeometryType(line.getGeometryType()); if (lineType != GeometryType.LINE_STRING && lineType != GeometryType.MULTI_LINE_STRING) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("First argument to line_locate_point must be a LineString or a MultiLineString. Got: %s", line.getGeometryType())); } GeometryType pointType = GeometryType.getForJtsGeometryType(point.getGeometryType()); if (pointType != GeometryType.POINT) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Second argument to line_locate_point must be a Point. Got: %s", point.getGeometryType())); } return new LengthIndexedLine(line).indexOf(point.getCoordinate()) / line.getLength(); }
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 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); } }
protected Coordinate extractOffsetAt(Geometry linearGeom, Coordinate testPt, double offsetDistance) { LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom); double index = indexedLine.indexOf(testPt); return indexedLine.extractPoint(index, offsetDistance); }
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; }
Double featureToMeasure = (Double) feature.getProperty(toMeasureAttb).getValue(); LengthIndexedLine lengthIndexedLine = new LengthIndexedLine( (Geometry) feature.getDefaultGeometryProperty().getValue()); double featureLength = featureToMeasure - featureFromMeasure; lengthIndexedLine.extractPoint(startOffset * calcLength / featureLength); results.add(createTargetFeature(feature, targetFeatureType, point)); } finally {
&& toMeasure < featureToMeasure) { LengthIndexedLine lengthIndexedLine = new LengthIndexedLine( (Geometry) feature.getDefaultGeometryProperty() if (calcLength == 0 || featureLength == 0) continue; Geometry extracted = lengthIndexedLine.extractLine( startOffset * calcLength / featureLength, stopOffset * calcLength / featureLength); } else if (fromMeasure > featureFromMeasure) { LengthIndexedLine lengthIndexedLine = new LengthIndexedLine( (Geometry) feature.getDefaultGeometryProperty() if (calcLength == 0 || featureLength == 0) continue; Geometry extracted = lengthIndexedLine.extractLine( startOffset * calcLength / featureLength, calcLength); } else { LengthIndexedLine lengthIndexedLine = new LengthIndexedLine( (Geometry) feature.getDefaultGeometryProperty()
protected Geometry indicesOfThenExtract(Geometry linearGeom, Geometry subLine) { LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom); double[] loc = indexedLine.indicesOf(subLine); Geometry result = indexedLine.extractLine(loc[0], loc[1]); return result; }
protected boolean indexOfAfterCheck(Geometry linearGeom, Coordinate testPt, Coordinate checkPt) { LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom); // check that computed location is after check location double checkLoc = indexedLine.indexOf(checkPt); double testLoc = indexedLine.indexOfAfter(testPt, checkLoc); if (testLoc < checkLoc) return false; return true; }
public static double projectIndex(Geometry g, Geometry g2) { LengthIndexedLine ll = new LengthIndexedLine(g); return ll.project(g2.getCoordinate()); }
/** * 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; } }
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,
public static Geometry extractLine(Geometry g, @Metadata(title="Start length") double start, @Metadata(title="End length") double end) { LengthIndexedLine ll = new LengthIndexedLine(g); return ll.extractLine(start, end); } public static Geometry project(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); }
/** * 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() )); }
new LengthIndexedLine( (Geometry) nearestFeature.getDefaultGeometryProperty().getValue()); double lineIndex = lengthIndexedLine.indexOf(nearestCoords[1]); double lineLength = ((Geometry) nearestFeature.getDefaultGeometryProperty().getValue())
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))); }
private void checkExtractLine(String wkt, double start, double end, String expected) { Geometry linearGeom = read(wkt); LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom); Geometry result = indexedLine.extractLine(start, end); checkExpected(result, expected); }
/** * 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))); }
@SqlNullable @Description("Returns a float between 0 and 1 representing the location of the closest point on the LineString to the given Point, as a fraction of total 2d line length.") @ScalarFunction("line_locate_point") @SqlType(DOUBLE) public static Double lineLocatePoint(@SqlType(GEOMETRY_TYPE_NAME) Slice lineSlice, @SqlType(GEOMETRY_TYPE_NAME) Slice pointSlice) { Geometry line = JtsGeometrySerde.deserialize(lineSlice); Geometry point = JtsGeometrySerde.deserialize(pointSlice); if (line.isEmpty() || point.isEmpty()) { return null; } GeometryType lineType = GeometryType.getForJtsGeometryType(line.getGeometryType()); if (lineType != GeometryType.LINE_STRING && lineType != GeometryType.MULTI_LINE_STRING) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("First argument to line_locate_point must be a LineString or a MultiLineString. Got: %s", line.getGeometryType())); } GeometryType pointType = GeometryType.getForJtsGeometryType(point.getGeometryType()); if (pointType != GeometryType.POINT) { throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Second argument to line_locate_point must be a Point. Got: %s", point.getGeometryType())); } return new LengthIndexedLine(line).indexOf(point.getCoordinate()) / line.getLength(); }