Rob, I am sure there is a better way to do this but this is the way I implemented it.
The solution I am about to give you should allow you to add markers to a Mapbox map (search "omnivore mapbox" for web application CSV import equivalent of TileMill add data source feature) that can be accessed through your web application and that gets its data from a CSV file generated from a GridView connected to a MS SQL database.
I had at the same problem, data is in SQL 2008 and I need to use it to create a map.
Mapbox required CSV or POSTGRESQL to display pins but I did not have a POSTGRESQL server setup anywhere.
Here is what I did:
(note that I am using C# and creating a ASP NET web application)
- Create an empty ASPX page, let's call it DataGridView.aspx
- Add a GridView
- Link that GridView to your SQL data source
- Create a button, call it "Refresh CSV"
- Double click on it to automatically create an event for that button.
In the code for the event for that button, use this piece of code:
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.AllowPaging = false;
GridView1.DataBind();
StringBuilder sb = new StringBuilder();
for (int k = 0; k < GridView1.Columns.Count; k++)
{
if(k==0) // little trick to avoid comma at the end of the line
{
sb.Append(GridView1.Columns[k].HeaderText);
continue;
}
//add separator
sb.Append(',' + GridView1.Columns[k].HeaderText);
}
//append new line
sb.Append("\r\n");
for (int i = 0; i < GridView1.Rows.Count; i++)
{
for (int k = 0; k < GridView1.Columns.Count ; k++)
{
if (k == 0) // little trick to avoid comma at the end of the line
{
sb.Append(GridView1.Rows[i].Cells[k].Text);
continue;
}
//add separator
sb.Append(','+GridView1.Rows[i].Cells[k].Text );
}
//append new line
sb.Append("\r\n");
}
string a= string.Empty;
StreamWriter yourStream = File.CreateText(Server.MapPath("~/CSVExport.csv"));
a = sb.ToString()+"\r\n"; //formatting text based on poeition
yourStream.Write(a);
yourStream.Close();
}
Don't forget to have these at the beginning of your DataGridView.aspx.cs file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Text;
On the root of your web application, create an empty file, name it "CSVExport.csv".
This is going to hold your GridView Data formatted as a CSV.
Now every time you click that button, it should update your CSVExport.csv file.
To check if everything displays correctly, launch TileMill and run (debug run locally) your website.
Go to [localhost:whateverthatportnumberis]/DataGridView.aspx
Click on the button.
Open CSVExport.csv to check if your file has been updated (you should see your data in CSV file format.)
Now, without stopping your local website test, go ahead and use the link to the CSV file in TileMill
[localhost:whateverthatportnumberis]/CSVExport.csv
If your CSVExport.csv file is formatted correctly, you should see the markers being displayed.
This should answer your question on how to get your data from SQL to a CSV format that can be used by Mapbox.
Your question becomes ambiguous here when you say: " Is there a better way to create a geo-mapping application that has to be accessed locally?". So I am going to stop here.
Again, the solution I just gave you should allow you to add markers to a Mapbox map (search "omnivore mapbox" for web application CSV import equivalent of TileMill add data source feature) that can be accessed through your web application and that gets its data from a CSV file generated from a GridView connected to a MS SQL database.