Using geometry with srid 4326, what unit does STDistance return?
So here's my setup:
I have a table for example:
Id, Lat, Long, GeoPoint, GeomPoint
both GeoPoint
(geography) and GeomPoint
(geometry) are set in SRID 4326
I have the following request:
DECLARE @radiiCollection TABLE
( [ID] INT IDENTITY(1, 1) PRIMARY KEY,
[Radius] GEOMETRY,
[RefPoint] GEOMETRY,
[RefAddr] VARCHAR(255),
[MinLat] VARCHAR(255),
[MaxLat] VARCHAR(255),
[MinLng] VARCHAR(255),
[MaxLng] VARCHAR(255))
DECLARE @point GEOMETRY = geometry::Point(-111.84493459999999, 33.3902569, 4326)
DECLARE @gpoint GEOGRAPHY = geography::Point(33.3902569, -111.84493459999999, 4326);
INSERT INTO @radiicollection
(radius,
refpoint,
refaddr,
maxlat,
maxlng,
minlat,
minlng)
VALUES ( @point.MakeValid().STBuffer(16093.40),
@point,
'10 miles of 85210',
33.51734689767781,
-111.6923852740045,
33.26298081643247,
-111.99703818130439 )
SELECT
GeomPoint,
GeoPoint
INTO #temp
FROM (
SELECT row_number() OVER (
PARTITION BY [ds].[ADDR],
[ds].[APT],
[ds].[ZIP] ORDER BY [ds].[IND_ID] ASC
) recid1, rGeop1.geompoint, rgeop1.GeoPoint
FROM [r].[main] ds
JOIN [r].[GeoPoint] rGeoP1
ON rGeoP1.[UID] = ds.[UID]
JOIN @radiiCollection rr
ON GeomPoint.STWithin(rr.radius) = 1
WHERE 1 = 1
AND (
(
(
(
try_cast(latitude AS DECIMAL(9, 1)) BETWEEN CONVERT(DECIMAL(9, 1), 33.26298081643247)
AND CONVERT(DECIMAL(9, 1), 33.51734689767781)
AND try_cast(longitude AS DECIMAL(9, 1)) BETWEEN CONVERT(DECIMAL(9, 1), - 111.99703818130439)
AND CONVERT(DECIMAL(9, 1), - 111.6923852740045)
)
)
)
)
) f
WHERE recid1 = 1
So by pulling both, I then pull out the STDistance for both GeoPoint and GeomPoint like so:
select top 10
try_cast(GeoPoint.STDistance(@gpoint) as float) DistanceGeo,
try_cast(GeoMPoint.STDistance(@point.MakeValid()) as float) DistanceGeom
from #temp
but what i get is a little weird:
DistanceGeo DistanceGeom
-----------------------------------------
10495.1674191715 0.111544285781801
10249.4175883919 0.100540150724826
12307.1907929483 0.1262738924781
11804.655587608 0.116453906202276
10249.4175883919 0.100540150724826
9607.03640753812 0.101614826463312
11130.8413059431 0.100596791997409
10249.4175883919 0.100540150724826
6973.69243171186 0.0644901191669685
9605.88647121359 0.0967178499759486
From what I understand, SRID defines the unit of measure for a spatial column, but obviously, since they are both SRID 4326, is that not the case? Any help would be greatly appreciated. I believe I see degrees here instead of meters. Is there an easy way in SQL to convert degrees to meters? Or a way to change what STDistance uses for output?
source to share
Geometry assumes a flat map, geography assumes the shape of the earth. Remember that the distance between landforms and longitudes depends on where you are on the globe (at the North Pole, the distance between longitudes is close to 0).
If you want to spot big differences, add some more extreme examples to your code ... pick a point near the north pole and another a few degrees. Compare this to two points on the equator ... Geometric distance and geography distance are two very different terms
source to share