jump to navigation

Extending SharpMap with SQLite 31 July 2007

Posted by Bill Dollins in gis, open source, sharpmap, sqlite.
trackback

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

Comments»

1. Diego Guidi - 31 July 2007

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

2. Bill Dollins - 31 July 2007

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

3. Paolo Corti - 31 July 2007

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?

4. Paolo Corti - 31 July 2007

test (bill, is it moderated now?)

5. Bill Dollins - 31 July 2007

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.

6. Regina Obe - 31 July 2007

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

Thanks,
Regina

7. Bill Dollins - 1 August 2007

@Regina

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

8. SharpMap and SQL Server 2008 Spatial « GeoMusings - 19 December 2007

[...] I previously sung the praises of SharpMap and its ease of extensibility. The turn-around time needed to write a provider speaks well of SQL 2008 to this point. All of the [...]

9. Ricardo Stuven - 16 April 2008

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

10. Bill Dollins - 16 April 2008

@Ricardo

Downloading as I type. Thanks for pointing that out.