[GIS] Loading different shapefile in SharpMap

cshapefilesharpmap

I am currently working on sharpmap project with the need to work on offline maps. As i am fresher in this field,I am following the sharpmap tutorial and facing a problem with loading new shape files in the given tutorial code.

For Example :

SharpMap.Layers.VectorLayer("States");
        vlay.DataSource = new SharpMap.Data.Providers.ShapeFile("path_to_data\\states_ugl.shp", true);

At this line of code,if i pass a different shapefile,code builds with a blank background or no display.
I have tried with different shape files with different sizes but the result is the same. It only works for the mentioned states_ugl.shp file given in the code.

Best Answer

My suggestion is look at the sample code the is in the SharpMap solution. Source code: older on CodePlex https://sharpmap.codeplex.com/

Current Fork on GitHub https://github.com/SharpMap/SharpMap It was pretty easy to get to compile using VS2013 or VS2015. Open SharpMap.sln Take a look at Examples\WinFormSamples and Examples\DemoWinForm projects

A couple things I learned over the years using shapeFiles. - Older shapefiles mid 1990s can be problematic to use. (I have a volcanoes shape file what had a duplicate column name (allowable in DBF but not MS access or FoxPro). And older versions SharpMap would error out

  • Check shapefile projection/Coordindations. Most common issue is the shape file is plotted to an incorrect position due coordinate transformation error.

  • Use a viewer like ESRI ArcGIS Explorer to validate the shapefile.

Related Question