This project has moved and is read-only. For the latest updates, please go here.

MultiPolygon Geometry

Sep 29, 2009 at 4:19 PM


I am trying to read in a MultiPolygon Gemoerty from a shape file then plot the shape into Virtual Earth.

Its almost wokring however, I need to logically seperate each individual object / shape that is contained within the MultiPolygon Geometry.

I hope this makes sense.  Can anyone help with pointers to the correct properties / methods?



Sep 29, 2009 at 4:33 PM
Edited Sep 29, 2009 at 4:38 PM

Hi Dan, assuming v2 there are several ways:


Inherits GeometryCollection which as a Geometries property ( IList<IGeometry<TCoordinate>>) .

Has an indexer so: childPolygon = multipolygonInstance[i] (where  0 =< i < multipolygonInstance.Count)

implements IEnumerable<IPolygon<TCoordinate>> so can take part in foreach


Multipolygon in 0.9/trunk

has an indexer

and has instance.GeometryN(n) where  0=< n < instance.NumGeometries

and is IEnumerable<IGeometry>

hth jd

Sep 29, 2009 at 11:14 PM

Thanks John,

Not sure if I am using the API in the correct way or if there is problem with the shape file.  When I run the following code:

If featureDataReader.Geometry.GeometryType = OgcGeometryType.MultiPolygon Then

            Dim multiPolygonGeomerty As IMultiPolygon = featureDataReader.Geometry

            For PolygonCount As Integer = 0 To (multiPolygonGeomerty.Count - 1)
                Dim shapeGeometry As IGeometry = multiPolygonGeomerty(PolygonCount)
                'DO SOME MORE WORK HERE
End If

The problem is that multiPolygonGeomerty.Count always returns 1.  I was expecting it to return a count of more than one.  One for each polygon in the shape.  However it always returns one Polygon which contains all the coordinates for the entire shape (even if the shape is made up of more than one polygon). 

When I open the shapefile in a GIS application you can clearly see one shape made up of many polygons (lots of small polygons inside one large polygon). 

Any ideas?



Sep 29, 2009 at 11:20 PM

Hi Dan,

what you have is a polygon declared as a mulipolygon. polygons may have holes.

for sharpmap 0.9 you can access these via the polygons InteriorRings property.



Sep 29, 2009 at 11:40 PM

Hi Fobermaier,,,,

Ah now that makes alot of sense....

Thanks.  I am currenlty on version 2.0.

Is it the same property / collection?



Sep 30, 2009 at 7:45 AM

Hi Dan,

you may have already noticed. The property has the same name but it is defined as

IEnumerable<ILineString<TCoordinate>> InteriorRings { get; }