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

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

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

  1. private boolean testVerticesEquality(Geometry geom1, Geometry geom2) {
  2. if ( geom1.getNumPoints() != geom2.getNumPoints() ) {
  3. return false;
  4. }
  5. for ( int i = 0; i < geom1.getNumPoints(); i++ ) {
  6. Coordinate cn1 = geom1.getCoordinates()[i];
  7. Coordinate cn2 = geom2.getCoordinates()[i];
  8. if ( !cn1.equals2D( cn2 ) ) {
  9. return false;
  10. }
  11. }
  12. return true;
  13. }
  14. }

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

  1. private boolean testVerticesEquality(Geometry geom1, Geometry geom2) {
  2. if ( geom1.getNumPoints() != geom2.getNumPoints() ) {
  3. return false;
  4. }
  5. for ( int i = 0; i < geom1.getNumPoints(); i++ ) {
  6. Coordinate cn1 = geom1.getCoordinates()[i];
  7. Coordinate cn2 = geom2.getCoordinates()[i];
  8. if ( !cn1.equals2D( cn2 ) ) {
  9. return false;
  10. }
  11. }
  12. return true;
  13. }
  14. }

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

  1. private static void writePolyline(Geometry geometry, SliceOutput output, boolean multitype)
  2. {
  3. int numParts;
  4. int numPoints = geometry.getNumPoints();
  5. if (multitype) {
  6. numParts = geometry.getNumGeometries();
  7. output.writeByte(GeometrySerializationType.MULTI_LINE_STRING.code());
  8. }
  9. else {
  10. numParts = numPoints > 0 ? 1 : 0;
  11. output.writeByte(GeometrySerializationType.LINE_STRING.code());
  12. }
  13. output.writeInt(EsriShapeType.POLYLINE.code);
  14. writeEnvelope(geometry, output);
  15. output.writeInt(numParts);
  16. output.writeInt(numPoints);
  17. int partIndex = 0;
  18. for (int i = 0; i < numParts; i++) {
  19. output.writeInt(partIndex);
  20. partIndex += geometry.getGeometryN(i).getNumPoints();
  21. }
  22. writeCoordinates(geometry.getCoordinates(), output);
  23. }

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

  1. protected boolean testTypeAndVertexEquality(Geometry geom1, Geometry geom2) {
  2. if ( !geom1.getGeometryType().equals( geom2.getGeometryType() ) ) {
  3. return false;
  4. }
  5. if ( geom1.getNumGeometries() != geom2.getNumGeometries() ) {
  6. return false;
  7. }
  8. if ( geom1.getNumPoints() != geom2.getNumPoints() ) {
  9. return false;
  10. }
  11. Coordinate[] coordinates1 = geom1.getCoordinates();
  12. Coordinate[] coordinates2 = geom2.getCoordinates();
  13. for ( int i = 0; i < coordinates1.length; i++ ) {
  14. Coordinate c1 = coordinates1[i];
  15. Coordinate c2 = coordinates2[i];
  16. if ( !testCoordinateEquality( c1, c2 ) ) {
  17. return false;
  18. }
  19. }
  20. return true;
  21. }

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

  1. public static int numPoints(Geometry arg0) {
  2. if (arg0 == null) return 0;
  3. Geometry _this = arg0;
  4. return _this.getNumPoints();
  5. }

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

  1. public int getNumPoints() {
  2. return geometry.getNumPoints();
  3. }

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. private static void addElemInfo(
  2. List elemInfoList,
  3. GeometryCollection geoms,
  4. final int STARTING_OFFSET,
  5. final int GTYPE) {
  6. Geometry geom;
  7. int offset = STARTING_OFFSET;
  8. int LEN = D(GTYPE) + L(GTYPE);
  9. for (int i = 0; i < geoms.getNumGeometries(); i++) {
  10. geom = geoms.getGeometryN(i);
  11. elemInfo(elemInfoList, geom, offset, GTYPE);
  12. if (geom instanceof Polygon && isRectangle((Polygon) geom)) {
  13. offset += (2 * LEN);
  14. } else {
  15. offset += (geom.getNumPoints() * LEN);
  16. }
  17. }
  18. }

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

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

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

  1. public void testEncode() throws Exception {
  2. Geometry geometry = GML3MockData.multiLineString();
  3. GML3EncodingUtils.setID(geometry, "geometry");
  4. Document dom = encode(geometry, GML.MultiLineString);
  5. // print(dom);
  6. assertEquals("geometry", getID(dom.getDocumentElement()));
  7. assertEquals(2, dom.getElementsByTagNameNS(GML.NAMESPACE, "lineStringMember").getLength());
  8. NodeList children =
  9. dom.getElementsByTagNameNS(GML.NAMESPACE, GML.LineString.getLocalPart());
  10. assertEquals(2, children.getLength());
  11. assertEquals("geometry.1", getID(children.item(0)));
  12. assertEquals("geometry.2", getID(children.item(1)));
  13. checkDimension(dom, GML.MultiLineString.getLocalPart(), 2);
  14. checkDimension(dom, GML.LineString.getLocalPart(), 2);
  15. checkPosListOrdinates(dom, 2 * geometry.getGeometryN(0).getNumPoints());
  16. }
  17. }

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

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

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

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

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

  1. public void testSimplification() throws Exception {
  2. SimpleFeatureSource fs = dataStore.getFeatureSource(tname("road"));
  3. if (fs.getSupportedHints().contains(Hints.GEOMETRY_SIMPLIFICATION) == false) return;
  4. SimpleFeatureCollection fColl = fs.getFeatures();
  5. Geometry original = null;
  6. try (SimpleFeatureIterator iterator = fColl.features()) {
  7. if (iterator.hasNext()) {
  8. original = (Geometry) iterator.next().getDefaultGeometry();
  9. }
  10. }
  11. double width = original.getEnvelope().getEnvelopeInternal().getWidth();
  12. Query query = new Query();
  13. Hints hints = new Hints(Hints.GEOMETRY_SIMPLIFICATION, width / 2);
  14. query.setHints(hints);
  15. Geometry simplified = null;
  16. fColl = fs.getFeatures(query);
  17. try (SimpleFeatureIterator iterator = fColl.features()) {
  18. if (iterator.hasNext()) simplified = (Geometry) iterator.next().getDefaultGeometry();
  19. }
  20. assertTrue(original.getNumPoints() >= simplified.getNumPoints());
  21. }

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

  1. public void testGeneralization() throws Exception {
  2. SimpleFeatureSource fs = dataStore.getFeatureSource(tname("lake"));
  3. if (fs.getSupportedHints().contains(Hints.GEOMETRY_GENERALIZATION) == false) return;
  4. SimpleFeatureCollection fColl = fs.getFeatures();
  5. Geometry original = null;
  6. try (SimpleFeatureIterator iterator = fColl.features()) {
  7. if (iterator.hasNext()) {
  8. original = (Geometry) iterator.next().getDefaultGeometry();
  9. }
  10. }
  11. double width = original.getEnvelope().getEnvelopeInternal().getWidth();
  12. Query query = new Query();
  13. Hints hints = new Hints(Hints.GEOMETRY_GENERALIZATION, width / 2);
  14. query.setHints(hints);
  15. Geometry generalized = null;
  16. fColl = fs.getFeatures(query);
  17. try (SimpleFeatureIterator iterator = fColl.features()) {
  18. if (iterator.hasNext()) {
  19. generalized = (Geometry) iterator.next().getDefaultGeometry();
  20. }
  21. }
  22. assertTrue(original.getNumPoints() >= generalized.getNumPoints());
  23. }

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

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

相关文章