Having problems adding a layer of collections

Topics: SharpMap Project, SharpMap v0.9 / v1.x, SharpMap v2.0, WinForms Controls
May 16, 2013 at 4:57 PM
I have a simple application which loads a shape file and then adds a layer which contains a collection of points. I want to add a custom theme to the layer so that the color of the points can be changed based on some criteria. The problem is that when I create a custom theme for the layer and run the application, I get UnsupportedException. Without the custom theme the code run perfectly. what I am missing here?

I have included the code as below:
private void AddLayer()
            SharpMap.Layers.ILayer lay = map.Map.Layers.GetLayerByName("EventLayer");
            if (lay != null)
            SharpMap.Layers.VectorLayer vectorLayer = new VectorLayer("EventLayer");
            Collection<GeoAPI.Geometries.IGeometry> geomColl = new Collection<GeoAPI.Geometries.IGeometry>();
            GeometryServiceProvider.Instance = new NtsGeometryServices();
            GeoAPI.Geometries.IGeometryFactory gf = GeometryServiceProvider.Instance.CreateGeometryFactory();

            //Add a single Point
            //geomColl.Add(gf.CreatePoint(new Coordinate(10, 10)));

            //Add a LineString with 2 Points
            Coordinate[] points = new Coordinate[] 
                new Coordinate(10, 10), 
                new Coordinate(20, 20), 

            vectorLayer.DataSource = new SharpMap.Data.Providers.GeometryProvider(geomColl);
            SharpMap.Rendering.Thematics.CustomTheme pointTheme = new SharpMap.Rendering.Thematics.CustomTheme(GetPointStyle);
            SharpMap.Styles.VectorStyle defaultstyle = new SharpMap.Styles.VectorStyle();
            //defaultstyle.Fill = Brushes.Gray;
            //pointTheme.DefaultStyle = defaultstyle;
            //vectorLayer.Theme = pointTheme;
            vectorLayer.Style.Fill = Brushes.HotPink;
private SharpMap.Styles.VectorStyle GetPointStyle(SharpMap.Data.FeatureDataRow row)
            SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();
            // If geometry is a (multi)polygon and the area of the polygon is less than 30, make it cyan            
            if (row.Geometry is GeoAPI.Geometries.IPoint)
                GeoAPI.Geometries.IGeometryFactory gf = GeometryServiceProvider.Instance.CreateGeometryFactory();
                IPoint pt = gf.CreatePoint(row.Geometry.Coordinate);
                style.Fill = GetPointColor(0);
                style.PointSize = 1f;
                style.PointColor = GetPointColor(0);
                return style;
            return null;                        
May 17, 2013 at 7:14 AM
The problem is that the plain GeometryProvider does not support ExecuteFeatureQuery method, which is necessary for theming.
Use GeometryFeatureProvider instead.

Hth FObermaier
May 17, 2013 at 9:55 PM
Thank you so much. That fixed the problem.