New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

Comments

Projects
None yet
1 participant
@szekerest
Member

szekerest commented Feb 19, 2013

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.

@ghost ghost assigned szekerest Feb 19, 2013

@szekerest

This comment has been minimized.

Show comment
Hide comment
@szekerest

szekerest Feb 19, 2013

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;
}
Member

szekerest commented Feb 19, 2013

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

This comment has been minimized.

Show comment
Hide comment
@szekerest

szekerest Feb 19, 2013

Member

Related to #3811

Member

szekerest commented Feb 19, 2013

Related to #3811

@szekerest szekerest closed this Feb 21, 2013

szekerest added a commit to szekerest/mapserver that referenced this issue Mar 28, 2013

mkofahl pushed a commit to faegi/mapserver that referenced this issue Apr 9, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment