org.locationtech.jts.geom.Polygon类的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(169)

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

Polygon介绍

[英]Represents a polygon with linear edges, which may include holes. The outer boundary (shell) and inner boundaries (holes) of the polygon are represented by LinearRings. The boundary rings of the polygon may have any orientation. Polygons are closed, simple geometries by definition.

The polygon model conforms to the assertions specified in the OpenGIS Simple Features Specification for SQL.

A Polygon is topologically valid if and only if:

  • the coordinates which define it are valid coordinates
  • the linear rings for the shell and holes are valid (i.e. are closed and do not self-intersect)
  • holes touch the shell or another hole at at most one point (which implies that the rings of the shell and holes must not cross)
  • the interior of the polygon is connected, or equivalently no sequence of touching holes makes the interior of the polygon disconnected (i.e. effectively split the polygon into two pieces).
    [中]表示具有线性边(可能包括孔)的多边形。多边形的外边界(壳)和内边界(孔)由线性毛刺表示。多边形的边界环可以有任何方向。多边形是封闭的、简单的几何体。
    多边形模型符合OpenGIS Simple Features Specification for SQL中指定的断言。
    当且仅当满足以下条件时,Polygon在拓扑上有效:
    *定义它的坐标是有效坐标
    *壳体和孔的线性环有效(即闭合且不自相交)
    *孔最多在一个点接触壳体或另一个孔(这意味着壳体环和孔不得交叉)
    *多边形的内部是连接的,或者等效地,没有一系列接触孔会使多边形的内部断开(即,有效地将多边形分割为两部分)。

代码示例

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

public Object getProperty(Object object, QName name) throws Exception {
    Polygon p = (Polygon) object;
    if ("outerBoundaryIs".equals(name.getLocalPart())) {
      return p.getExteriorRing();
    } else if ("innerBoundaryIs".equals(name.getLocalPart())) {
      if (p.getNumInteriorRing() > 0) {
        LinearRing[] interior = new LinearRing[p.getNumInteriorRing()];
        for (int i = 0; i < interior.length; i++) {
          interior[i] = (LinearRing) p.getInteriorRingN(i);
        }

        return interior;
      }
    }

    return null;
  }
}

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

/**
   * @param polygon
   * @throws TransformException
   */
  public Polygon transformPolygon(Polygon polygon, GeometryFactory gf) throws TransformException {
    LinearRing exterior = (LinearRing) transformLineString(polygon.getExteriorRing(), gf);
    LinearRing[] interiors = new LinearRing[polygon.getNumInteriorRing()];

    for (int i = 0; i < interiors.length; i++) {
      interiors[i] = (LinearRing) transformLineString(polygon.getInteriorRingN(i), gf);
    }

    Polygon transformed = gf.createPolygon(exterior, interiors);
    transformed.setUserData(polygon.getUserData());
    return transformed;
  }
}

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

public Envelope getEnvelopeInternal() {
  return polygon.getEnvelopeInternal();
}

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

/**
 * Lossy conversion to a GraphHopper Polygon.
 */
public static Polygon create(org.locationtech.jts.geom.Polygon polygon) {
  double[] lats = new double[polygon.getNumPoints()];
  double[] lons = new double[polygon.getNumPoints()];
  for (int i = 0; i < polygon.getNumPoints(); i++) {
    lats[i] = polygon.getCoordinates()[i].y;
    lons[i] = polygon.getCoordinates()[i].x;
  }
  return new Polygon(lats, lons);
}

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

shell.setUserData(new ArrayList<LinearRing>());
    if (shell.contains(hole)) {
      ((List<LinearRing>) shell.getUserData()).add(hole);
      break outer;
List<LinearRing> shellHoles = ((List<LinearRing>) shell.getUserData());
punched.add(geometryFactory.createPolygon((LinearRing) (shell.getExteriorRing()),
    shellHoles.toArray(new LinearRing[shellHoles.size()])));

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

for (int j = 0; j < multiPolygon.getNumGeometries(); j++) {
  Polygon polygon = (Polygon) multiPolygon.getGeometryN(j);
  if (polygon.getNumPoints() > maxPoints) {
    maxPoints = polygon.getNumPoints();
    maxPolygon = polygon;
  throw new IllegalStateException("no maximum polygon was found?");
} else {
  polygonShells.add(maxPolygon.getExteriorRing().getCoordinates());

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

/**
 * Create a nice Polygon from the given Polygon. Will ensure that shells are clockwise and holes
 * are counter-clockwise. Capiche?
 *
 * @param p The Polygon to make "nice".
 * @return The "nice" Polygon.
 */
public static final Polygon makeGoodShapePolygon(Polygon p) {
  GeometryFactory factory = p.getFactory();
  LinearRing outer;
  LinearRing[] holes = new LinearRing[p.getNumInteriorRing()];
  Coordinate[] coords;
  coords = p.getExteriorRing().getCoordinates();
  if (CGAlgorithms.isCCW(coords)) {
    outer = reverseRing((LinearRing) p.getExteriorRing());
  } else {
    outer = (LinearRing) p.getExteriorRing();
  }
  for (int t = 0, tt = p.getNumInteriorRing(); t < tt; t++) {
    coords = p.getInteriorRingN(t).getCoordinates();
    if (!(CGAlgorithms.isCCW(coords))) {
      holes[t] = reverseRing((LinearRing) p.getInteriorRingN(t));
    } else {
      holes[t] = (LinearRing) p.getInteriorRingN(t);
    }
  }
  return factory.createPolygon(outer, holes);
}

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

for (int i = 0; i < numGeometries; i++) {
  Polygon polygon = (Polygon) geometry.getGeometryN(i);
  if (polygon.getNumPoints() > 0) {
    numParts += polygon.getNumInteriorRing() + 1;
  shellPart[currentPart] = true;
  currentPart++;
  currentPoint += polygon.getExteriorRing().getNumPoints();
  int holesCount = polygon.getNumInteriorRing();
  for (int holeIndex = 0; holeIndex < holesCount; holeIndex++) {
    partIndexes[currentPart] = currentPoint;
    shellPart[currentPart] = false;
    currentPart++;
    currentPoint += polygon.getInteriorRingN(holeIndex).getNumPoints();

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

public void testPolygon3D() throws Exception {
  GML3MockData.polygon3D(document, document, true);
  Polygon polygon = (Polygon) parse();
  assertNotNull(polygon);
  LineString exterior = polygon.getExteriorRing();
  assertTrue(new Coordinate(1d, 2d, 10d).equals3D(exterior.getCoordinateN(0)));
  LineString interior = polygon.getInteriorRingN(0);
  assertTrue(new Coordinate(1d, 2d, 10d).equals3D(interior.getCoordinateN(0)));
}

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

private static Geometry smoothLineString(
    GeometryFactory factory, GeometrySmoother smoother, Geometry geom, double fit) {
  if (geom instanceof LinearRing) {
    // Treat as a Polygon
    Polygon poly = factory.createPolygon((LinearRing) geom, null);
    Polygon smoothed = smoother.smooth(poly, fit);
    return smoothed.getExteriorRing();
  } else {
    return smoother.smooth((LineString) geom, fit);
  }
}

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

polygon.apply(
    new CoordinateSequenceFilter() {
  for (int i = 0; i < result.size(); i++) {
    Polygon item = result.get(i);
    if (item.getNumInteriorRing() > 0) {
      GeometryFactory factory = item.getFactory();
      Polygon noHoles =
          factory.createPolygon((LinearRing) item.getExteriorRing(), null);
      result.set(i, noHoles);

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

if (polygon.getExteriorRing() != null) {
  buffer.append("MDSYS.SDO_GEOMETRY(");
  buffer.append(SDO.D(polygon));
  buffer.append("MDSYS.SDO_ORDINATE_ARRAY(");
  CoordinateSequenceFactory fact = polygon.getFactory().getCoordinateSequenceFactory();
  CoordinateSequence exterior = polygon.getExteriorRing().getCoordinateSequence();
  CoordinateSequence coordSeq = SDO.counterClockWise(fact, exterior);
if (polygon.getNumInteriorRing() > 0) {
  LOGGER.warning(
      "Polygon contains Interior Rings. "

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

public static Geometry interiorRingN(Geometry arg0, Integer arg1) {
  if (!(arg0 instanceof Polygon) || arg1 == null) return null;
  Polygon _this = (Polygon) arg0;
  if (arg1 < 0 || arg1 >= _this.getNumInteriorRing()) return null;
  return _this.getInteriorRingN(arg1);
}

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

public static int numInteriorRing(Geometry arg0) {
  if (!(arg0 instanceof Polygon)) return 0;
  Polygon _this = (Polygon) arg0;
  return _this.getNumInteriorRing();
}

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

/**
 * Finds a centroid for a polygon catching any exceptions resulting from generalization or other
 * polygon irregularities.
 *
 * @param geom The polygon.
 * @return The polygon centroid, or null if it can't be found.
 */
public static Point getPolygonCentroid(Polygon geom) {
  Point centroid;
  try {
    centroid = geom.getCentroid();
  } catch (Exception e) {
    // generalized polygons causes problems - this
    // tries to hide them.
    try {
      centroid = geom.getExteriorRing().getCentroid();
    } catch (Exception ee) {
      try {
        centroid = geom.getFactory().createPoint(geom.getCoordinate());
      } catch (Exception eee) {
        return null; // we're hooped
      }
    }
  }
  return centroid;
}

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

/**
   * Create a new polygon without hole.
   *
   * @param polygon
   * @return
   */
  public static Polygon removeHolesPolygon(Polygon polygon) {
    return new Polygon((LinearRing) polygon.getExteriorRing(), null, polygon.getFactory());
  }
}

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

public LineString getInteriorRingN(int n) {
  return polygon.getInteriorRingN(n);
}

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

public void setUserData(Object userData) {
  polygon.setUserData(userData);
}

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

/**
   * Returns the completed OGC Polygon.
   *
   * @param geometryFactory Geometry factory to be used in Polygon creation.
   * @return Completed OGC Polygon.
   */
  public Geometry create(GeometryFactory geometryFactory) {
    for (int i = 0; i < innerBoundaries.size(); i++) {
      LinearRing hole = (LinearRing) innerBoundaries.get(i);
      if (hole.crosses(outerBoundary)) {
        LOGGER.warning("Topology Error building polygon");

        return null;
      }
    }

    LinearRing[] rings =
        (LinearRing[]) innerBoundaries.toArray(new LinearRing[innerBoundaries.size()]);
    Polygon polygon = geometryFactory.createPolygon(outerBoundary, rings);
    polygon.setUserData(getSRS());
    polygon.setSRID(getSRID());
    return polygon;
  }
}

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

poly.geometryChanged(); // djb -- jessie should do this during
if (displayGeomEnv.contains(poly.getEnvelopeInternal())) {
  return poly.getFactory().createMultiPolygon(polys);
  Polygon[] polys = new Polygon[1];
  polys[0] = (Polygon) clip;
  return poly.getFactory().createMultiPolygon(polys);
return poly.getFactory().createMultiPolygon(polys.toArray(new Polygon[1]));

相关文章