randy
randy

Reputation: 275

What is the unit of measure for the distance of BufferWithTolerance in sql 2008

I found this link Create a SqlGeography polygon-circle from a center and radius

which says it is meters. This also shows meters on my system.

SELECT * FROM sys.spatial_reference_systems where spatial_reference_id = 4326;

However, when I create a circle using this code, the resulting circle has a radius of about 27 miles when I plot it using google maps api and manually measure the distance, so something is definitely off. It should be 1/2 a meter and it's actually 27 miles.

DECLARE @g geometry;
SET @g = geometry::STGeomFromText('POINT(-88.0 44.5)', 4326);
select @g.BufferWithTolerance(.5,.01,1)

-Randy

Upvotes: 1

Views: 1811

Answers (2)

Liesel
Liesel

Reputation: 2979

If you have a look at the well_known_text col in sys.spatial_reference_systems you'll see the unit for 4326 is degrees. This is the unit used for describing the location of points etc. and distance in a planar system. The unit_of_measure column is the units used for distance between points and areas when using ellipsoidal types.

So, you're using Geometry (the SQL planar type) which uses the WKT unit. If you were to be using Geography (the SQL ellipsoidal type) then the unit_of_measure is used for distances etc.

You can see this in these examples:

Geometry

DECLARE @g geometry;
DECLARE @g2 geometry;
SET @g = geometry::STGeomFromText('POINT(-88.0 44.5)', 4326);
SET @g2 = geometry::STGeomFromText('POINT(-88.0 44.0)', 4326);
SELECT @g.STDistance(@g2)

0.5

(Distance in degrees)

Geography

DECLARE @g geography;
DECLARE @g2 geography;
SET @g = geography::STGeomFromText('POINT(-88.0 44.5)', 4326);
SET @g2 = geography::STGeomFromText('POINT(-88.0 44.0)', 4326);
SELECT @g.STDistance(@g2)

55558.5621458782

(Distance in metres)

https://msdn.microsoft.com/en-us/library/bb964711.aspx#differences

Upvotes: 4

MortenSickel
MortenSickel

Reputation: 2200

The unit will be the same as the unit of the coordinate system i.e degrees if you use geographical coordinates, meters if you use UTM or feet if you use some of the american projections.

Upvotes: 2

Related Questions