15

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?

Litisqe Kumar
  • 2,512
  • 4
  • 26
  • 40
ChrisCurrie
  • 1,589
  • 6
  • 15
  • 36

2 Answers2

21

You may use something like this(SQL SERVER)

SELECT Coordinates.Lat 'Latitude', Coordinates.Long 'Longitude' FROM SpatialZonePolygons 

For more information - How To Get Lat-Long From Geography Data Type

Litisqe Kumar
  • 2,512
  • 4
  • 26
  • 40
18
Select convert(varchar(max),Coordinates) as Coordinates from SpatialZonePolygons ;

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

Hardik Vinzava
  • 968
  • 10
  • 22