Navigating from Feature to Geometry or via verca.

Sep 22, 2009 at 5:21 PM


Newb here so please excuse if this is a stupid question.

Was wondering if it is possible to navigate from a Feature to a Geomety or via verca?

E.g. if I had a feature how would I retrieve its associated Geometry(s)? 

I can do it by using the Extent of the Geomerty to find the associated Feature but this seems over the top to me.

Any help with this would be much appreciated.

Thank you,


Sep 22, 2009 at 5:37 PM

Hi dan, FeatureDataRow has a Geometry property so you can navigate from feature -> geometry but the reverse is not true you cannot get the attributes from a geometry hth jd

Sep 23, 2009 at 10:13 AM

Hi John,

Yes I spotted that property but when I try to access it (and its not just this property) the debugger reveals that the following exception occurs "The method or operation is not implemented."

Here is a code snippet illustrating when the error occurs:

 BoundingBox shapeFileExtent = sf.GetExtents();
Geometry shapeFileGeometry = shapeFileExtent.ToGeometry();

FeatureSpatialExpression fse = new FeatureSpatialExpression(shapeFileGeometry, SpatialExpressionType.Within, null);

sf.ExecuteFeatureQuery(fse, ds);

FeatureDataTableReader featureDataTableReader = new FeatureDataTableReader(ds.Tables[0]);

while (!featureDataTableReader.Read())
       Geometry featureGeometry = featureDataTableReader.Geometry;   

The exception occurs when the Read() method is called.  The version number of the SharpMap.dll is  The NPack.dll is 0.7.8392.0  Could it be I am using the wrong version?



Sep 23, 2009 at 10:32 AM

Ah right - you are using the v2 branch from codeplex - this isn't actually the current v2 tree which is at  . At a guess the FeatureDataTableReader isn't implemented in the tree you are using. If you enumerate the rows of the FeatureDataTable you should be able to get the Geometry. hth jd 

Sep 23, 2009 at 11:24 AM
Edited Sep 23, 2009 at 2:47 PM

Hi John,

Have now done exactly that but now some of the usings are erroring, the ones below cannot be found:







Has there been some re-structing of the namespaces or somthing?



Sep 23, 2009 at 11:53 AM
Edited Sep 23, 2009 at 11:57 AM

Hi dan,

the SharpMap.Data.Providers.Shapefile Namespace has been factored out to a seperate project which you need to reference (look in the providers folder)

For the other two you should be all right with GeoApi.X instead of SharpMap.X. You might need to reference GeoApi.Net as well.



Sep 23, 2009 at 3:14 PM



Now I have another issue, when trying to open the Shape file with the ShapeFileProvider class.  Had a ldig around and it looks like it is because there is a polygon in the shape file which is it failing to find any points then it is failing on an Assertion that a polygon must have more than zero points.

Here is the exception code and desciption:

GeoAPI.Diagnostics.AssertionFailedException - {"Expected value not to be 0 but encountered 0"}

Here is the stack trace...

at GeoAPI.Diagnostics.Assert.IsNotEquals[TValue](TValue unExpectedValue, TValue actualValue, String message) in C:\Projects\SharpMapV2\GeoAPI\src\GeoAPI\Diagnostics\Assert.cs:line 81
   at GeoAPI.Diagnostics.Assert.IsNotEquals[TValue](TValue expectedValue, TValue actualValue) in C:\Projects\SharpMapV2\GeoAPI\src\GeoAPI\Diagnostics\Assert.cs:line 72
   at SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.readPolygon(StreamOffsetUtility offsetUtility, ShapeType shpType) in C:\Projects\SharpMapV2\SharpMap.Data.Providers\ShapeFileProvider\ShapeFileProvider.cs:line 2927

Now the strange thing about this is that I am using the same shapefile as I was with the older version of the sharpmap code and I wasn't having any of these problems, although I was having difficult matching Geometrys to Features which was my original problem.

Any ideas?



Sep 23, 2009 at 3:40 PM

The follow code snippet is the code I have written which generates the error:

ShapeFileProvider sf = null;

ICoordinateFactory<Coordinate> coordinateFactory = new CoordinateFactory();

IGeometryFactory<Coordinate> geometryFactory = new GeometryFactory<Coordinate>(new CoordinateSequenceFactory());

sf = new ShapeFileProvider(filePath, geometryFactory);





Sep 23, 2009 at 5:36 PM

Are you sure the shapefile is valid -  the old reader was very lenient the new one is a lot stricter - and a polygon with 0 outer shells is not a real polygon..

try setting

sf.ReadStrictness = ShapeFileReadStrictness.Lenient; /* this turns what would have been holes into shells if the polygon doesnt have any shells*/ 


before calling sf.Open(false)


 cheers jd

Sep 25, 2009 at 11:00 AM


Your a star, it looks like I have an invalid Shape file, unfortunalty I am not the author so cannot correct it, but the Lenient flag seems to be doing the trick.