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

Function ogrGeomLine

mapogr.cpp:271–373  ·  view source on GitHub ↗

* ogrGeomLine() * * Recursively convert any OGRGeometry into a shapeObj. Each part becomes * a line in the overall shapeObj. **********************************************************************/

Source from the content-addressed store, hash-verified

269 * a line in the overall shapeObj.
270 **********************************************************************/
271static int ogrGeomLine(OGRGeometryH hGeom, shapeObj *outshp,
272 int bCloseRings)
273{
274 if (hGeom == NULL)
275 return 0;
276
277/* ------------------------------------------------------------------
278 * Use recursive calls for complex geometries
279 * ------------------------------------------------------------------ */
280 OGRwkbGeometryType eGType = wkbFlatten( OGR_G_GetGeometryType( hGeom ) );
281
282
283 if ( eGType == wkbPolygon
284 || eGType == wkbGeometryCollection
285 || eGType == wkbMultiLineString
286 || eGType == wkbMultiPolygon )
287 {
288 if (eGType == wkbPolygon && outshp->type == MS_SHAPE_NULL)
289 outshp->type = MS_SHAPE_POLYGON;
290
291 /* Treat it as GeometryCollection */
292 for (int iGeom=0; iGeom < OGR_G_GetGeometryCount( hGeom ); iGeom++ )
293 {
294 if( ogrGeomLine( OGR_G_GetGeometryRef( hGeom, iGeom ),
295 outshp, bCloseRings ) == -1 )
296 return -1;
297 }
298 }
299/* ------------------------------------------------------------------
300 * OGRPoint and OGRMultiPoint
301 * ------------------------------------------------------------------ */
302 else if ( eGType == wkbPoint || eGType == wkbMultiPoint )
303 {
304 /* Hummmm a point when we're drawing lines/polygons... just drop it! */
305 }
306/* ------------------------------------------------------------------
307 * OGRLinearRing/OGRLineString ... both are of type wkbLineString
308 * ------------------------------------------------------------------ */
309 else if ( eGType == wkbLineString )
310 {
311 int j, numpoints;
312 lineObj line={0,NULL};
313 double dX, dY;
314
315 if ((numpoints = OGR_G_GetPointCount( hGeom )) < 2)
316 return 0;
317
318 if (outshp->type == MS_SHAPE_NULL)
319 outshp->type = MS_SHAPE_LINE;
320
321 line.numpoints = 0;
322 line.point = (pointObj *)malloc(sizeof(pointObj)*(numpoints+1));
323 if(!line.point)
324 {
325 msSetError(MS_MEMERR, "Unable to allocate temporary point cache.",
326 "ogrGeomLine");
327 return(-1);
328 }

Callers 1

ogrConvertGeometryFunction · 0.85

Calls 2

msSetErrorFunction · 0.85
msAddLineDirectlyFunction · 0.85

Tested by

no test coverage detected