Friday, August 12, 2011

Convert Lat/Lon into a Geolocation SQL Server 2008(Example)

To convert the latitude and longitude coordinates to a geography point, we will use the StPointFromText function. 
The STPointFromText returns a geography instance from an Open Geospatial Consortium (OGC) Well-Known Text (WKT) representation.

CREATE TABLE  Locations(lat float ,lon float,[GeoLocation] GEOGRAPHY)

INSERT INTO Locations(lat,lon)values

UPDATE Locations set [GeoLocation] = geography::STPointFromText('POINT(' + CAST([Lon] AS VARCHAR(20)) + ' ' + CAST([Lat] AS VARCHAR(20)) + ')', 4326)

No comments:

Post a Comment