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

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

本文整理了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

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

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

@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();
}

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

public double getLength() {
  return geometry.getLength();
}

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

@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);
    }
  }
}

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

@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();
}

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

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

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

private double positiveIndex(double index)
 {
  if (index >= 0.0) return index;
  return linearGeom.getLength() + index;
 }
}

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

/**
 * Returns the index of the end of the line
 * @return the end index
 */
public double getEndIndex()
{
 return linearGeom.getLength();
}

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

public double getLength()
{
 double sum = 0.0;
 for (int i = 0; i < geometries.length; i++) {
  sum += (geometries[i]).getLength();
 }
 return sum;
}

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

public int compare(Object o1, Object o2)
 {
  Geometry g1 = (Geometry) o1;
  Geometry g2 = (Geometry) o2;
  return Double.compare(g1.getLength(), g2.getLength());
 }
}

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

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(

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

@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);
}

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

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="

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

@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));
}

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

@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));
}

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

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");
}

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

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

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

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);
}

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

double lineLength =
    ((Geometry) nearestFeature.getDefaultGeometryProperty().getValue())
        .getLength();
Double featureFromMeasure =
    (Double) nearestFeature.getProperty(fromMeasureAttb).getValue();

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

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);
  }

相关文章