Raihan Iqbal
Life is codetastic!

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.

Spatial Reference Identifiers (SRIDs)

Most of their functions, require this as a parameter. If your GIS application uses Google Maps then you should use 4326.

Code Examples

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.64369010925293 41.96765920367816, 
             -87.6309871673584 41.920672548686824, 
             -87.72522926330566 41.91939525416699, 
             -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 ;)

Happy Programming!

Share

Posted in Development, Map, T-SQL, Tools | 6,626 views | 3 Comments

Tags:

3 Responses to “Using MsSqlSpatial with Google Maps”

  1. MsSqlSpatial Demo using Google Maps…

    DotNetBurner – burning hot .net content…

  2. Jerome St-Pierre says:

    Have you heard about this?

    http://postgis.refractions.net/

    This is very cool stuff but SQL Server would be my very last choice if I had to use this kind of technology for a project.

  3. Raihan Iqbal says:

    @Jerome: Yes I have heard about PostGIS. I know its faster and I’m trying to convince my boss to let me use it in our project :)

Leave a Reply