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)
Change History (10)
comment:1 by , 13 years ago
Component: | default → OGR_SF |
---|
comment:2 by , 13 years ago
Priority: | high → normal |
---|
comment:3 by , 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 , 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.
comment:5 by , 13 years ago
Meanwhile I tried ogrinfo -al c:\testpolygon.shp and that seems to be loading all the details fine.
by , 13 years ago
Attachment: | OgrHelper.cpp added |
---|
comment:6 by , 13 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
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) { }
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.