MCPcopy Create free account
hub / github.com/MapServer/MapServer / msGEOSGeometry2Shape_multipolygon

Function msGEOSGeometry2Shape_multipolygon

mapgeos.c:480–541  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

478}
479
480static shapeObj *msGEOSGeometry2Shape_multipolygon(GEOSGeom g)
481{
482 int i, j, k;
483 shapeObj *shape=NULL;
484 lineObj line;
485 int numPoints, numRings, numPolygons;
486
487 GEOSCoordSeq coords;
488 GEOSGeom polygon, ring;
489
490 if(!g) return NULL;
491 numPolygons = GEOSGetNumGeometries(g);
492
493 shape = (shapeObj *) malloc(sizeof(shapeObj));
494 msInitShape(shape);
495 shape->type = MS_SHAPE_POLYGON;
496 shape->geometry = (GEOSGeom) g;
497
498 for(k=0; k<numPolygons; k++) { /* for each polygon */
499 polygon = (GEOSGeom) GEOSGetGeometryN(g, k);
500
501 /* exterior ring */
502 ring = (GEOSGeom) GEOSGetExteriorRing(polygon);
503 numPoints = GEOSGetNumCoordinates(ring);
504 coords = (GEOSCoordSeq) GEOSGeom_getCoordSeq(ring);
505
506 line.point = (pointObj *) malloc(sizeof(pointObj)*numPoints);
507 line.numpoints = numPoints;
508
509 for(i=0; i<numPoints; i++) {
510 GEOSCoordSeq_getX(coords, i, &(line.point[i].x));
511 GEOSCoordSeq_getY(coords, i, &(line.point[i].y));
512 /* GEOSCoordSeq_getZ(coords, i, &(line.point[i].z)); */
513 }
514 msAddLineDirectly(shape, &line);
515
516 /* interior rings */
517 numRings = GEOSGetNumInteriorRings(polygon);
518
519 for(j=0; j<numRings; j++) {
520 ring = (GEOSGeom) GEOSGetInteriorRingN(polygon, j);
521 if(GEOSisRing(ring) != 1) continue; /* skip it */
522
523 numPoints = GEOSGetNumCoordinates(ring);
524 coords = (GEOSCoordSeq) GEOSGeom_getCoordSeq(ring);
525
526 line.point = (pointObj *) malloc(sizeof(pointObj)*numPoints);
527 line.numpoints = numPoints;
528
529 for(i=0; i<numPoints; i++) {
530 GEOSCoordSeq_getX(coords, i, &(line.point[i].x));
531 GEOSCoordSeq_getY(coords, i, &(line.point[i].y));
532 /* GEOSCoordSeq_getZ(coords, i, &(line.point[i].z)); */
533 }
534 msAddLineDirectly(shape, &line);
535 }
536 } /* next polygon */
537

Callers 1

msGEOSGeometry2ShapeFunction · 0.85

Calls 3

msInitShapeFunction · 0.85
msAddLineDirectlyFunction · 0.85
msComputeBoundsFunction · 0.85

Tested by

no test coverage detected