Extracting latitude and longitude from the SQL geometry data type

If that title is confusing, let me explain what this post is about: Extracting latitude and longitude from the SQL geometry data type.

SELECT PlaceName, geometry::STGeomFromText(CONVERT(nvarchar(50),geo), 0).STX,
geometry::STGeomFromText(CONVERT(nvarchar(50),geo), 0).STY
FROM Location
WHERE PlaceName ‘Dulles International Airport’

So I convert the Geometry field in my database (the field name is “geo”, like the “Team Umizoomi” character) to an nvarchar. With that done, I call the STGeomFromText function, a built-in procedure for the geometry data type. And the final step is to call the STX (for latitude) and STY (for longitude).

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: