@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(); }
/** * 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)); }
private LinearLocation(int componentIndex, int segmentIndex, double segmentFraction, boolean doNormalize) { this.componentIndex = componentIndex; this.segmentIndex = segmentIndex; this.segmentFraction = segmentFraction; if (doNormalize) normalize(); }
protected Coordinate extractOffsetAt(Geometry linearGeom, Coordinate testPt, double offsetDistance) { LengthIndexedLine indexedLine = new LengthIndexedLine(linearGeom); double index = indexedLine.indexOf(testPt); return indexedLine.extractPoint(index, offsetDistance); }
/** * 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))); }
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); }
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 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; }
/** * 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); }
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 testMultiLineString2() throws Exception { runExtractLine("MULTILINESTRING ((0 0, 10 10), (20 20, 30 30))", new LinearLocation(0, 0, 1.0), new LinearLocation(1, 0, .5), "MULTILINESTRING ((10 10, 10 10), (20 20, 25 25))"); }
public static double indexOf(Geometry linearGeom, Coordinate inputPt) { LengthIndexOfPoint locater = new LengthIndexOfPoint(linearGeom); return locater.indexOf(inputPt); }
/** * 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(); }
/** * Returns the index of the end of the line * @return the location index */ public LinearLocation getEndIndex() { return LinearLocation.getEndLocation(linearGeom); }
/** * Adds a point to the current line. * * @param pt the Coordinate to add */ public void add(Coordinate pt) { add(pt, true); }
public void testExtractLineBothIndicesAtEndpointXXX() { checkExtractLine("MULTILINESTRING ((0 0, 10 0), (20 0, 25 0, 30 0))", -10, 10, "LINESTRING (10 0, 10 0)"); }
public void testLoopWithIdenticalSubLine() { runIndicesOfThenExtract("LINESTRING (0 0, 0 10, 10 10, 10 0, 0 0)", "LINESTRING (0 0, 0 10, 10 10, 10 0, 0 0)"); }
new LengthIndexedLine( (Geometry) nearestFeature.getDefaultGeometryProperty().getValue()); double lineIndex = lengthIndexedLine.indexOf(nearestCoords[1]); double lineLength = ((Geometry) nearestFeature.getDefaultGeometryProperty().getValue())
public void testMultiLineStringSimple() throws Exception { runExtractLine("MULTILINESTRING ((0 0, 10 10), (20 20, 30 30))", new LinearLocation(0, 0, .5), new LinearLocation(1, 0, .5), "MULTILINESTRING ((5 5, 10 10), (20 20, 25 25))"); }