Memory overflow when loading large polygon shape file

Feb 17 at 8:14 AM
Edited Feb 17 at 8:14 AM
When loading the shapefile (polygon, 308 mb) I can see how quickly is increasing the size of RAM usage (3 GB) and program crashes. Any ideas how to fix this and why this is happening?
Coordinator
Feb 17 at 10:17 AM
Could you show us the instantiation code of the shapefile provider and the vector layer, please.
Feb 17 at 11:58 AM
        public void createVectorLayer1(string srcName, string layerName)
        {
            ShapeFile shapeFileProvider = new ShapeFile(srcName, true);
            shapeFileProvider.Encoding = System.Text.Encoding.GetEncoding(1251);
            v_layer = new VectorLayer(layerName, shapeFileProvider);
            mapBox1.Map.Layers.Add(v_layer);
        }
Feb 17 at 12:24 PM
Feb 18 at 6:02 AM
Edited Feb 18 at 6:02 AM
Sorry. A little mistake, when renaming files. Once again the same files, but with the right extensions
TEXT
Coordinator
Feb 22 at 12:45 PM
There actually seems to be an issue with the pure amont of geometries in this file, as the VectorLayer loads all geometries of the current viewport into memory and then draws them.

You can
  • split the Shapefile in several Shapefiles and create a vector layer for each and group them in a LayerGroup,
  • restrain the maximum viewport size so the Shapefile does not get to be seen with all the geometries
  • set some filter to reastrain the features by their attributes.
Mar 7 at 5:17 AM
Edited Mar 7 at 6:21 AM
Not yet figured out why, but the fact is. I restricted sampling using a filter, there are 270 records left. However, all 40,000 polygons were drawn and quite quickly.
To set the filter - renamed the field to the name without Cyrillic ("УЛ" -> uch_lesn). And set the filter like this:
ShapeFile shapeFileProvider = new ShapeFile(srcName, true);
if (layerName == "kvartals")
        shapeFileProvider.FilterDelegate = new SharpMap.Data.Providers.ShapeFile.FilterMethod(delegate(SharpMap.Data.FeatureDataRow row) { return (!row["uch_lesn"].ToString().StartsWith( "Кемское" )); });
New shape:
TEXT
All polygons are visible (display time ~ 20 sec);
TEXT
Left in the file only the filtered (in arcmap) polygons:
TEXT

If the filter is removed, the memory overflows and program crashes.
Coordinator
Mar 7 at 6:38 AM
Ah, now I got it. The provider tries to cache the features in memory. Use ShapeFile shapeFileProvider = new ShapeFile(srcName, true, false); constructor.
Mar 7 at 6:46 AM
Yes, it works ! Thank you very much)))