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

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

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

Geometry.getCentroid介绍

[英]Computes the centroid of this Geometry. The centroid is equal to the centroid of the set of component Geometries of highest dimension (since the lower-dimension geometries contribute zero "weight" to the centroid).

The centroid of an empty geometry is POINT EMPTY.
[中]计算此Geometry的质心。质心等于最高尺寸组件几何图形集的质心(因为较低尺寸几何图形对质心的“权重”为零)。
空几何体的质心为POINT EMPTY

代码示例

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

  1. public static Geometry centroid(Geometry arg0) {
  2. if (arg0 == null) return null;
  3. Geometry _this = arg0;
  4. return _this.getCentroid();
  5. }

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

  1. public Point getCentroid() {
  2. return geometry.getCentroid();
  3. }

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

  1. public Point toPoint() {
  2. Geometry geometry = toGeometry();
  3. return geometry.getCentroid();
  4. }

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

  1. public Object evaluate(Object feature) {
  2. Geometry arg0;
  3. try { // attempt to get value and perform conversion
  4. arg0 = (Geometry) getExpression(0).evaluate(feature);
  5. } catch (Exception e) // probably a type error
  6. {
  7. throw new IllegalArgumentException(
  8. "Filter Function problem for function getZ argument #0 - expected type Geometry");
  9. }
  10. return new Double(arg0.getCentroid().getCoordinate().z);
  11. }
  12. }

代码示例来源: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. @DescribeProcess(
  2. title = "Centroid",
  3. description =
  4. "Returns the geometric centroid of a geometry. Output is a single point. The centroid point may be located outside the geometry."
  5. )
  6. @DescribeResult(description = "Centroid of the input geometry")
  7. public static Geometry centroid(
  8. @DescribeParameter(name = "geom", description = "Input geometry") Geometry geom) {
  9. return geom.getCentroid();
  10. }

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

  1. /**
  2. * @param geometry the JTS {@link Geometry} object
  3. * @return the centroid of the given geometry
  4. */
  5. public static LatLong computeCentroid(Geometry geometry) {
  6. Point centroid = geometry.getCentroid();
  7. if (centroid != null) {
  8. return new LatLong(centroid.getCoordinate().y, centroid.getCoordinate().x);
  9. }
  10. return null;
  11. }

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

  1. if (!((g instanceof Point) || (g instanceof MultiPoint))) // handle
  2. g = g.getCentroid(); // will be point
  3. if (g instanceof Point) {
  4. Point point = (Point) g;

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

  1. @Override
  2. public JtsPoint getCenter() {
  3. if (isEmpty()) //geom.getCentroid == null
  4. return new JtsPoint(ctx.getGeometryFactory().createPoint((Coordinate)null), ctx);
  5. return new JtsPoint(geom.getCentroid(), ctx);
  6. }

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

  1. public SimpleFeature next() throws NoSuchElementException {
  2. SimpleFeature f = delegate.next();
  3. for (Object attribute : f.getAttributes()) {
  4. if ((attribute instanceof Geometry) && !(attribute instanceof Point)) {
  5. attribute = ((Geometry) attribute).getCentroid();
  6. }
  7. fb.add(attribute);
  8. }
  9. return fb.buildFeature(f.getID());
  10. }
  11. }

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

  1. /**
  2. * Returns the center of the reference geometry of the distance buffer operator, in case
  3. *
  4. * @param operator
  5. * @return
  6. */
  7. protected Coordinate getReferenceGeometryCentroid(DistanceBufferOperator operator) {
  8. Geometry geom = operator.getExpression1().evaluate(null, Geometry.class);
  9. if (geom == null) {
  10. geom = operator.getExpression2().evaluate(null, Geometry.class);
  11. }
  12. if (geom == null) {
  13. return null;
  14. }
  15. return geom.getCentroid().getCoordinate();
  16. }

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

  1. private static Geometry pointInGeometry(Geometry g) {
  2. Point p = g.getCentroid();
  3. if (g instanceof Polygon) {
  4. // if the geometry is heavily generalized centroid computation may fail and return NaN
  5. if (Double.isNaN(p.getX()) || Double.isNaN(p.getY()))
  6. return g.getFactory().createPoint(g.getCoordinate());
  7. // otherwise let's check if the point is inside. Again, this check and
  8. // "getInteriorPoint"
  9. // will work only if the geometry is valid
  10. if (g.isValid() && !g.contains(p)) {
  11. try {
  12. p = g.getInteriorPoint();
  13. } catch (Exception e) {
  14. // generalized geometries might make interior point go bye bye
  15. return p;
  16. }
  17. } else {
  18. return p;
  19. }
  20. }
  21. return p;
  22. }

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

  1. + source.toString()
  2. + " to Point. This could be unsafe");
  3. destGeometry = ((Geometry) source).getCentroid();

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

  1. } else {
  2. geom = geom.getCentroid();

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

  1. } else {
  2. LOGGER.warning("Failed to get label for geometry: " + geometry);
  3. return geometry.getCentroid();

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

  1. public DelaunayNode[] featuresToNodes(SimpleFeatureCollection fc) {
  2. SimpleFeatureIterator iter = fc.features();
  3. int size = fc.size();
  4. DelaunayNode[] nodes = new DelaunayNode[size];
  5. int index = 0;
  6. while (iter.hasNext()) {
  7. SimpleFeature next = iter.next();
  8. Geometry geom = (Geometry) next.getDefaultGeometry();
  9. Point centroid;
  10. if (geom instanceof Point) {
  11. centroid = (Point) geom;
  12. } else {
  13. centroid = geom.getCentroid();
  14. }
  15. DelaunayNode node = new DelaunayNode();
  16. node.setCoordinate(centroid.getCoordinate());
  17. node.setFeature(next);
  18. if (!(arrayContains(node, nodes, index))) {
  19. nodes[index] = node;
  20. index++;
  21. }
  22. }
  23. DelaunayNode[] trimmed = new DelaunayNode[index];
  24. for (int i = 0; i < index; i++) {
  25. trimmed[i] = nodes[i];
  26. }
  27. return trimmed;
  28. }

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

  1. public static DelaunayNode[] featureCollectionToNodeArray(SimpleFeatureCollection fc) {
  2. SimpleFeatureIterator iter = fc.features();
  3. int size = fc.size();
  4. DelaunayNode[] nodes = new DelaunayNode[size];
  5. int index = 0;
  6. while (iter.hasNext()) {
  7. SimpleFeature next = iter.next();
  8. Geometry geom = (Geometry) next.getDefaultGeometry();
  9. Point centroid;
  10. if (geom instanceof Point) {
  11. centroid = (Point) geom;
  12. } else {
  13. centroid = geom.getCentroid();
  14. }
  15. DelaunayNode node = new DelaunayNode();
  16. node.setCoordinate(centroid.getCoordinate());
  17. node.setFeature(next);
  18. if (!(arrayContains(node, nodes, index))) {
  19. nodes[index] = node;
  20. index++;
  21. }
  22. }
  23. DelaunayNode[] trimmed = new DelaunayNode[index];
  24. for (int i = 0; i < index; i++) {
  25. trimmed[i] = nodes[i];
  26. }
  27. return trimmed;
  28. }

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

  1. public InteriorPointPoint(Geometry g)
  2. {
  3. centroid = g.getCentroid().getCoordinate();
  4. add(g);
  5. }

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

  1. public InteriorPointLine(Geometry g)
  2. {
  3. centroid = g.getCentroid().getCoordinate();
  4. addInterior(g);
  5. if (interiorPoint == null)
  6. addEndpoints(g);
  7. }

相关文章