要遍历多边形的点,您必须LinearRing
通过调用GEOSGetExteriorRing
来获取,如下所示。
此示例适用于MultiPolygon
s 或Polygon
s。此示例打印构成多面体的 LinearRings 中点的所有 x,y 坐标。如果 inputGeom 是多边形,它也可以工作。
GEOSGeometry *inputGeom = GEOSGeomFromWKT("MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)), ((15 5, 40 10, 10 20, 5 10, 15 5)))");
const GEOSGeometry *linearRing;
const GEOSCoordSequence *coordSeq;
int numGeom = GEOSGetNumGeometries(inputGeom);
int n;
for (n=0; n < numGeom; n++) {
linearRing = GEOSGetExteriorRing(GEOSGetGeometryN(inputGeom, n));
printf("%s\n", GEOSGeomToWKT(linearRing));
unsigned int numPoints, p;
numPoints = GEOSGeomGetNumPoints(linearRing);
for (p=0; p < numPoints; p++) {
double xCoord, yCoord;
coordSeq = GEOSGeom_getCoordSeq(linearRing);
GEOSCoordSeq_getX(coordSeq, p, &xCoord);
GEOSCoordSeq_getY(coordSeq, p, &yCoord);
printf("%f, %f\n", xCoord, yCoord);
}
}
就我的目的而言,多边形中从来没有孔,所以这就是我所需要的。