org.locationtech.jts.geom.Geometry.getLength()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(378)

本文整理了Java中org.locationtech.jts.geom.Geometry.getLength()方法的一些代码示例,展示了Geometry.getLength()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Geometry.getLength()方法的具体详情如下:
包路径:org.locationtech.jts.geom.Geometry
类名称:Geometry
方法名:getLength

Geometry.getLength介绍

[英]Returns the length of this Geometry. Linear geometries return their length. Areal geometries return their perimeter. They override this function to compute the area. Others return 0.0
[中]返回此Geometry的长度。线性几何体返回其长度。面积几何体返回其周长。它们覆盖此函数以计算面积。其他人返回0.0

代码示例

代码示例来源:origin: geotools/geotools

  1. public static double geomLength(Geometry arg0) {
  2. if (arg0 == null) return 0d;
  3. Geometry _this = arg0;
  4. return _this.getLength();
  5. }

代码示例来源:origin: prestodb/presto

  1. @SqlNullable
  2. @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.")
  3. @ScalarFunction("line_locate_point")
  4. @SqlType(DOUBLE)
  5. public static Double lineLocatePoint(@SqlType(GEOMETRY_TYPE_NAME) Slice lineSlice, @SqlType(GEOMETRY_TYPE_NAME) Slice pointSlice)
  6. {
  7. Geometry line = JtsGeometrySerde.deserialize(lineSlice);
  8. Geometry point = JtsGeometrySerde.deserialize(pointSlice);
  9. if (line.isEmpty() || point.isEmpty()) {
  10. return null;
  11. }
  12. GeometryType lineType = GeometryType.getForJtsGeometryType(line.getGeometryType());
  13. if (lineType != GeometryType.LINE_STRING && lineType != GeometryType.MULTI_LINE_STRING) {
  14. throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("First argument to line_locate_point must be a LineString or a MultiLineString. Got: %s", line.getGeometryType()));
  15. }
  16. GeometryType pointType = GeometryType.getForJtsGeometryType(point.getGeometryType());
  17. if (pointType != GeometryType.POINT) {
  18. throw new PrestoException(INVALID_FUNCTION_ARGUMENT, format("Second argument to line_locate_point must be a Point. Got: %s", point.getGeometryType()));
  19. }
  20. return new LengthIndexedLine(line).indexOf(point.getCoordinate()) / line.getLength();
  21. }

代码示例来源:origin: geotools/geotools

  1. public double getLength() {
  2. return geometry.getLength();
  3. }

代码示例来源:origin: geotools/geotools

  1. @Override
  2. public void filter(Geometry gmtr) {
  3. if (MultiPolygon.class.isAssignableFrom(binding)) {
  4. if (gmtr.getArea() != 0.0d && gmtr.getGeometryType().equals("Polygon")) {
  5. collection.add(gmtr);
  6. }
  7. }
  8. if (MultiLineString.class.isAssignableFrom(binding)) {
  9. if (gmtr.getLength() != 0.0d && gmtr.getGeometryType().equals("LineString")) {
  10. collection.add(gmtr);
  11. }
  12. }
  13. if (MultiPoint.class.isAssignableFrom(binding)) {
  14. if (gmtr.getNumGeometries() > 0 && gmtr.getGeometryType().equals("Point")) {
  15. collection.add(gmtr);
  16. }
  17. }
  18. if (Point.class.isAssignableFrom(binding)) {
  19. if (gmtr.getGeometryType().equals("Point")) {
  20. collection.add(gmtr);
  21. }
  22. }
  23. }

代码示例来源:origin: geotools/geotools

  1. @DescribeProcess(
  2. title = "Length",
  3. description =
  4. "Returns the total length of all line segments in a geometry. Measurement is given in the source units, so geographic coordinates are not recommended."
  5. )
  6. @DescribeResult(description = "Total perimeter of the geometry")
  7. public static double length(
  8. @DescribeParameter(name = "geom", description = "Input geometry") Geometry geom) {
  9. return geom.getLength();
  10. }

代码示例来源:origin: geotools/geotools

  1. if (g.getLength() != 0) {
  2. lines.add((LineString) g);
  3. return 1;

代码示例来源:origin: locationtech/jts

  1. private double positiveIndex(double index)
  2. {
  3. if (index >= 0.0) return index;
  4. return linearGeom.getLength() + index;
  5. }
  6. }

代码示例来源:origin: locationtech/jts

  1. /**
  2. * Returns the index of the end of the line
  3. * @return the end index
  4. */
  5. public double getEndIndex()
  6. {
  7. return linearGeom.getLength();
  8. }

代码示例来源:origin: locationtech/jts

  1. public double getLength()
  2. {
  3. double sum = 0.0;
  4. for (int i = 0; i < geometries.length; i++) {
  5. sum += (geometries[i]).getLength();
  6. }
  7. return sum;
  8. }

代码示例来源:origin: locationtech/jts

  1. public int compare(Object o1, Object o2)
  2. {
  3. Geometry g1 = (Geometry) o1;
  4. Geometry g2 = (Geometry) o2;
  5. return Double.compare(g1.getLength(), g2.getLength());
  6. }
  7. }

代码示例来源:origin: geotools/geotools

  1. private Geometry simpleOffsetTest(Geometry geom, final double offsetDistance) {
  2. Geometry offset = offset(geom, offsetDistance);
  3. assertTrue(offset.isValid());
  4. assertTrue(offset.getLength() > 0);
  5. assertEquals(abs(offsetDistance), offset.distance(geom), EPS * abs(offsetDistance));
  6. offset.apply(

代码示例来源:origin: geotools/geotools

  1. @Test
  2. public void testSelfIntersectRight() throws Exception {
  3. Geometry geom = geometry("LINESTRING(0 0, 10 0, 10 -10, 3 -10, 3 3)");
  4. Geometry offset = offset(geom, -1);
  5. assertTrue(offset.isValid());
  6. assertTrue(offset.getLength() > 0);
  7. // the offset line intersects the original one, because it's also self intersecting, so we
  8. // cannot have this test
  9. // assertEquals(2, offset.distance(geom), EPS);
  10. assertEquals(geometry("LINESTRING (0 -1, 9 -1, 9 -9, 4 -9, 4 3)"), offset);
  11. }

代码示例来源:origin: geotools/geotools

  1. feature.getDefaultGeometryProperty()
  2. .getValue())
  3. .getLength();
  4. if (calcLength == 0 || featureLength == 0) continue;
  5. Geometry extracted =
  6. feature.getDefaultGeometryProperty()
  7. .getValue())
  8. .getLength();
  9. if (calcLength == 0 || featureLength == 0) continue;
  10. Geometry extracted =
  11. feature.getDefaultGeometryProperty()
  12. .getValue())
  13. .getLength();
  14. if (calcLength == 0 || featureLength == 0) continue;
  15. Geometry extracted =
  16. lengthIndexedLine.extractLine(
  17. 0, stopOffset * calcLength / featureLength);
  18. if (extracted.isEmpty() || extracted.getLength() == 0.0) {
  19. LOGGER.info(
  20. "Empty segment: featureFromMeasure="

代码示例来源:origin: geotools/geotools

  1. @Test
  2. public void testElongatedLoopGenerator() throws Exception {
  3. Geometry geom = geometry("LINESTRING(0 0, 5 0, 5 -10, 7 -10, 7 0, 10 0)");
  4. Geometry offset = offset(geom, 1.5);
  5. assertTrue(offset.isValid());
  6. assertTrue(offset.getLength() > 0);
  7. // this one "fails", but the output cannot be really called wrong anymore, if we are trying
  8. // to
  9. // offset a road at least
  10. Geometry expected =
  11. geometry(
  12. "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)");
  13. assertTrue(expected.equalsExact(offset, 0.1));
  14. }

代码示例来源:origin: geotools/geotools

  1. @Test
  2. public void testSelfIntersectLeft() throws Exception {
  3. Geometry geom = geometry("LINESTRING(0 0, 10 0, 10 -10, 3 -10, 3 3)");
  4. Geometry offset = offset(geom, 2);
  5. assertTrue(offset.isValid());
  6. assertTrue(offset.getLength() > 0);
  7. // the offset line intersects the original one, because it's also self intersecting, so we
  8. // cannot have this test
  9. // assertEquals(2, offset.distance(geom), EPS);
  10. Geometry expected =
  11. geometry(
  12. "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)");
  13. assertTrue(expected.equalsExact(offset, 0.1));
  14. }

代码示例来源:origin: locationtech/jts

  1. private void writeGeomStats(String label,
  2. Geometry g, StringBuffer buf)
  3. {
  4. if (g == null) return;
  5. buf.append(label + " : ");
  6. buf.append(GeometryUtil.structureSummary(g));
  7. buf.append("\n");
  8. buf.append(" Length = " + g.getLength() + " Area = " + g.getArea() + "\n");
  9. buf.append("\n");
  10. }

代码示例来源:origin: geotools/geotools

  1. double startOffset = measure - featureFromMeasure;
  2. double calcLength =
  3. ((Geometry) feature.getDefaultGeometryProperty().getValue()).getLength();
  4. if (calcLength == 0) {
  5. LOGGER.info("Edge feature has zero length");

代码示例来源:origin: locationtech/jts

  1. public static Geometry sortByLength(Geometry g)
  2. {
  3. List geoms = components(g);
  4. Collections.sort(geoms, new GeometryLengthComparator());
  5. // annotate geometries with area
  6. for (Object o : geoms) {
  7. Geometry geom = (Geometry) o;
  8. geom.setUserData(geom.getLength());
  9. }
  10. return g.getFactory().buildGeometry(geoms);
  11. }

代码示例来源:origin: geotools/geotools

  1. double lineLength =
  2. ((Geometry) nearestFeature.getDefaultGeometryProperty().getValue())
  3. .getLength();
  4. Double featureFromMeasure =
  5. (Double) nearestFeature.getProperty(fromMeasureAttb).getValue();

代码示例来源:origin: locationtech/jts

  1. public void checkLength(String wkt, double expectedValue) throws Exception {
  2. Geometry g = reader.read(wkt);
  3. double len = g.getLength();
  4. // //System.out.println(len);
  5. assertEquals(expectedValue, len, TOLERANCE);
  6. }

相关文章