Using Theme to set MaxVisible property

Jul 24, 2009 at 10:04 PM
Edited Jul 24, 2009 at 10:07 PM

I am trying to use a custom theme on a New York State Highway/Roads Shapefile to hide smaller roads at a certain zoom level as to only show the major highways.  I believe I am doing it correctly but the shapefile is rather large(154,097kb) and causing the program to become non-responsive.  When I apply MaxVisible at the layer level I do not have a problem loading the map.  I was wondering if there is a more efficient way to go about this or a correct way to go about this.

Here are code snippets:

        //Set up New York Road layer
        SharpMap.Layers.VectorLayer layRoads = new SharpMap.Layers.VectorLayer("Roads");
        //Set the datasource to a shapefile
        layRoads.DataSource = new SharpMap.Data.Providers.ShapeFile(sfPath + "\\" + shapeFiles[3], true);
            
        SharpMap.Rendering.Thematics.CustomTheme roadTheme = new SharpMap.Rendering.Thematics.CustomTheme(GetRoadStyle);
        SharpMap.Styles.VectorStyle defaultstyle = new SharpMap.Styles.VectorStyle();
        defaultstyle.Fill = Brushes.Gray;

        roadTheme.DefaultStyle = defaultstyle;

        layRoads.Theme = roadTheme;

        layRoads.Style.SymbolScale = 0.8f;
        layRoads.MaxVisible = 2;
        layRoads.SRID = 4326;


    public static SharpMap.Styles.VectorStyle GetRoadStyle(SharpMap.Data.FeatureDataRow row)
    {
        SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();
        string val = row["TYPE"].ToString();
        //style.MaxVisible = 2;
        
        switch (val)
        {
            case "motorway":
                style.Line = new Pen(Color.Orange);
                //style.SymbolScale = 0.9f;
                
                return style;
            case "primary":
                style.Line = new Pen(Color.Orange);
                //style.SymbolScale = 0.9f;
                //style.MaxVisible = 2;
                return style;
            case "motorway_link":
                style.Line = new Pen(Color.Orange);
                //style.SymbolScale = 0.9f;
                //style.MaxVisible = 2;
                return style;
            case "trunk":
                style.Line = new Pen(Color.Orange);
                //style.SymbolScale = 0.9f;
                //style.MaxVisible = 2;
                return style;
            case "trunk_link":
                style.Line = new Pen(Color.Orange);
                //style.SymbolScale = 0.9f;
                //style.MaxVisible = 2;
                return style;
            case "residential":
                style.Line = new Pen(Color.Black);
                //style.SymbolScale = 0.7f;
                //style.MaxVisible = .5;
                return style;
            default:
                style.Line = new Pen(Color.Black);
                //style.SymbolScale = 0.7f;
                //style.MaxVisible = 1;
                return style;
        }


       
        return style;
    }
As you can see from the code I would also like to set the scaling differently but one problem at a time.  I just grabbed the project from the trunk yesterday so I believe I am using the current version of SharpMap.  I tried searching for an answer and the closest thing I got was the in the "How to..." section.
Coordinator
Jul 25, 2009 at 11:50 AM

Hi rjonesAtTelog the MinVisible and MaxVisible apply to all features in a layer so really what you want to do is split the shapefile into smaller ones each containing a classification of road (or similar classifications)
then each shapefile goes into its own layer with its own Min/Max Visible setting allowing more fine tuning of performance. So you might split along the lines of

Motorways & Motorway Link

Primary

Trunk Roads & Trunk Link

Residential

hth jd

Jul 27, 2009 at 3:34 PM

That's what I was afraid of.  What would be the best approach to this?  Is there a tool you would suggest to use?

Coordinator
Jul 27, 2009 at 7:23 PM

hi rjonesAtTelog, you may be able to use udig or QuantumGIS both available as part of the OSGeo4W package or linked from http://www.osgeo.org/home there are also command line tools available within FWTools which may help. Failing that ArcGIS or MapInfo hth jd

Jul 27, 2009 at 7:41 PM

Alright I will check those out thank you for the guidance.