Label filtering

Topics: General Topics
Mar 2, 2007 at 11:06 AM
Hi,

I have a label layer that I want to filter. Basically, I only want to label features if they appear within a specific polygon on the map. The polygon will be, for example, a county boundary and the labels are the names of towns within that county. I don't want to label the towns that are outside the county.

Is it possible to do this using the LabelLayer.LabelFilter property? If so, how would I go about doing this? I can't find any documentation for this property :(

Cheers,

Dylan
Mar 2, 2007 at 12:14 PM
Hi!

I'd recomend looking into LabelLayer.Theme property and SharpMap.Rendering.Thematics.CustomTheme namespace. This alows you to setup a delegate (public delegate IStyle CustomTheme.GetStyleMethod(FeatureDataRow dr))); pointing to your filter method. There you can examine your FeatureDataRow and build a Style accordingly.

Goran
Mar 2, 2007 at 1:29 PM
Edited Mar 2, 2007 at 1:31 PM
That's a good idea! I have used themes for other types of layers, such as colouring roads differently depending on their classification, but I didn't think to do it for this - where I would show or hide the label depending on its location.

Thanks. I'll see what I can come up with.
Mar 2, 2007 at 2:12 PM
Ok, I've been looking into this for the past 30 mins and I can't figure out how to check whether a point contained within SharpMap.Data.FeatureDataRow is contained within a polygon! I would have presumed that this would work:

if (poly.Contains(row.Geometry))
{
    // Do something
}

where poly is the polygon, and row is the row passed to the method. Yet this appears to return false for all cases including the ones that I know are definitely within the polygon. Any ideas?
Coordinator
Mar 3, 2007 at 9:47 PM
I believe spatial containment isn't implemented until the NTS code is integrated.
Mar 5, 2007 at 4:44 PM
Right. Is this something that still needs to be done, or is it merely a matter of compiling the latest source code? Or something else?
Coordinator
Mar 6, 2007 at 8:21 PM
It's still being worked on - I don't believe the code has been committed yet. Volleyknaller can well correct me on this point, however.
Mar 7, 2007 at 11:58 AM
Ah okay. This problem got me thinking, and I realised it was probably a better idea to do the filtering at the data level rather than when it comes to displaying it, so I decided to have a go at doing it using MsSqlSpatial, which is my data source, but after several attempts I decided to go right back to the source data and pre-process it so that each point knows which polygon it is in - much easier to filter on an attribute that already exists in the data source than it is to dynamically calculate it ;)