• okbangas (9/20/2014)


    I've searched a bit, and from what I can see, both Geometry and Gography stores the coordinates as IEEE 754 64-bit float internally, hence there is no difference in precision... Please review the following code:

    DECLARE @geo geography;

    SET @geo = geography::Point(1.234567890123456789, 1.234567890123456789, 4326)

    SELECT @geo.ToString();

    go

    DECLARE @geo geometry;

    SET @geo = geometry::Point(1.234567890123456789, 1.234567890123456789, 4326)

    SELECT @geo.ToString();

    go

    Both select statements return the same:

    POINT (1.2345678901234567 1.2345678901234567)

    The two data types are identical in structure and numerical accuracy, the difference is the actual meaning of the data stored within each type, one can think of geometry as a position and geography as a location. Inspecting the hexadecimal representation of the two:

    DECLARE @geo1 geography;

    DECLARE @geo2 geometry;

    SET @geo1 = geography::Point(1.234567890123456789, 1.234567890123456789, 4326)

    SET @geo2 = geometry::Point(1.234567890123456789, 1.234567890123456789, 4326)

    SELECT CONVERT(VARBINARY(64),@geo1,3) AS GEO_BIN UNION ALL

    SELECT CONVERT(VARBINARY(64),@geo2,3);

    shows that the two are identical

    GEO_BIN

    -----------------------------------------------

    0xE6100000010CFB598C42CAC0F33FFB598C42CAC0F33F

    0xE6100000010CFB598C42CAC0F33FFB598C42CAC0F33F

    Although the SRID is set in both instances, the geometry data type will ignore it which renders it useless for geographical coordinates. Consider the following example:

    DECLARE @GEOGR01 GEOGRAPHY = GEOGRAPHY::Point(50,0,4326);

    DECLARE @GEOGR02 GEOGRAPHY = GEOGRAPHY::Point(51,0,4326);

    DECLARE @GEOM01 GEOMETRY = GEOMETRY::Point(50,0,4326);

    DECLARE @GEOM02 GEOMETRY = GEOMETRY::Point(51,0,4326);

    SELECT @GEOGR01.STDistance(@GEOGR02) AS P_DISTANCE UNION ALL

    SELECT @GEOM01.STDistance(@GEOM02);

    Results

    P_DISTANCE

    ----------------------

    111238.680801466

    1

    The geography returns the distance but the geometry returns the difference between the two x values of the coordinates.

    😎