Parse Shapefile using SharpMap

Our current project required us to read Shapefile and import the shape (from .shp file) and data (from .dbf file) from the same. We investigated into quite a few tools having the ability to parse a shape file and import the shape (also called Geometries) along with the data into the database. These tools were either not up to the mark or pretty costly. This is when I came across SharpMap which did the trick for us.  

SharpMap is an easy-to-use mapping library for use in web and desktop applications. It is an open source under GNU Lesser General license.  

Download and import the SharpMap dll  

 You can download the SharpMap dll from here. Import the compiled dll into the application by browsing downloaded location.  

Write code to import Shapefile data 

    
ShapeFileProvider sf = null;
sf = new ShapeFileProvider(filePath);
sf.Open(false);
BoundingBox ext = sf.GetExtents();
FeatureDataSet ds = new FeatureDataSet();
sf.ExecuteIntersectionQuery(ext, ds);
FeatureDataTable<uint> table = ds.Tables[0]
as FeatureDataTable<uint>//TODO:
//Read the .dbf data from the row.

foreach (FeatureDataRow row in table.Rows)
{
   Polygon polygon = row.Geometry
          as SharpMap.Geometries.Polygon;
   if(polygon != null)
  {
     foreach (var vertex in polygon.ExteriorRing.Vertices)
     {
        double latitude = vertex.Y;
        double longitude = vertex.X;

        //TODO:
        //Import to to the database.
     }
   }
}

 

 

You can write a program which would run once and import all the shapefile data into your database schema. You will, thus, have all the data to play at will. Try it out.

Advertisements

Bing Map Silverlight Control Released

I had been playing around with the Bing Map Silverlight Control CPT for quite sometime now and was really thrilled to find out that it has finally been released. Great news for all the MS developers who wanted to get rid of the pain of coding JavaScript to integrate Maps to their application. The control leverages the power and richness of Silverlight technology. The interactive SDK looks really cool. Microsoft can really make a big impact on the GIS front with the Bing Map Silverlight Control.

There is, however, a point concern. Microsoft has altered the Terms and conditions for usage. Here is a list of some of the features in the Bing Maps Silverlight Control v1.0:

• Silverlight 3 enabled,
• Position Silverlight UIElements on the Map,
• Data Binding with the MapItemsControl,
Bing Maps Web Services support,
• World Wrap / infinite pan across the dateline,
• Design-time integration with Expression Blend,
• Scripting interface for coding with JavaScript,
• cool Online Interactive SDK.

Here are some useful links to try out the new Bing Maps Silverlight Control:

Download Bing Maps Silverlight Control
Bing Maps Silverlight Control Interactive SDK
Bing Maps Silverlight Control SDK
Bing Maps Account Center

Hope this was useful.