Search code examples
sqlsqlgeography

How do I select Lat & Long coordinates back out of SQL Server Geography data type field


Considering the SQL Server 'geography' data type...

I can enter an array of latitude and longitude (btw is that the correct order to do so or should it be longitude latitude?) points into the field as follows:

INSERT INTO SpatialZonePolygons (Coordinates)
VALUES (geography::STGeomFromText('POLYGON((-122.358 47.653 , -122.348 47.649, -122.348 47.658, -122.358 47.658, -122.358 47.653))', 4326));
GO

This then appears as:

0xE6100000010405000000DD24068195D34740F4FDD478E9965EC0508D976E12D3474083C0CAA145965EC04E62105839D4474083C0CAA145965EC04E62105839D44740F4FDD478E9965EC0DD24068195D34740F4FDD478E9965EC001000000020000000001000000FFFFFFFF0000000003

How do I select them back into their latitude and longitude formats?


Solution

  • Select convert(varchar(max),Coordinates) as Coordinates from SpatialZonePolygons ;
    

    take a look here for more information - SQL Server Geography Data Type