[gdal-dev] GDAL, ESRI Shapefiles and nested polygons
Graeme Wilkie
graeme.wilkie at btinternet.com
Thu Aug 7 13:20:34 PDT 2014
Hi,
I'm trying to use GDAL to read ESRI shapefiles. I've got it working for
points, lines, polygons, polylines and multipoint but I'm having problems
with polygons that contain polygons in the same feature.
The following is a cut down code sample of the code I'm using. The problem I
have is that I can read the number of polygons in the feature (i.e. 3
polygons, nested) using OGR_G_GetGemoetryCount. When I use
OGR_R_GetGeometryRef to get the handle/pointer for each of the polygons in
turn I get what appears to be a valid handle but when I use it to get the
number of points/vertices in the polygon it always returns 0.
If I use the lower level routines SHPOpen, SHPReadObject, SHPClose I can get
access to the data (after a fashion) but the requirement is to use the
higher level API.
I'm using GDAL-1.6.2 (yes I know I should be using a much more up-to-date
version but the project will not sanction it). I'm developing on a Linux
(Redhat 5.9) system in GCC.
I'd appreciate it if you could point out what I'm doing wrong (I suspect it
is my error).
OGRDataSourceH hDS;
OGRFeatureH hFeature;
OGRLayerH;
OGRRegisterAll();
hDS = OGROpen(filename, FALSE, NULL);
hLayer = OGR_DS_GetLayer(hDS, 0); // only interested in layer 0
while ((hFeature = OGR_L_GetNextFeature(hLayer)) != NULL)
(
Int index = 0;
OGRGeometryH hGeometry = OGR_F_GetGeometryRef(hFeature);
int shape_type = wkbFlatten(ORG_G_GetGeometry(hGeometry);
int num_geom = OGR_G_GetGeometryCount(hGeometry) - 1; // Returns a valid
result
do
{
OGRGeometryH hRing = OGR_G_GetGeometryRef(hGeometry, index);
Int num_vertices = OGR_G_GetPointCount(hRing); // returns 0
//.
//. Do something with the data
//.
Index++;
}
// Destroy the hfeature here
)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20140807/65e56749/attachment.html>
More information about the gdal-dev
mailing list