This project has moved. For the latest updates, please go here.

VectorLayer issue

Topics: General Topics, SharpMap Project, SharpMap v0.9 / v1.x
Jun 29, 2010 at 11:50 AM

The issue is that if an IProvider gives to VectorLayer features that are derived from Geometry the render method will fail. This happens because in VectorLayer.RenderGeometry, feature.GetType().Name will not be a Geometry class name and Enum.Parse on GeometryType2 will fail.

In my project i have created a class named Infrastructure inheriting LineString. Feature.GetType().Name will return "Infrastructure" which is not a member of GeometryType2. The solution to this is to refer to Feature.GetType().BaseType.Name which will eventually be "LineString". My IProvider adapter class recieves Infrastructure items and type-casts them as (Geometry)infr, and casting in C# does not erase information about the derived type.

A simple solution would be to place the Enum.Parse line in a Try-Catch block, and if an ArgumentNotFound exception is raised, try to Enum.Parse on the base type, but it is rather inefficient.

Any help appreciated,
Andrei Stefan

Jun 29, 2010 at 12:24 PM

Hello andrei,

I'm no fan of Enum.Parse() function calls in time critical situations. I'd prefer to

a) change the switch case block to if (feature is <GeometryType>) ... block

b) add GeometryType2 property to all geometry classes.

Any pro/cons or other suggestions?