I'm looking for the MSSQL equivalent of the following mySQL statement:
SELECT Y(location) as Lat, X(location) as Lon from myTable;
I want to get the X and Y values of my geography I have stored as a geography data type.
I know STAsText(Location) as Location
will give me the WKT... i just need the X and Y number values.
The geography spatial data type, geography, is implemented as a . NET common language runtime (CLR) data type in SQL Server. This type represents data in a round-earth coordinate system. The SQL Server geography data type stores ellipsoidal (round-earth) data, such as GPS latitude and longitude coordinates.
p. precision you should use DECIMAL . Latitudes range from -90 to +90 (degrees), so DECIMAL(10,8) is ok for that, but longitudes range from -180 to +180 (degrees) so you need DECIMAL(11,8) .
You can use STDistance like this. DECLARE @g geography; DECLARE @h geography; SET @g = geography::STGeomFromText('POINT(-122.35900 47.65129)', 4326); SET @h = geography::STGeomFromText('POINT(-122.34720 47.65100)', 4326); SELECT @g. STDistance(@h);
For GEOGRAPHY:
SELECT location.Lat as Lat, location.Long as Lon from myTable;
For GEOMETRY:
SELECT location.STY as Lat, location.STX as Lon from myTable;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With