Opened 13 years ago

Closed 13 years ago

#3831 closed defect (invalid)

OGRFeature->GetGeometryRef() returns NULL in GDAL 1.71 Windows/SunOS

Reported by: X453252 Owned by: warmerdam
Priority: normal Milestone:
Component: OGR_SF Version: 1.7.1
Severity: normal Keywords: OGR, OGRGeometry
Cc:

Description

The OGRFeature->GetGeometryRef() is returning NULL in GDAL 1.71 Windows/SunOS.

I am using the example from tutorial from below link:

http://www.gdal.org/ogr/ogr_apitut.html

        OGRGeometry *poGeometry;

        poGeometry = poFeature->GetGeometryRef();
        if( poGeometry != NULL 
            && wkbFlatten(poGeometry->getGeometryType()) == wkbPoint )
        {
            OGRPoint *poPoint = (OGRPoint *) poGeometry;

            printf( "%.3f,%3.f\n", poPoint->getX(), poPoint->getY() );
        }
        else
        {
            printf( "no point geometry\n" );
        } 

Attachments (4)

TestPolygon.shp (1.6 KB ) - added by X453252 13 years ago.
Test Polygon shapefile
TestPolygon.dbf (2.3 KB ) - added by X453252 13 years ago.
Test Polygon dbf file
TestPolygon.shx (108 bytes ) - added by X453252 13 years ago.
Test Polygon shx file
OgrHelper.cpp (2.0 KB ) - added by X453252 13 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 by X453252, 13 years ago

Component: defaultOGR_SF

comment:2 by warmerdam, 13 years ago

Priority: highnormal

Manish,

What file are you reading? OGR does support reading files with features that have no geometry in which case the return result of poFeature->GetGeometryRef() would be NULL.

comment:3 by X453252, 13 years ago

Pordon my ignorance here. I am using shape file and I do have all three files (.shp, .dbf and .shx)

Would you like to have them attached?

comment:4 by warmerdam, 13 years ago

Yes, please, and a self contained code sequence that compiles and demonstrates the problem.

I will note it is possible to have "null" shapes in a shapefile which will come through with a NULL geometry. But this is uncommon, so I would be willing to check your file if you think this should not be the case.

by X453252, 13 years ago

Attachment: TestPolygon.shp added

Test Polygon shapefile

by X453252, 13 years ago

Attachment: TestPolygon.dbf added

Test Polygon dbf file

by X453252, 13 years ago

Attachment: TestPolygon.shx added

Test Polygon shx file

comment:5 by X453252, 13 years ago

Meanwhile I tried ogrinfo -al c:\testpolygon.shp and that seems to be loading all the details fine.

by X453252, 13 years ago

Attachment: OgrHelper.cpp added

comment:6 by X453252, 13 years ago

Resolution: invalid
Status: newclosed

Seems to some problem with my original compile. The issue has been resolved.

Also, I had to change my if condition from,

if( poGeometry != NULL 
            && wkbFlatten(poGeometry->getGeometryType()) == wkbPoint )
        {
....

To:

OGRwkbGeometryType geoType = wkbFlatten(poGeometry->getGeometryType());

if( geoType == wkbPolygon)
{

}else  if( geoType == wkbMultiPolygon)
{
	OGRMultiPolygon *poPoly = (OGRMultiPolygon*)poGeometry;
	cout<<"\nA Multi Polygon Geometry found!!\n";

}else  if( geoType == wkbPoint)
{
}
Note: See TracTickets for help on using tickets.