Parent layer from instance of FeatureDataRow

Topics: SharpMap v0.9 / v1.x
Feb 10 at 4:20 PM
Edited Feb 10 at 4:20 PM
Hello,

I'm using similar code as on the CustomTheme rendering documentation page here: https://sharpmap.codeplex.com/wikipage?title=CustomTheme

I would like to know which layer the geometry being rendered is. For example when I receive a FeatureDataRow, is there an attribue in that instance that refers to the parent layer name?

The only solution I found so far is horribly slow and messy, I would like to know if there is any other way. Maybe building a dictionary of geometries ObjectID and layer names before rendering so that I can directly lookup by feature ObjectID in that dictionary?

For now this is my ugly solution:
    private SharpMap.Styles.VectorStyle GetCountryStyle(SharpMap.Data.FeatureDataRow row)
    {

            string layerName = "";
            foreach (SharpMap.Layers.VectorLayer vlay in mapBox1.Map.Layers)
            {
                foreach (GeoAPI.Geometries.IGeometry geometry in (vlay as SharpMap.Layers.VectorLayer).DataSource.GetGeometriesInView(mapBox1.Map.Envelope))
                {
                    if (row.Geometry.Equals(geometry))
                    {//matched layer name, this is kind of bad because layers can have matching geometries if the same shapefile is loaded twice for example
                        layerName = vlay.LayerName;
                        break;
                    }
                }
            }
Coordinator
Feb 11 at 7:41 AM
If you derive yourself a CustomTheme, you can keep track of the layer it is assigned to in a member variable.