Extending SharpMap with SQLite

Or vice versa.

A while back I posted about setting up a GIS server using open source GIS technologies. When I left off, I was going to start messing with SharpMap. I’ve been able to get back to that recently. I am working on a project where I need to do some basic spatial operations on a workstation but I want to keep a relatively small software foot print on the box. Of course, this screams “web service” or some such thing but the platform is mobile with no guaranteed network access.

So I went back to SharpMap. It’s footprint is relatively small (compared to ArcGIS) and the licensing model can’t be beat 🙂 . Next, I had to focus on the data source. I decided to look at SQLite due to its small footprint. Additionally, the availabiliy of an OLEDB driver gave me option for non-spatial data that shapefiles alone didn’t (I just didn’t want to wrestle with the dBase driver).

So I got to do something I’ve wanted to do for a while: write my own data provider for SharpMap. There’s probably something out there already but how can I learn that way? So I based my data provider class on the class that already existed for MS SQL Server (MsSql.cs). It served as an excellent basis. I was surprised at how very easy it was to do this sort of implementation. The picture below depicts a SharpMap MapImage control with polygon data being read from SQLite.

SharpMap desktop app with data from SQLite

SQLite is inherently text-based so I found it easier to store the geometry as WKT rather that WKB but that actually helps me with another project requirement: displaying the data in a WPF form. Transforming the WKT to XAML will be easier but I digress.

I am very impressed with the updates being made to SharpMap. I feel like I’m just scratching the surface of what it can do. Version 2.0 has not technically been released but I have found the latest builds to be very stable and I’m moving forward without hesitation using it in my project.

I have uploaded my code below. Just rename it to a .cs file.

Click here for the SqlLite.cs source code

hit counter

  • Great choice and great post 😀
    Please post you code in the SharpMap website, so Sqlite provide could be added as standard provider for SharpMap.

  • Thanks! I’m glad you like it. I’ll definitely post the code over at SharpMap. I’ve been shuttling between meetings this morning.

  • Bill I think we should definitely consider using SharpMap as the zigGis layer provider, we could easily extend zigGis to work with any data source implemented for SharpMap (MySQL Spatial, PostGIS, MS SQL Spatial…..). I wish I can spend some time this summer for making this integration, what do you say?

  • test (bill, is it moderated now?)

  • Nope. It’s not moderated. I got your first comment just fine.

    I think your suggestion is definitely worth looking into. SharpMap has certainly tackled the data access piece for a lot of data sources.

    Looking forward to our chat session.

  • Really cool example Bill. I was looking for something similar to this.


  • @Regina

    I hope you find it useful. Thanks for the feedback.

  • Pingback: SharpMap and SQL Server 2008 Spatial « GeoMusings()

  • Ricardo Stuven

    Check out SpatiaLite & VirtualShape, spatial extensions for SQLite: http://www.gaia-gis.it/spatialite/

  • @Ricardo

    Downloading as I type. Thanks for pointing that out.

  • jayanliyanage

    Dear Sir,

    we are a project group that implements GPS Navigation system using sharpmap version 0.9. (Desktop application)
    we are facing some problems of using sharpmap.

    we want to know how to add a symbol(image clip) to a loaded map, for a button click event.

    also we need to know how to retrive data from postgresql data base using sharpmap data providers.

    also we need to know a method to dynamically load several shape file maps when the GPS reciver moves on the map.

    we need source code (in C#.net 2005) to do these tasks and if you can help on this topics please send us a email

    Thank You

    Jayan Liyanage

  • @Jayan

    Thanks for stopping by. You inquiry covers a lot of ground and will take some time for me to dig up some of the specifics but some of your questions may already be addressed in the excellent “How To” article on the SharpMap site.

    Much of the documentation it focused on web applications but most of the lower-level operations work on the desktop without modification.


  • Satheesh


    Good work! But when I tried to load SQLite using SharpMap in VC# 2008 Express; I got the following error.
    Error 1 ‘SharpMap.Data.Providers.SqlLite’ does not implement interface member ‘SharpMap.Data.Providers.IProvider.GetGeometriesInView(SharpMap.Geometries.BoundingBox)’. ‘SharpMap.Data.Providers.SqlLite.GetGeometriesInView(SharpMap.Geometries.BoundingBox)’ cannot implement ‘SharpMap.Data.Providers.IProvider.GetGeometriesInView(SharpMap.Geometries.BoundingBox)’ because it does not have the matching return type of ‘System.Collections.Generic.List’.

    I followed the steps
    1. Downloaded SharpMap & SharpMap.UI assemblies
    2. Downloaded SqlLite.cs source code from this current page
    3. New Project in C# and referenced SharpMap & SharpMap.UI
    4. Added SqlLite.cs
    4. Compiled

    Kindly let me know, where I am doing mistake.
    Thanks in Advance, for anyone’s kind help

  • The SQLite provider is now part of the SharpMap project. This code was written against an older version and I think the interface has changed since then. You should use the one that is distributed with SharpMap.

    I hope that helps.


  • Satheesh

    Thanks Bill, Downloaded SqlLite.cs from http://www.codeplex.com/SharpMap/Wiki/View.aspx?title=SqlLite&referringTitle=Extensions

    Now it works good. Thanks again!

  • Great! I’m glad that set you straight. Have fun with SharpMap!

  • Pingback: Odds and Ends (SpatiaLite and Stuff) « GeoMusings()