I'm trying to unpack shapefiles in C# using GDAL-OGR library, but I'm confused about the structure of multipolygon with holes in OGR. As far as I know, the models of shapefiles and OGR geometry (the latter following simple feature specifications) are different. Shapefiles have a "polygon" type that might be in OGR term either a polygon or a multipolygon. So I must handle both cases. When reading a shapefile, OGR does some topological analysis to figure out the spatial relationship between rings and determine if they must be outer or inner rings.
An OGR polygon is a collection of rings, the first one being the outer ring and the following ones the inner rings. So, this code will work fine.
Feature feat;
while ((feat = layer.GetNextFeature()) != null)
{
var geom = feat.GetGeometryRef();
for (var i = 0; i < geom.GetGeometryCount(); i++)
{
//First one is the outer ring and, all the next ones are the inner rings
var ring = geom.GetGeometryRef(i);
...
}
}
But, if the geometry is multipolygon, e.g 2 polygons with holes. How do you determine which one is the outer ring of the second polygon? Because if I understand it correctly, geom.GetGeometryRef()
will only return the first polygon. Shouldn't Feature
have something like feat.GetGeometryCount()
(to determine the number of polygons - the outer rings only) and feat.GetGeometryRef(i)
(to get the i outer ring of i polygon) or something? I checked, and there is none. How do you handle such case? Can anyone help me with it, please?
Also, how many nested levels that OGR support for polygons (i.e, holes inside holes)? How do handle such cases?
Sorry for my English! I'm not a native speaker.