| 210 | } |
| 211 | |
| 212 | static GEOSGeom msGEOSShape2Geometry_polygon(shapeObj *shape) |
| 213 | { |
| 214 | int i, j; |
| 215 | GEOSGeom *polygons; |
| 216 | int *outerList, numOuterRings=0, lastOuterRing=0; |
| 217 | GEOSGeom g; |
| 218 | |
| 219 | outerList = msGetOuterList(shape); |
| 220 | for(i=0; i<shape->numlines; i++) { |
| 221 | if(outerList[i] == MS_TRUE) { |
| 222 | numOuterRings++; |
| 223 | lastOuterRing = i; /* save for the simple case */ |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | if(numOuterRings == 1) { |
| 228 | g = msGEOSShape2Geometry_simplepolygon(shape, lastOuterRing, outerList); |
| 229 | } else { /* a true multipolygon */ |
| 230 | polygons = malloc(numOuterRings*sizeof(GEOSGeom)); |
| 231 | if(!polygons) return NULL; |
| 232 | |
| 233 | j = 0; /* part counter */ |
| 234 | for(i=0; i<shape->numlines; i++) { |
| 235 | if(outerList[i] == MS_FALSE) continue; |
| 236 | polygons[j] = msGEOSShape2Geometry_simplepolygon(shape, i, outerList); /* TODO: account for NULL return values */ |
| 237 | j++; |
| 238 | } |
| 239 | |
| 240 | g = GEOSGeom_createCollection(GEOS_MULTIPOLYGON, polygons, numOuterRings); |
| 241 | } |
| 242 | |
| 243 | free(outerList); |
| 244 | return g; |
| 245 | } |
| 246 | |
| 247 | GEOSGeom msGEOSShape2Geometry(shapeObj *shape) |
| 248 | { |
no test coverage detected