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

What is the Fastest Way to Open\Render Huge Shapefiles ?

Topics: SharpMap v0.9 / v1.x, WinForms Controls
Sep 16, 2011 at 1:55 PM

I'm pretty new here,

I want to open and next render huge shapefiles ( more then 100MB ). What should i choose for it ImageBox/MapBox/MapImage ? What is the best apprach to do it?

        //--> Define the data name and source
        const string DATA_NAME = "World Countries";
        const string DATA_PATH = @"C:\Files\\SharpMap\POL_adm\POL_adm2.shp";
        const string DATA_PATH2 = @"C:\Files\\skany_map\Poz\pozPlan.TAB";
        ICoordinateTransformation transform;

        countriesLayer = new SharpMap.Layers.VectorLayer("Mapa");
        countriesLayer.DataSource = new SharpMap.Data.Providers.ShapeFile(GlobalVar.DATA_PATH);


        ICoordinateSystem source = ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84;

            var ctf = new CoordinateTransformationFactory();
            var target = new CoordinateSystemFactory().CreateFromWkt(
                "PROJCS[\"World_Plate_Carree_Degrees\", GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\", SPHEROID[\"WGS_1984\", 6378137, 298.257223563]],PRIMEM[\"Greenwich\", 0], UNIT[\"Degree\", 0.017453292519943295]],PROJECTION[\"Mercator\"], PARAMETER[\"False_Easting\", 0],    PARAMETER[\"False_Northing\", 0], PARAMETER[\"Central_Meridian\", 0], PARAMETER[\"Latitude_of_origin\", 0], UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], AXIS[\"East\", EAST], AXIS[\"North\", NORTH]] ");

            //Create transformation
            CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();

            countriesLayer.CoordinateTransformation = transform;

            (_sharpMap.Layers[0] as VectorLayer).CoordinateTransformation = transform;

            //--> Zoom the map to the entire extent

            countriesLayer.Style.Fill = Brushes.LightGreen;
            countriesLayer.Style.EnableOutline = true;
            countriesLayer.Style.Outline = Pens.DarkGreen;

            _sharpMap.BackColor = Color.LightBlue;
            SharpMap.Layers.LabelLayer labelLayer =
            new SharpMap.Layers.LabelLayer("Country Names");
            labelLayer.DataSource = countriesLayer.DataSource;
            labelLayer.LabelColumn = "Varname_2";
            labelLayer.Style.CollisionDetection = true;
            labelLayer.Style.CollisionBuffer = new SizeF(35, 35);
            labelLayer.MultipartGeometryBehaviour =
            labelLayer.Style.Font = new Font(FontFamily.GenericSansSerif, 8);

            SharpMap.Layers.VectorLayer VLayer = new SharpMap.Layers.VectorLayer("GeometryLayer");

            VLayer.CoordinateTransformation = transform;

            Collection<SharpMap.Geometries.Geometry> GeomColl = new Collection<SharpMap.Geometries.Geometry>()
            VLayer.Style.EnableOutline = false;

            SharpMap.Rendering.Thematics.CustomTheme myTheme = new SharpMap.Rendering.Thematics.CustomTheme(GetCountryStyle);
            VLayer.Theme = myTheme;


            _sharpMap.Center = new SharpMap.Geometries.Point(2256983.38012856, 6790586.36976343);
            _sharpMap.Zoom -= _sharpMap.Zoom * 2.5 * ZOOM_FACTOR;

            pictureBox1.Image = _sharpMap.GetMap();


Sep 17, 2011 at 2:42 PM

What kind of data is you trying to visualize?

The size (100Mb) is not a problem as long as follow some rules:
* Set filters according to zoom-level (it's unessecary to draw many features on the same pixel when viewing the world)
* Let SharpMap create a spatial index on the data
* If you need more performance and have many different filters/styles you can gain performance by splitting the file into several filtered files.

But as usual, test and see where your bottleneck is..

Mapbox have some more functionality compared to MapImage, but both uses the same way to draw the map så performance on mapdrawing will not vary depending on choice of MapControl.



Sep 19, 2011 at 2:51 PM

Yes, I  need more performance. Could you help me, please?

Could you show me some examples?

*How can i  gain performance by splitting the file into several filtered files?

*How to reduce the number of pixels?

I would be thankful for any help.


Sep 19, 2011 at 6:46 PM

1. In what reference system is your dataset represented and in what reference system are you planning to display the data. 
- Number one rule, these two should be the same to get performance, if thats not the case you should transform you dataset.

2. For creating filtered  base-layers you can  use the ogr2ogr tool of the fwtools suite for example ( With ogr2ogr you can also change the Spatial reference system

Example: filtering a shapefile shapefile1.shp in regard of an level attribute you can do

ogr2ogr -where "LEVEL=1" -f "ESRI Shapefile" shapefile_level1.shp shapefile1.shp
ogr2ogr -where "LEVEL=2" -f "ESRI Shapefile" shapefile_level2.shp shapefile1.shp


Then you can make sure that low resolution only level 1 (biggest roads) is drawn, then when zooming in you can make level2 roads appear and so on.. 

You control this via the Max/Min Visible property of the layer.