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

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

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

public void setGeom(Geometry geom) throws EmptyPolygonException, UnsupportedGeometryException {
  if (geom instanceof MultiPolygon) {
    if (geom.isEmpty()) {
      throw new EmptyPolygonException();
    }
    if (geom.getNumGeometries() > 1) {
      // LOG.warn("Multiple polygons in MultiPolygon, using only the first.");
      // TODO percolate this warning up somehow
    }
    this.geom = geom.getGeometryN(0);
  } else if( geom instanceof Point || geom instanceof Polygon){
    this.geom = geom;
  } else {
    throw new UnsupportedGeometryException( "Non-point, non-polygon Geometry, not supported." );
  }
  // cache a representative point
  Point point = geom.getCentroid();
  this.lat = point.getY();
  this.lon = point.getX();
}

代码示例来源:origin: com.vividsolutions/jts

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

代码示例来源:origin: com.vividsolutions/jts

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

代码示例来源:origin: org.geotools/gt2-main

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

代码示例来源:origin: org.orbisgis/h2spatial

public static Geometry getCentroid(Geometry geometry) {
    if(geometry==null) {
      return null;
    }
    return geometry.getCentroid();
  }
}

代码示例来源:origin: org.geotools/gt-main

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

代码示例来源:origin: org.orbisgis/h2gis-functions

public static Geometry getCentroid(Geometry geometry) {
    if(geometry==null) {
      return null;
    }
    return geometry.getCentroid();
  }
}

代码示例来源:origin: org.orbisgis/h2gis

public static Geometry getCentroid(Geometry geometry) {
    if(geometry==null) {
      return null;
    }
    return geometry.getCentroid();
  }
}

代码示例来源:origin: nl.cloudfarming.client/isobus-type

@Override
public com.vividsolutions.jts.geom.Point getCentroid() {
  Geometry temp = getGeometry();
  if(temp != null){
    return temp.getCentroid();
  }
  return null;
}

代码示例来源:origin: nl.cloudfarming.client/isobus-tree

@Override
public com.vividsolutions.jts.geom.Point getCentroid() {
  Geometry temp = getGeometry();
  if(temp != null){
    return temp.getCentroid();
  }
  return null;
}

代码示例来源:origin: eu.agrosense.client/grid

@Override
public com.vividsolutions.jts.geom.Point getCentroid() {
  checkState();
  return this.boundingBoxGeometry.getCentroid();
}

代码示例来源:origin: Stratio/cassandra-lucene-index

/**
 * Returns the center of the specified {@link JtsGeometry}.
 *
 * @param shape the JTS shape to be transformed
 * @return the center
 */
@Override
public JtsGeometry apply(JtsGeometry shape) {
  Geometry centroid = shape.getGeom().getCentroid();
  return CONTEXT.makeShape(centroid);
}

代码示例来源:origin: org.geotools/gt-main

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: BaseXdb/basex

@Override
 public Item item(final QueryContext qc, final InputInfo ii) throws QueryException {
  return toElement(checkGeo(0, qc).getCentroid(), qc);
 }
}

代码示例来源:origin: com.vividsolutions/jts-core

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

代码示例来源:origin: Stratio/cassandra-lucene-index

/**
 * Returns the center of the specified {@link JtsGeometry}.
 *
 * @return the center
 */
@Override
public JtsGeometry apply() {
  Geometry centroid = shape.apply().getGeom().getCentroid();
  return CONTEXT.makeShape(centroid);
}

代码示例来源:origin: com.spatial4j/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: org.geotools/gt-process-raster

/**
 * 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: com.vividsolutions/jts-core

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

代码示例来源:origin: org.geotools/gt-jts-wrapper

/**
 * Returns the centroid of this geometry.
 */
public final DirectPosition getCentroid() {
  com.vividsolutions.jts.geom.Geometry jtsGeom = getJTSGeometry();
  com.vividsolutions.jts.geom.Point jtsCentroid = jtsGeom.getCentroid();
  return JTSUtils.pointToDirectPosition(jtsCentroid,
      getCoordinateReferenceSystem());
}

相关文章