public static double geomLength(Geometry arg0) { if (arg0 == null) return 0d; Geometry _this = arg0; return _this.getLength(); }
@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 double getLength() { return geometry.getLength(); }
@Override public void filter(Geometry gmtr) { if (MultiPolygon.class.isAssignableFrom(binding)) { if (gmtr.getArea() != 0.0d && gmtr.getGeometryType().equals("Polygon")) { collection.add(gmtr); } } if (MultiLineString.class.isAssignableFrom(binding)) { if (gmtr.getLength() != 0.0d && gmtr.getGeometryType().equals("LineString")) { collection.add(gmtr); } } if (MultiPoint.class.isAssignableFrom(binding)) { if (gmtr.getNumGeometries() > 0 && gmtr.getGeometryType().equals("Point")) { collection.add(gmtr); } } if (Point.class.isAssignableFrom(binding)) { if (gmtr.getGeometryType().equals("Point")) { collection.add(gmtr); } } }
@DescribeProcess( title = "Length", description = "Returns the total length of all line segments in a geometry. Measurement is given in the source units, so geographic coordinates are not recommended." ) @DescribeResult(description = "Total perimeter of the geometry") public static double length( @DescribeParameter(name = "geom", description = "Input geometry") Geometry geom) { return geom.getLength(); }
if (g.getLength() != 0) { lines.add((LineString) g); return 1;
private double positiveIndex(double index) { if (index >= 0.0) return index; return linearGeom.getLength() + index; } }
/** * Returns the index of the end of the line * @return the end index */ public double getEndIndex() { return linearGeom.getLength(); }
public double getLength() { double sum = 0.0; for (int i = 0; i < geometries.length; i++) { sum += (geometries[i]).getLength(); } return sum; }
private Geometry simpleOffsetTest(Geometry geom, final double offsetDistance) { Geometry offset = offset(geom, offsetDistance); assertTrue(offset.isValid()); assertTrue(offset.getLength() > 0); assertEquals(abs(offsetDistance), offset.distance(geom), EPS * abs(offsetDistance)); offset.apply(
@Test public void testSelfIntersectRight() throws Exception { Geometry geom = geometry("LINESTRING(0 0, 10 0, 10 -10, 3 -10, 3 3)"); Geometry offset = offset(geom, -1); assertTrue(offset.isValid()); assertTrue(offset.getLength() > 0); // the offset line intersects the original one, because it's also self intersecting, so we // cannot have this test // assertEquals(2, offset.distance(geom), EPS); assertEquals(geometry("LINESTRING (0 -1, 9 -1, 9 -9, 4 -9, 4 3)"), offset); }
feature.getDefaultGeometryProperty() .getValue()) .getLength(); if (calcLength == 0 || featureLength == 0) continue; Geometry extracted = feature.getDefaultGeometryProperty() .getValue()) .getLength(); if (calcLength == 0 || featureLength == 0) continue; Geometry extracted = feature.getDefaultGeometryProperty() .getValue()) .getLength(); if (calcLength == 0 || featureLength == 0) continue; Geometry extracted = lengthIndexedLine.extractLine( 0, stopOffset * calcLength / featureLength); if (extracted.isEmpty() || extracted.getLength() == 0.0) { LOGGER.info( "Empty segment: featureFromMeasure="
@Test public void testElongatedLoopGenerator() throws Exception { Geometry geom = geometry("LINESTRING(0 0, 5 0, 5 -10, 7 -10, 7 0, 10 0)"); Geometry offset = offset(geom, 1.5); assertTrue(offset.isValid()); assertTrue(offset.getLength() > 0); // this one "fails", but the output cannot be really called wrong anymore, if we are trying // to // offset a road at least Geometry expected = geometry( "LINESTRING (0 1.5, 5 1.5, 5.260472266500395 1.477211629518312, 5.513030214988503 1.4095389311788626, 5.75 1.299038105676658, 5.964181414529809 1.149066664678467, 6.149066664678467 0.9641814145298091, 6.299038105676658 0.7500000000000002, 6.409538931178862 0.5130302149885032, 6.477211629518312 0.2604722665003956, 6.5 0.0000000000000001, 6.5 -8.5, 5.5 -8.5, 5.5 0.0000000000000001, 5.522788370481688 0.2604722665003956, 5.590461068821138 0.5130302149885032, 5.700961894323342 0.7499999999999998, 5.850933335321533 0.9641814145298091, 6.035818585470191 1.149066664678467, 6.25 1.299038105676658, 6.486969785011497 1.4095389311788624, 6.739527733499605 1.477211629518312, 7 1.5, 10 1.5)"); assertTrue(expected.equalsExact(offset, 0.1)); }
@Test public void testSelfIntersectLeft() throws Exception { Geometry geom = geometry("LINESTRING(0 0, 10 0, 10 -10, 3 -10, 3 3)"); Geometry offset = offset(geom, 2); assertTrue(offset.isValid()); assertTrue(offset.getLength() > 0); // the offset line intersects the original one, because it's also self intersecting, so we // cannot have this test // assertEquals(2, offset.distance(geom), EPS); Geometry expected = geometry( "LINESTRING (0 2, 10 2, 10.34729635533386 1.969615506024416, 10.684040286651337 1.8793852415718169, 11 1.7320508075688774, 11.28557521937308 1.532088886237956, 11.532088886237956 1.2855752193730787, 11.732050807568877 1.0000000000000002, 11.879385241571816 0.6840402866513376, 11.969615506024416 0.3472963553338608, 12 0.0000000000000001, 12 -10, 11.969615506024416 -10.34729635533386, 11.879385241571818 -10.684040286651337, 11.732050807568877 -11, 11.532088886237956 -11.28557521937308, 11.28557521937308 -11.532088886237956, 11 -11.732050807568877, 10.684040286651339 -11.879385241571816, 10.34729635533386 -11.969615506024416, 10 -12, 2.9999999999999996 -12, 2.6527036446661394 -11.969615506024416, 2.3159597133486622 -11.879385241571816, 2 -11.732050807568877, 1.714424780626921 -11.532088886237956, 1.467911113762044 -11.28557521937308, 1.2679491924311228 -11, 1.1206147584281831 -10.684040286651337, 1.030384493975584 -10.34729635533386, 1 -10, 1 3)"); assertTrue(expected.equalsExact(offset, 0.1)); }
private void writeGeomStats(String label, Geometry g, StringBuffer buf) { if (g == null) return; buf.append(label + " : "); buf.append(GeometryUtil.structureSummary(g)); buf.append("\n"); buf.append(" Length = " + g.getLength() + " Area = " + g.getArea() + "\n"); buf.append("\n"); }
double startOffset = measure - featureFromMeasure; double calcLength = ((Geometry) feature.getDefaultGeometryProperty().getValue()).getLength(); if (calcLength == 0) { LOGGER.info("Edge feature has zero length");
public static Geometry sortByLength(Geometry g) { List geoms = components(g); Collections.sort(geoms, new GeometryLengthComparator()); // annotate geometries with area for (Object o : geoms) { Geometry geom = (Geometry) o; geom.setUserData(geom.getLength()); } return g.getFactory().buildGeometry(geoms); }
double lineLength = ((Geometry) nearestFeature.getDefaultGeometryProperty().getValue()) .getLength(); Double featureFromMeasure = (Double) nearestFeature.getProperty(fromMeasureAttb).getValue();
public void checkLength(String wkt, double expectedValue) throws Exception { Geometry g = reader.read(wkt); double len = g.getLength(); // //System.out.println(len); assertEquals(expectedValue, len, TOLERANCE); }