[GIS] Options for getting data from SQL Server into Leaflet app

ajaxleafletsql server

I have polygon data in SQL Server 2012 that I need to get onto a Leaflet application – we're not talking thousands of polygons, but simplified U.S. counties where only one state will be displayed at a time. The database gets updated every 5 minutes and the map needs to reflect that. I know there are several ways to get the data to geojson/json and put that onto the map (such as the jQuery $.getJSON method). We've thought about creating a web service to pull the data and do the conversion to geojson, then get it onto the map with Ajax. The concern there is that this sounds slow and CPU-intensive. Thoughts on that?

I'd lke to know if there are any methods that would allow me to more directly query SQL Server (from within the application perhaps) and get the polygon data into my Leaflet app, keeping in mind that it needs to be refreshed every 5 minutes.

Best Answer

To expand on my comment, let me talk about a similar application I had developed to showcase results of an election. There was some data which was updated periodically in the database (i.e. the Results), while most of the data, including the Geometry did not change.

  1. My JavaScript Application used a static GeoJSON file for the static data and Geometry.

  2. I had a C# windows Service on the Server. It periodically queried the database, and dumped the dynamic parts as a JSON file in the WebServer.

  3. My JavaScript Application, periodically queried for the JSON file with a timestamp attached to the GET request, so that it got the latest data. Once the Ajax call received the data, it changed the symbology of the Vector layer.

Part 2 was developed in this way, instead of a normal web service, to reduce the strain on the database. A conventional service would be hit by all clients, and hence there would be many calls to the database. We wanted to avoid that, and cache this data. Hence we proceded with the architecture given in step 2.