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

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

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

Geometry.getNumPoints介绍

[英]Returns the count of this Geometrys vertices. The Geometry s contained by composite Geometrys must be Geometry's; that is, they must implement getNumPoints
[中]返回此Geometrys顶点的计数。复合Geometrys包含的Geometrys必须是几何体的;也就是说,他们必须实现getNumPoints

代码示例

代码示例来源:origin: hibernate/hibernate-orm

private boolean testVerticesEquality(Geometry geom1, Geometry geom2) {
    if ( geom1.getNumPoints() != geom2.getNumPoints() ) {
      return false;
    }
    for ( int i = 0; i < geom1.getNumPoints(); i++ ) {
      Coordinate cn1 = geom1.getCoordinates()[i];
      Coordinate cn2 = geom2.getCoordinates()[i];
      if ( !cn1.equals2D( cn2 ) ) {
        return false;
      }
    }
    return true;
  }
}

代码示例来源:origin: hibernate/hibernate-orm

private boolean testVerticesEquality(Geometry geom1, Geometry geom2) {
    if ( geom1.getNumPoints() != geom2.getNumPoints() ) {
      return false;
    }
    for ( int i = 0; i < geom1.getNumPoints(); i++ ) {
      Coordinate cn1 = geom1.getCoordinates()[i];
      Coordinate cn2 = geom2.getCoordinates()[i];
      if ( !cn1.equals2D( cn2 ) ) {
        return false;
      }
    }
    return true;
  }
}

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

private static void writePolyline(Geometry geometry, SliceOutput output, boolean multitype)
{
  int numParts;
  int numPoints = geometry.getNumPoints();
  if (multitype) {
    numParts = geometry.getNumGeometries();
    output.writeByte(GeometrySerializationType.MULTI_LINE_STRING.code());
  }
  else {
    numParts = numPoints > 0 ? 1 : 0;
    output.writeByte(GeometrySerializationType.LINE_STRING.code());
  }
  output.writeInt(EsriShapeType.POLYLINE.code);
  writeEnvelope(geometry, output);
  output.writeInt(numParts);
  output.writeInt(numPoints);
  int partIndex = 0;
  for (int i = 0; i < numParts; i++) {
    output.writeInt(partIndex);
    partIndex += geometry.getGeometryN(i).getNumPoints();
  }
  writeCoordinates(geometry.getCoordinates(), output);
}

代码示例来源:origin: hibernate/hibernate-orm

protected boolean testTypeAndVertexEquality(Geometry geom1, Geometry geom2) {
  if ( !geom1.getGeometryType().equals( geom2.getGeometryType() ) ) {
    return false;
  }
  if ( geom1.getNumGeometries() != geom2.getNumGeometries() ) {
    return false;
  }
  if ( geom1.getNumPoints() != geom2.getNumPoints() ) {
    return false;
  }
  Coordinate[] coordinates1 = geom1.getCoordinates();
  Coordinate[] coordinates2 = geom2.getCoordinates();
  for ( int i = 0; i < coordinates1.length; i++ ) {
    Coordinate c1 = coordinates1[i];
    Coordinate c2 = coordinates2[i];
    if ( !testCoordinateEquality( c1, c2 ) ) {
      return false;
    }
  }
  return true;
}

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

public static int numPoints(Geometry arg0) {
  if (arg0 == null) return 0;
  Geometry _this = arg0;
  return _this.getNumPoints();
}

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

public int getNumPoints() {
  return geometry.getNumPoints();
}

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

int numPoints = geometry.getNumPoints();
for (int i = 0; i < numGeometries; i++) {
  Polygon polygon = (Polygon) geometry.getGeometryN(i);

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

@DescribeProcess(
  title = "Number of Points",
  description = "Returns the number of vertices in a given geometry."
)
@DescribeResult(description = "Total number of vertices")
public static int numPoints(
    @DescribeParameter(name = "geom", description = "Input geometry") Geometry geom) {
  return geom.getNumPoints();
}

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

/**
 * Gets a point to represent the Geometry. If the Geometry is a point, this is returned.
 * Otherwise, the centroid is used.
 *
 * @param g the geometry to find a point for
 * @return a point representing the Geometry
 */
private static Coordinate getPoint(Geometry g) {
  if (g.getNumPoints() == 1) return g.getCoordinate();
  return g.getCentroid().getCoordinate();
}

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

/**
 * Gets a point to represent the Geometry. If the Geometry is a point, this is returned.
 * Otherwise, the centroid is used.
 *
 * @param g the geometry to find a point for
 * @return a point representing the Geometry
 */
private static Coordinate getRepresentativePoint(Geometry g) {
  if (g.getNumPoints() == 1) return g.getCoordinate();
  return g.getCentroid().getCoordinate();
}

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

LOGGER.finer("\tpoints: " + geom.getNumPoints());
} else {
  LOGGER.finer("got a null geometry back from gml parser");

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

coordinates += g.getNumPoints();
if (maxCoordinates > 0 && coordinates > maxCoordinates) {
  throw new IllegalStateException(

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

private static void addElemInfo(
    List elemInfoList,
    GeometryCollection geoms,
    final int STARTING_OFFSET,
    final int GTYPE) {
  Geometry geom;
  int offset = STARTING_OFFSET;
  int LEN = D(GTYPE) + L(GTYPE);
  for (int i = 0; i < geoms.getNumGeometries(); i++) {
    geom = geoms.getGeometryN(i);
    elemInfo(elemInfoList, geom, offset, GTYPE);
    if (geom instanceof Polygon && isRectangle((Polygon) geom)) {
      offset += (2 * LEN);
    } else {
      offset += (geom.getNumPoints() * LEN);
    }
  }
}

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

ensureNonNull("geometry", geometry);
if ((minPoints <= 0) || (geometry.getNumPoints() < minPoints)) {
  return geometry;

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

public void testEncode() throws Exception {
    Geometry geometry = GML3MockData.multiLineString();
    GML3EncodingUtils.setID(geometry, "geometry");
    Document dom = encode(geometry, GML.MultiLineString);
    // print(dom);
    assertEquals("geometry", getID(dom.getDocumentElement()));
    assertEquals(2, dom.getElementsByTagNameNS(GML.NAMESPACE, "lineStringMember").getLength());
    NodeList children =
        dom.getElementsByTagNameNS(GML.NAMESPACE, GML.LineString.getLocalPart());
    assertEquals(2, children.getLength());
    assertEquals("geometry.1", getID(children.item(0)));
    assertEquals("geometry.2", getID(children.item(1)));

    checkDimension(dom, GML.MultiLineString.getLocalPart(), 2);
    checkDimension(dom, GML.LineString.getLocalPart(), 2);
    checkPosListOrdinates(dom, 2 * geometry.getGeometryN(0).getNumPoints());
  }
}

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

Geometry g = (Geometry) value;
if ((g == null) || (g.getNumPoints() == 0) || (g.getCoordinates().length == 0)) {
  return;

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

final Geometry original = JTS.toGeometry(shape);
final Geometry reduced = JTS.removeCollinearVertices(original);
assertEquals(10, original.getNumPoints());
assertEquals(5, reduced.getNumPoints());
final double DELTA = 1E-9;

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

public void testSimplification() throws Exception {
  SimpleFeatureSource fs = dataStore.getFeatureSource(tname("road"));
  if (fs.getSupportedHints().contains(Hints.GEOMETRY_SIMPLIFICATION) == false) return;
  SimpleFeatureCollection fColl = fs.getFeatures();
  Geometry original = null;
  try (SimpleFeatureIterator iterator = fColl.features()) {
    if (iterator.hasNext()) {
      original = (Geometry) iterator.next().getDefaultGeometry();
    }
  }
  double width = original.getEnvelope().getEnvelopeInternal().getWidth();
  Query query = new Query();
  Hints hints = new Hints(Hints.GEOMETRY_SIMPLIFICATION, width / 2);
  query.setHints(hints);
  Geometry simplified = null;
  fColl = fs.getFeatures(query);
  try (SimpleFeatureIterator iterator = fColl.features()) {
    if (iterator.hasNext()) simplified = (Geometry) iterator.next().getDefaultGeometry();
  }
  assertTrue(original.getNumPoints() >= simplified.getNumPoints());
}

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

public void testGeneralization() throws Exception {
  SimpleFeatureSource fs = dataStore.getFeatureSource(tname("lake"));
  if (fs.getSupportedHints().contains(Hints.GEOMETRY_GENERALIZATION) == false) return;
  SimpleFeatureCollection fColl = fs.getFeatures();
  Geometry original = null;
  try (SimpleFeatureIterator iterator = fColl.features()) {
    if (iterator.hasNext()) {
      original = (Geometry) iterator.next().getDefaultGeometry();
    }
  }
  double width = original.getEnvelope().getEnvelopeInternal().getWidth();
  Query query = new Query();
  Hints hints = new Hints(Hints.GEOMETRY_GENERALIZATION, width / 2);
  query.setHints(hints);
  Geometry generalized = null;
  fColl = fs.getFeatures(query);
  try (SimpleFeatureIterator iterator = fColl.features()) {
    if (iterator.hasNext()) {
      generalized = (Geometry) iterator.next().getDefaultGeometry();
    }
  }
  assertTrue(original.getNumPoints() >= generalized.getNumPoints());
}

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

geometry = reader.read(WKT);
assertNotNull("parsed perfect circle", geometry);
assertEquals(11, geometry.getNumPoints());

相关文章