Using thematics with WFS client

Topics: Algorithms, SharpMap v0.9 / v1.x
Jan 6, 2015 at 7:37 AM
Edited Jan 6, 2015 at 7:39 AM
I am trying to apply a CustomTheme to a VectorLayer with WFS as a datasource. So far without success. It all works fine without the theme and with only a VectorStyle. If a apply ANY theme, the output is blank. I am using version 1.1 of SharpMap.

My first question: Should this be possible? If yes, what am i doing wrong? :-) If a more complete code or sample app is required, i can provide those.

A note: In debugging i can see, that the GetStyle function never gets called, and the blank result returns so quickly, that i suspect nothing is rendered at all, when i use the CustomTheme.

Here are the steps i am using:
//Creating the WFS client and adding some OGCfilters
WFS wfs = new WFS(....)
wfs.QuickGeometries = true;

//Creating the VectorLayer, with the wfs as a data source.
VectorLayer vl = new VectorLayer("test", wfs);

//Creating the CustomTheme and applying it to the VectorLayer.
CustomTheme ct = new CustomTheme(GetStyle);
vl.Theme = ct;

//A simple function for testing the CustomTheme
public static VectorStyle GetStyle(FeatureDataRow row)
            return new VectorStyle() { Fill = Brushes.Red, Outline = Pens.Black, EnableOutline = true };

//I also create a map and add the VectorLayer to it. Call ZoomToBox and GetMap on the map.
As mentioned, it all works fine when using a VectorStyle directly:
VectorStyle style = new VectorStyle();
style.Fill = Brushes.Green;
style.Outline = Pens.Black;
style.EnableOutline = true;
style.Enabled = true;
vl.Style = style;
Jan 7, 2015 at 11:05 AM
If you want to use thematics on a vector layer, VectorLayer uses IProvider.ExecuteIntersectionQuery to get the data.
The WFS provider is only capable to get one attribute data. You need to set "WFS.Label" to the name of the property you want to get the data.
Once you have set that, call WFS.GetGeometriesInView with some small extent to set everything up ok. Using WFS.QuickGeometries is contraproductive in this scenario.
Jan 8, 2015 at 1:01 PM
Edited Jan 8, 2015 at 1:09 PM
Thank you for a quick reply!

I tried as you suggested and added the following code:
wfs.Label = "kms:Enhedid";

FeatureDataSet fds = new FeatureDataSet();
wfs.ExecuteIntersectionQuery(envelopeUTM32, fds);

Collection<IGeometry> geometries = wfs.GetGeometriesInView(envelopeUTM32);

wfs.GetGeometriesInView returns the geometries correctly, if i set wfs.QuickGeometries to true. If i set wfs.QuickGeometries to false, an empty list is returned. In both cases the wfs server is called correctly and returns the data. I looked at the code for the createGeometries function in the PolygonFactory class here, but was unable to find out why it fails to return anything.
Jan 8, 2015 at 1:41 PM
Edited Jan 8, 2015 at 1:44 PM
This should do:
wfs.Label = "kms:Enhedid";
Collection<IGeometry> geometries = wfs.GetGeometriesInView(envelopeUTM32);
Jan 8, 2015 at 2:04 PM
So no wfs.ExecuteIntersectionQuery?

I tried that, and it seemed to make no difference. The only way i can get it to work, is to set wfs.QuickGeometries to true and NOT set wfs.Label.
Jan 8, 2015 at 7:27 PM
Edited Jan 8, 2015 at 7:29 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.

Could you provide a unit test, an url to a WFS Server?