Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#1891 closed defect (fixed)

ms_shapeObjFromWkt doesn't work with MULTILINESTRING and MULTIPOLYGON

Reported by: maikstoeckmann@… Owned by: dmorissette
Priority: high Milestone: 4.10 release
Component: MapScript-PHP Version: 4.8
Severity: normal Keywords:
Cc:

Description

The PHP mapscript function ms_shapeObjFromWkt doesn't work with MULTILINESTRING 
and MULTIPOLYGON. For these geometry types the function generally returns 
nothing. No error message is produced.

Change History (13)

comment:1 by dmorissette, 18 years ago

Cc: steve.lime@… warmerdam@… added
MapServer doesn't do the parsing of WKT, it relies on methods from GEOS (if
available) or from OGR (if GEOS not available) to do the conversion from WKT.

We'd need to know the version of GEOS (if you have it) and OGR that you are using.


comment:2 by maikstoeckmann@…, 18 years ago

I compiled mapserver with OGR option only. My DGAL/OGR-Version was 2.0.33-1.1. 
I have tried to install GEOS 2.2.3, but then I get an Internal Server Error 
message, when using the ms_shapeObjFromWkt function.

comment:3 by sdlime, 18 years ago

Can you share the WKT strings? GEOS support was re-written in 4.10 and should 
be much more robust. I'll take a look against 4.8 though but need your test 
case.

Steve

comment:4 by maikstoeckmann@…, 18 years ago

Sorry, my version info wasn't correct. So again. I'm using:
MapServer/MapScript 4.8.4,
GDAL/OGR 1.3.2,
I compiled MapServer completely without GEOS, but with GDAL/OGR 1.3.2. The 
mapscript function ms_shapeObjFromWkt works very well, except for multipart 
geometries.
Should I have to use GEOS? What version?

comment:5 by dmorissette, 18 years ago

Short answer: it seems that the OGR implementation doesn't support
multilinestring and multipolygon. Hopefully the GEOS implementation does but I
didn't check.

Long answer:

After a quick check in mapogr.cpp, it seems that msOGRGeometryToShape() only
supports wkbPoint, wkbLineString and wkbPolygon. However, it seems that the
underlying ogrGeomLine() function should be able to handle wkbMultiLineString
and wkbMultiPolygon as well.

Question for Frank: did you intentionally omit wkbMultiLineString and
wkbMultiPolygon in msOGRGeometryToShape() because of a know limitation of the
underlying OGR_G_CreateFromWkt() or some other reason?

comment:6 by sdlime, 18 years ago

The GEOS version does implement multipart features... I've tested with simple 
multipart polygons but not multi linestrings. However, multiline strings are 
*much* easier since you don't have to deal with inner/outer rings.

Steve

comment:7 by maikstoeckmann@…, 18 years ago

I modified the function in maporg.cpp for my own, re-compiled mapscript and now 
it works fine!

int msOGRGeometryToShape(OGRGeometryH hGeometry, shapeObj *psShape,
                         OGRwkbGeometryType nType)
{
    if (hGeometry && psShape && nType > 0)
    {
        if (nType == wkbPoint)
          return ogrConvertGeometry((OGRGeometry *)hGeometry,
                                    psShape,  MS_LAYER_POINT);
        else if (nType == wkbLineString || nType == wkbMultiLineString )
          return ogrConvertGeometry((OGRGeometry *)hGeometry,
                                    psShape,  MS_LAYER_LINE);
        else if (nType == wkbPolygon || nType == wkbMultiPolygon)
          return ogrConvertGeometry((OGRGeometry *)hGeometry,
                                    psShape,  MS_LAYER_POLYGON);
        else
            return MS_FAILURE;
    }
    else
        return MS_FAILURE;
}

comment:8 by dmorissette, 18 years ago

Frank, can you please confirm that it would be safe to apply Maik's change to
msOGRGeometryToShape() in 4.10?
(That fix seems fine to me as long as there is no known limitation in OGR's
OGR_G_CreateFromWkt() that I'm not aware of.)

comment:9 by fwarmerdam, 18 years ago

The proposed changes look fine to me. 

comment:10 by dmorissette, 18 years ago

Milestone: 4.10 release
Owner: changed from mapserverbugs to dmorissette
Sounds good. Applying this fix in 4.10 CVS now.

comment:11 by dmorissette, 18 years ago

Cc: assefa@… added
Resolution: fixed
Status: newclosed
Applied Maik's fix in CVS HEAD. Will be in 4.10.0-beta3.


P.S. I just saw in CVS logs that msOGRGeometryToShape() was created by Assefa,
not Frank. Sorry for bugging you about this one Frank, I thought it had been
created by you.

comment:12 by fwarmerdam, 18 years ago

I have also added MULTIPOINT support, and added tests for these three
multi geometries in msautotest/misc/ogr_wkt.map. 


comment:13 by fwarmerdam, 18 years ago

This bug is also somewhat related to Bug 1618 which relates to going the other
way.
Note: See TracTickets for help on using tickets.