本文整理了Java中org.locationtech.jts.geom.Polygon
类的一些代码示例,展示了Polygon
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Polygon
类的具体详情如下:
包路径:org.locationtech.jts.geom.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:
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]));
内容来源于网络,如有侵权,请联系作者删除!