* ogrGeomLine() * * Recursively convert any OGRGeometry into a shapeObj. Each part becomes * a line in the overall shapeObj. **********************************************************************/
| 269 | * a line in the overall shapeObj. |
| 270 | **********************************************************************/ |
| 271 | static 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 | } |
no test coverage detected