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

Function msGEOSShape2Geometry_simplepolygon

mapgeos.c:154–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

152}
153
154static GEOSGeom msGEOSShape2Geometry_simplepolygon(shapeObj *shape, int r, int *outerList)
155{
156 int i, j, k;
157 GEOSCoordSeq coords;
158 GEOSGeom g;
159 GEOSGeom outerRing;
160 GEOSGeom *innerRings=NULL;
161 int numInnerRings=0, *innerList;
162
163 if(!shape || !outerList) return NULL;
164
165 /* build the outer shell */
166 coords = GEOSCoordSeq_create(shape->line[r].numpoints, 2); /* todo handle z's */
167 if(!coords) return NULL;
168
169 for(i=0; i<shape->line[r].numpoints; i++) {
170 GEOSCoordSeq_setX(coords, i, shape->line[r].point[i].x);
171 GEOSCoordSeq_setY(coords, i, shape->line[r].point[i].y);
172 /* GEOSCoordSeq_setZ(coords, i, shape->line[r].point[i].z); */
173 }
174
175 outerRing = GEOSGeom_createLinearRing(coords); /* outerRing owns the coordinates in coords */
176
177 /* build the holes */
178 innerList = msGetInnerList(shape, r, outerList);
179 for(j=0; j<shape->numlines; j++)
180 if(innerList[j] == MS_TRUE) numInnerRings++;
181
182 if(numInnerRings > 0) {
183 k = 0; /* inner ring counter */
184
185 innerRings = malloc(numInnerRings*sizeof(GEOSGeom));
186 if(!innerRings) return NULL; /* todo, this will leak memory (outerRing) */
187
188 for(j=0; j<shape->numlines; j++) {
189 if(innerList[j] == MS_FALSE) continue;
190
191 coords = GEOSCoordSeq_create(shape->line[j].numpoints, 2); /* todo handle z's */
192 if(!coords) return NULL; /* todo, this will leak memory (shell + allocated holes) */
193
194 for(i=0; i<shape->line[j].numpoints; i++) {
195 GEOSCoordSeq_setX(coords, i, shape->line[j].point[i].x);
196 GEOSCoordSeq_setY(coords, i, shape->line[j].point[i].y);
197 /* GEOSCoordSeq_setZ(coords, i, shape->line[j].point[i].z); */
198 }
199
200 innerRings[k] = GEOSGeom_createLinearRing(coords); /* innerRings[k] owns the coordinates in coords */
201 k++;
202 }
203 }
204
205 g = GEOSGeom_createPolygon(outerRing, innerRings, numInnerRings);
206
207 free(innerList); /* clean up */
208
209 return g;
210}
211

Callers 1

Calls 1

msGetInnerListFunction · 0.85

Tested by

no test coverage detected