Geometry column: STGeomFromText and SRID (what is an SRID?)

前端 未结 5 1109
被撕碎了的回忆
被撕碎了的回忆 2020-12-15 03:53

I\'m playing with the new geography column in SQL Server 2008 and the STGeomFromText function. Here is my code (works with AdventureWorks2008)

DECLARE @regi         


        
5条回答
  •  时光取名叫无心
    2020-12-15 04:22

    The distance returned depends on the "Spatial Reference Identifier (SRID)" you define for your geography types.

    In the example below, the default SRID of 4336 is used, see the second argument of STGeomFromText. This means the distance returned is in meters, you find this via querying the catalog view spatial_reference_systems i.e. select srs.unit_of_measure from sys.spatial_reference_systems as srs where srs.spatial_reference_id = 4326

    As an alternative to STGeomFromText, you can use parse which assumes a SRID of 4326 and you don't have to specify one explicitly.

    When calculating the distance between two points, you must use the same SRID for both geography types else you get an error. Example:

    DECLARE @address1 GEOGRAPHY
    DECLARE @address2 GEOGRAPHY
    DECLARE @distance float
    SET @address1 = GEOGRAPHY::STGeomFromText ('point(53.046908 -2.991673)',4326)
    SET @address2 = GEOGRAPHY::STGeomFromText ('point(51.500152 -0.126236)',4326)
    SET @distance = @address1.STDistance(@address2)
    SELECT @distance --this is the distance in meters
    

提交回复
热议问题