Search code examples
sql-servergeocodinggeography

SQL Geometry return type


In a sql query I can say

select * 
from location
where geoLocation.STDistance(0xE6100000010CDDB5847CD0EB42C033333333331F6240) < 10000

but how do I pass that 0xE61... bit in programatically.

when returning in from the database, it appears to be in a binary format. Thus just putting it into the query doesn't work. If I put it in as type binary it doesn't work either.

Is there a way to retrieve the Geolocation from the database that retains it in the above format, i've tried casting it to varchar but it ends up like POINT(....


Solution

  • SQL has a bunch of static methods for creating geospatial data. Check this out (specifically the OGC static and Extended static links). For example:

    DECLARE @g geography;
    SET @g = geography::STPointFromText('POINT(-122.34900 47.65100)', 4326);
    SELECT @g.ToString();