[Gdal-dev] Possible bug in getGeometryType() version 1.3.0

Chapman, Martin MChapman at sanz.com
Mon Oct 10 18:17:04 EDT 2005


Sean,

Ok, I think I figured out the bug.  The basic problem I think is that the shape reader function SHPReadOGRObject () in shape2ogr.cpp creates the OGRPoint object with x, y, z and in turn the OGRPoint class has an original dimension of 3.  Then he (Frank) calls the function setCoordinateDimension(2) if the shape type is SHPT_POINT.  The problem being that the function setCoordinateDimension is a virtual function defined and implemented in ogrgeometry.h/.cpp.  OGRLineString and OGRPolygon override this virtual function and call Make2D() when the coord dimension is reduced to 2.  OGRPoint does not override this function.  The result is that the base class function setCoordinateDimension() in ogrgeometry gets called for points, and the Make2D() function is never called.  The solution is to implement the virtual function setCoordinateDimension() in the OGRPoint class and call Make2D() when dimension == 2.  

In the meantime, a fairly harmless workaround is to call pOgrGeometry->flattenTo2D() when pOgrGeometry->getGeometryType() returns less than zero if you aren't interested in using 3D data.  flattenTo2D() apparently just sets z = 0 and changes the dimension to 2.  So it shouldn't be that cpu expensive.

Martin

-----Original Message-----
From: Sean Gillies [mailto:sgillies at frii.com] 
Sent: Monday, October 10, 2005 3:03 PM
To: Chapman, Martin
Cc: gdal-dev at lists.maptools.org
Subject: Re: [Gdal-dev] Possible bug in getGeometryType() version 1.3.0

On Oct 10, 2005, at 2:48 PM, Chapman, Martin wrote:

> Frank,
>  
> When I call pOgrGeometry->getGeometryType(); in version 1.3.0 it 
> returns the wrong value (basically an unsigned int value) for esri 
> shape files that contain point geometry.  Polygons and LineStrings 
> work as expected.  Can you confirm that this is a bug?  This is on 
> Windows XP, haven't tried it on Linux yet, but I will shortly.
>  
> Best regards,
> Martin

Martin,

I ran into something like this last night on Linux. The data were 
points digitized using QGis 0.7. Ogrinfo reported this shapefile as 
containing 3D points, and getGeometryType returned an invalid value. I 
used ogr2ogr with -nlt POINT to coerce these into "normal" points with 
GeometryType 1.

Sean

--
Sean Gillies
sgillies at frii dot com
http://zcologia.com




More information about the Gdal-dev mailing list