[GIS] Programmatic conversion between GML and GeoJSON

cgeojsongmlleaflet

I am modifying a .Net (C#, MSSQL) system to add some geography that I'd like to display on a leaflet map.

I had originally expected to save GeoJSON directly into text strings in the DB, but after seeing some SQL2008 spatial types, I wonder if I'd be better served by keeping it as WKT or GML so I can run SQL-Spatial queries against it and use C# native objects.

But then, I need to get stuff into GeoJSON or some other leaflet-compatible format.

I realize there are utilities to do the conversion (Convert GML to GeoJSON), but I can't use that on the fly to serve content.

Am I barking up the wrong tree? Any chastisement is welcome. =)

Best Answer

The easiest thing to do will be to store the data in both formats. Run your spatial queries against the spatial types the DB understands, and then serve the pre-converted geoJSON representation for consumption by your Leaflet client.

Note that this solution is best suited for data that won't change frequently and that has a (relatively) small number of geographies (such that they're all stored in the database ready to serve).