This project has moved. For the latest updates, please go here.

Unable to load Shape files in SharpMap v0.9 - build 2423

Topics: SharpMap Project, WinForms Controls
Feb 14, 2010 at 11:39 AM

Dear John Diss,

I am using SharpMap v0.9 - build 2423 in a WinForms application.

I am filling the geometries in a FeatureDataTable and setting the VectorLayer's DataSource property to a GeometryFeatureProvider which holds the before mentioned FeatureDataTable. It has been working wonderfully until now.

Now I have a need to also add Shape file layers into the map. Below is the code I am using to load a shape file:

            VectorLayer shpLayer = new VectorLayer(layerName);
            shpLayer.DataSource = new ShapeFile(shpFilePath, false);
            shpLayer.Style.Outline = Pens.Azure;
            shpLayer.Style.EnableOutline = true;
            shpLayer.Style.Fill = new SolidBrush(Color.Beige);
            shpLayer.SRID = Constants.WGS_84_SRID;


VectorLayer shpLayer = new VectorLayer(layerName);
shpLayer.DataSource = new ShapeFile(shpFilePath, false);

shpLayer.Style.Outline = Pens.Black;
shpLayer.Style.EnableOutline = true;


The problem is that most of the shape files I use for testing raise an exception in the constructor of QuadTree(List<BoxObjects> objList, uint depth, Heuristic heurdata). The objList parameter contains zero elements in it. Therefore the line "_box = objList[0].box;" throws an IndexOutOfRange exception.

For some files, no exceptions are thrown, but nothing is displayed in the map either!

I do understand that based on the Datum of various layers the projections need to be transformed. But in the proof-of-concept I am working right now, there are no such tricky circumstances. I have a dummy form with a MapImage control and the above code to load shape file in it.

Please help me out with this. I definitely don't want to upgrade to SharpMap v2 before it atleast reaches the RC stage. If I am not wrong, it is in alpha right now.

Feb 14, 2010 at 10:10 PM

Hello kraghavk, have you tried constructing the shapefile provider with 'true' for the spatial index parameter. It seems to me it ought to be set to 'true' for that provider to work correctly

Hth FObermaier

Feb 15, 2010 at 11:08 AM

Hi kraghavk, As far as I can tell you are trying to spatially index an empty dataset and it is failing. I am not sure I agree that this is an error in sharpmap. jd

Feb 18, 2010 at 7:15 AM


If I use "true" for the spatial index parameter, then I get the dreaded "Unable to read beyond the stream" exception.


I am not really good at ArcGIS formats. This is a project I have been developing for NGOs to monitor their afforestation/reforestation programmes. GIS map is a necessity and I did not quite understand any of the existing GIS softwares. At, first I started with my own solution using GDI+ (ick!), which obviously did not come out that well. So I started looking for any existing open source libraries and found this gem called SharpMap. So, anything well within GeometryFeatureProvider, I am able to troubleshoot and help myself out. But with SHP files being totally unknown entity to me, I am not really sure where the problem is.

I do not have the SHP files with me right now. When I do get them, can I send them across to you, so that you can have a look and let me know what the issue might be?


Feb 20, 2010 at 5:58 AM


Thanks for taking the time out to check the SHP files. The problem seems to be with the version of SharpMap I was using.

I was using v0.9.3528.25138 which had this problem. Now I have downloaded and rebuilt my app using v0.9.3575.26255 which does not seem to have this problem.


Nov 8, 2010 at 5:04 AM

Hi my friends,

I have a problem and hope you will help me,


As you know, ShapeFile Provider is always using Spatial Index, right?

I want to do a comparision between using and not using Spatial Index with shp file. ShapeFile Provider in SharpMap 0.9 is using Spatial Index, now I need a ShapeFile Provider which is NOT using Spatial Index. How can I do this?

Thanks for your time, my friends!