Write a WCF service that returns a JSONP response. WCF service should return a data in following format:
[
{
"feature": {
"attributes": {
"objectid": 1,
"fdate": 932428800000,
"resolution": 3,
"gnis_id": null,
"gnis_name": null,
"lengthkm": 0.024,
"reachcode": "11070101001016",
"flowdir": 1,
"wbareacomid": null,
"ftype": 558,
"fcode": 55800,
"enabled": 1
},
"geometry": {
"paths": [
[
[
-95.9899452281111,
38.1345878074741
],
[
-95.9898896947778,
38.1344644074744
],
[
-95.9899164947778,
38.1343866074744
]
]
]
}
}
}
]
Hopefully you've found the answer you're looking for by now but I just came across this and figured I'd take a stab at answering it for others at least.
From C# here's what I do for inserting a Polygon. I'm deriving this on the fly from some working code I have but not actually testing it so forgive any typo errors.
You'll need the following assemblies.
System.Data.SqlClient;
System.Data.SqlTypes;
System.Data.SqlServer.Types;
public void Main()
{
// the coordinate parameters below are doubles that can gathered from wherever, you can add additional points as necessary to the POLYGON list just make sure that they from a counter-clockwise 'circle'
string areaName = "Texas";
string extents = string.Format("POLYGON(({0} {1}, {0} {2}, {3} {2}, {3} {1}, {0} {1}))", leftLongitude, upperLatitude, lowerLatitude, rightLongitude));
InsertArea(areaName, extents);
}
public void InsertArea(string nameParameter, string extentsString)
{
SqlConnection sqlConn = new SqlConnection(...)
sqlConn.Open();
SqlCommand sqlCom = new SqlCommand("INSERT INTO areas (name, extents) VALUES (@name, @extents)", sqlConn);
sqlCom.Parameters.AddWithValue("@name", nameParameter);
SqlParamater extents = new SqlParameter("@extents", SqlDbType.Udt);
extents.UdtTypeName = "Geography";
extents.Value = GetGeographyFromText(extentsString);
sqlCom.Parameters.Add(extents);
sqlCom.ExecuteNonQuery();
sqlConn.Close();
}
public SqlGeography GetGeographyFromText(String pText)
{
SqlString ss = new SqlString(pText);
SqlChars sc = new SqlChars(ss);
try
{
return SqlGeography.STPolyFromText(sc, 4326);
}
catch (Exception ex)
{
throw ex;
}
}
I hope this helps someone.
Best Answer
In theory just replace all SQL commands having geometry:: cast to geography casts (assuming that you 2008 R2 MSSQL server) Edit: looked that example code . Change Microsoft.SqlServer.Types.SqlGeometry to Microsoft.SqlServer.Types.SqlGeography OR Find SQL command which select code and force it to cast your geography objects to geometry