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

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

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

public static Geometry centroid(Geometry arg0) {
  if (arg0 == null) return null;
  Geometry _this = arg0;
  return _this.getCentroid();
}

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

public Point getCentroid() {
  return geometry.getCentroid();
}

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

public Point toPoint() {
  Geometry geometry = toGeometry();
  return geometry.getCentroid();
}

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

public Object evaluate(Object feature) {
    Geometry arg0;

    try { // attempt to get value and perform conversion
      arg0 = (Geometry) getExpression(0).evaluate(feature);
    } catch (Exception e) // probably a type error
    {
      throw new IllegalArgumentException(
          "Filter Function problem for function getZ argument #0 - expected type Geometry");
    }

    return new Double(arg0.getCentroid().getCoordinate().z);
  }
}

代码示例来源: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

@DescribeProcess(
  title = "Centroid",
  description =
      "Returns the geometric centroid of a geometry. Output is a single point.  The centroid point may be located outside the geometry."
)
@DescribeResult(description = "Centroid of the input geometry")
public static Geometry centroid(
    @DescribeParameter(name = "geom", description = "Input geometry") Geometry geom) {
  return geom.getCentroid();
}

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

/**
 * @param geometry the JTS {@link Geometry} object
 * @return the centroid of the given geometry
 */
public static LatLong computeCentroid(Geometry geometry) {
  Point centroid = geometry.getCentroid();
  if (centroid != null) {
    return new LatLong(centroid.getCoordinate().y, centroid.getCoordinate().x);
  }
  return null;
}

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

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

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

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

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

public SimpleFeature next() throws NoSuchElementException {
    SimpleFeature f = delegate.next();
    for (Object attribute : f.getAttributes()) {
      if ((attribute instanceof Geometry) && !(attribute instanceof Point)) {
        attribute = ((Geometry) attribute).getCentroid();
      }
      fb.add(attribute);
    }
    return fb.buildFeature(f.getID());
  }
}

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

/**
 * Returns the center of the reference geometry of the distance buffer operator, in case
 *
 * @param operator
 * @return
 */
protected Coordinate getReferenceGeometryCentroid(DistanceBufferOperator operator) {
  Geometry geom = operator.getExpression1().evaluate(null, Geometry.class);
  if (geom == null) {
    geom = operator.getExpression2().evaluate(null, Geometry.class);
  }
  if (geom == null) {
    return null;
  }
  return geom.getCentroid().getCoordinate();
}

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

private static Geometry pointInGeometry(Geometry g) {
  Point p = g.getCentroid();
  if (g instanceof Polygon) {
    // if the geometry is heavily generalized centroid computation may fail and return NaN
    if (Double.isNaN(p.getX()) || Double.isNaN(p.getY()))
      return g.getFactory().createPoint(g.getCoordinate());
    // otherwise let's check if the point is inside. Again, this check and
    // "getInteriorPoint"
    // will work only if the geometry is valid
    if (g.isValid() && !g.contains(p)) {
      try {
        p = g.getInteriorPoint();
      } catch (Exception e) {
        // generalized geometries might make interior point go bye bye
        return p;
      }
    } else {
      return p;
    }
  }
  return p;
}

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

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

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

} else {
  geom = geom.getCentroid();

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

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

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

public DelaunayNode[] featuresToNodes(SimpleFeatureCollection fc) {
  SimpleFeatureIterator iter = fc.features();
  int size = fc.size();
  DelaunayNode[] nodes = new DelaunayNode[size];
  int index = 0;
  while (iter.hasNext()) {
    SimpleFeature next = iter.next();
    Geometry geom = (Geometry) next.getDefaultGeometry();
    Point centroid;
    if (geom instanceof Point) {
      centroid = (Point) geom;
    } else {
      centroid = geom.getCentroid();
    }
    DelaunayNode node = new DelaunayNode();
    node.setCoordinate(centroid.getCoordinate());
    node.setFeature(next);
    if (!(arrayContains(node, nodes, index))) {
      nodes[index] = node;
      index++;
    }
  }
  DelaunayNode[] trimmed = new DelaunayNode[index];
  for (int i = 0; i < index; i++) {
    trimmed[i] = nodes[i];
  }
  return trimmed;
}

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

public static DelaunayNode[] featureCollectionToNodeArray(SimpleFeatureCollection fc) {
  SimpleFeatureIterator iter = fc.features();
  int size = fc.size();
  DelaunayNode[] nodes = new DelaunayNode[size];
  int index = 0;
  while (iter.hasNext()) {
    SimpleFeature next = iter.next();
    Geometry geom = (Geometry) next.getDefaultGeometry();
    Point centroid;
    if (geom instanceof Point) {
      centroid = (Point) geom;
    } else {
      centroid = geom.getCentroid();
    }
    DelaunayNode node = new DelaunayNode();
    node.setCoordinate(centroid.getCoordinate());
    node.setFeature(next);
    if (!(arrayContains(node, nodes, index))) {
      nodes[index] = node;
      index++;
    }
  }
  DelaunayNode[] trimmed = new DelaunayNode[index];
  for (int i = 0; i < index; i++) {
    trimmed[i] = nodes[i];
  }
  return trimmed;
}

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

public InteriorPointPoint(Geometry g)
{
 centroid = g.getCentroid().getCoordinate();
 add(g);
}

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

public InteriorPointLine(Geometry g)
{
 centroid = g.getCentroid().getCoordinate();
 addInterior(g);
 if (interiorPoint == null)
  addEndpoints(g);
}

相关文章