Geometry operations may cause 'Unsupported GEOS geometry type' error #4591

Closed
szekerest opened this Issue Feb 19, 2013 · 2 comments

Projects

None yet

1 participant

@szekerest
Member

Certain geometry operations (like Intersection) may cause 'Unsupported GEOS geometry type' error. This is because GEOS may return geometry collections in some cases which is not supported when converting to shapeObj.

@szekerest szekerest was assigned Feb 19, 2013
@szekerest
Member

To provide a workaround we can collect the lines from the sub-geometries into a single shape as follows:

shapeObj *msGEOSGeometry2Shape(GEOSGeom g)
{
  int type;

   if(!g)
    return NULL; /* a NULL geometry generates a NULL shape */

   type = GEOSGeomTypeId(g);
   switch(type) {
   case GEOS_POINT:
     return msGEOSGeometry2Shape_point(g);
     break;
   case GEOS_MULTIPOINT:
     return msGEOSGeometry2Shape_multipoint(g);
     break;
   case GEOS_LINESTRING:
     return msGEOSGeometry2Shape_line(g);
    break;
   case GEOS_MULTILINESTRING:
     return msGEOSGeometry2Shape_multiline(g);
     break;
   case GEOS_POLYGON:
     return msGEOSGeometry2Shape_polygon(g);
     break;
   case GEOS_MULTIPOLYGON:
     return msGEOSGeometry2Shape_multipolygon(g);
     break;
   case GEOS_GEOMETRYCOLLECTION:
     if (!GEOSisEmpty(g))
     {
       int i, j, numGeoms;
       shapeObj* shape;

       numGeoms = GEOSGetNumGeometries(g);

       shape = (shapeObj *) malloc(sizeof(shapeObj));
       msInitShape(shape);
       shape->type = MS_SHAPE_LINE;
       shape->geometry = (GEOSGeom) g;

       numGeoms = GEOSGetNumGeometries(g);
       for(i = 0; i < numGeoms; i++) { /* for each geometry */
          shapeObj* shape2 = msGEOSGeometry2Shape((GEOSGeom)GEOSGetGeometryN(g, i));
          if (shape2) {
             for (j = 0; j < shape2->numlines; j++)
                msAddLineDirectly(shape, &shape2->line[j]);
             shape2->numlines = 0;
             shape2->geometry = NULL; /* not owned */
             msFreeShape(shape2);
          }
       }
       msComputeBounds(shape);
       return shape;
     }
    break;
   default:
   msSetError(MS_GEOSERR, "Unsupported GEOS geometry type (%d).", "msGEOSGeometry2Shape()", type);
 }
 return NULL;
}
@szekerest
Member

Related to #3811

@szekerest szekerest closed this Feb 21, 2013
@szekerest szekerest added a commit to szekerest/mapserver that referenced this issue Mar 28, 2013
@szekerest szekerest Fix geometry collection support (#4591) 0fb5fdd
@mkofahl mkofahl pushed a commit to faegi/mapserver that referenced this issue Apr 9, 2013
@szekerest szekerest Fix for the unsupported geometry type problem (#4591) ca27fd7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment