Using MsSqlSpatial with Google Maps
One of the many .NET open-source projects that don’t get the attention they deserve is MsSqlSpatial. This project provides spatial extensions to SQL Server 2005 – meaning you can perform various spatial calculations right in your T-SQL queries! Cool eh? But, this project lacks documentation which is a problem for us developers. I’m sure they are working their ass off to make one but in the mean time we have to play around with the code to understand its inner workings.
Since Google Maps is very popular among developers, and my personal favorite, I thought why not give out some tips.
Most of their functions, require this as a parameter. If your GIS application uses Google Maps then you should use 4326.
Convert a Point on the map from a Well-Known-Text(WKT) format to a Well-Known-Binary Format:
SELECT ST.PointFromText('POINT(-87.6673250 41.9489650)', 4326)
The Point should be of the format POINT( longitude latitude ).
Polygon to text:
SELECT [Bloggernate].[ST].[PolygonFromText] ( 'POLYGON((-87.71956443786621 41.96727630029047,
-87.71956443786621 41.96727630029047))' ,4326)
The polygon must be a closed one otherwise you’ll receive an exception.
Check if a polygon contains a specified point:
SELECT [ST].[Contains] (YOUR_WKB_POLYGON, YOUR_WKB_POINT)
I hope this provides a good starting point for those daring to step into the unknown