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

GradientTheme for XY points does not work (layer is correctly added but points does not show)

Topics: SharpMap Project, SharpMap v0.9 / v1.x
Jun 17, 2016 at 5:33 PM

I built a function that creates a point layer from X-Y-value data. I'm trying to show the layer on the map with a color gradient on the "value" column.

In another function I get the layer created by the CreatePointsLayer() function and show it in the map, then zoom to the extents. The zoom to extents works fine but the points are not showing.

If I only use the PointColor method to change all points color, it works.

I don't know if that might help, I tried accessing a data row of my layer using layPoints.DataSource.GetFeature(0) and I'm getting an error: "Attribute data is not supported by the GeometryProvider."

Here's the code:
public SharpMap.Layers.VectorLayer CreatePointsLayer(DataGridView dgv)
            SharpMap.Layers.VectorLayer layPoints = new SharpMap.Layers.VectorLayer("Points");

            SharpMap.Data.FeatureDataTable dt = new SharpMap.Data.FeatureDataTable();

            GeoAPI.GeometryServiceProvider.Instance = new NetTopologySuite.NtsGeometryServices();
            GeoAPI.Geometries.IGeometryFactory gf = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory();

            var rows = dgv.SelectedRows;
            foreach (DataGridViewRow row in rows)
                string raw_x = row.Cells[dgv.Columns["x_coord"].Index].Value.ToString();
                string raw_y = row.Cells[dgv.Columns["y_coord"].Index].Value.ToString();
                double value = Convert.ToDouble(row.Cells[dgv.Columns["value"].Index].Value);

                double long_x;
                double lat_y;

                ToLatLon(Convert.ToDouble(raw_x), Convert.ToDouble(raw_y), "19N", out long_x, out lat_y);

                SharpMap.Data.FeatureDataRow f_row = dt.NewRow();
                f_row["value"] = value;

                GeoAPI.Geometries.IGeometry geom = gf.CreatePoint(new GeoAPI.Geometries.Coordinate(lat_y, long_x));
                f_row.Geometry = geom;


            layPoints.DataSource = new GeometryProvider(dt);

            SharpMap.Styles.VectorStyle min = new SharpMap.Styles.VectorStyle();
            SharpMap.Styles.VectorStyle max = new SharpMap.Styles.VectorStyle();
            //Create a fill that starts from white to red
            //and an outline that starts from thin black to wide yellow
            min.PointColor = Brushes.White;
            max.PointColor = Brushes.Red;

            double min_val = 0;
            double max_val = 10;
            layPoints.Theme = new SharpMap.Rendering.Thematics.GradientTheme("value", min_val, max_val, min, max);

            // layPoints.Style.PointColor = new SolidBrush(Color.Purple);   <<----- This is working fine.

            return layPoints;
Jun 18, 2016 at 7:10 PM
You need to use GeometryFeatureProvider.
Jun 20, 2016 at 2:18 PM
I've changed
layPoints.DataSource = new GeometryProvider(dt);
layPoints.DataSource = new GeometryFeatureProvider(dt);
and now the layer show, but my layer still shows with the default colors. I've checked the layPoints object and the theme is correctly applied to the object.

Any idea where is the problem ?
Jun 20, 2016 at 3:48 PM
It seems that neither PointColor nor PointSize are handled in the current implementation of GradientTheme. Sorry.
You can grab the source and modify CalculateVectorStyle according to your needs.