Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Spatial Data Type Precision Question

Author  Topic 

Danger44
Starting Member

2 Posts

Posted - 2011-03-01 : 23:58:16
Hello.

I was reading up the geography data type, and everything I have read states that the latitude and longitude values are stored as floats. That is cool and all, but when I run this code, it suggests differently. Why is the lng and lat values from the geography object rounded down to just a few decimal places? Am I doing something stupid here?

DECLARE @lng decimal(18,15) = -117.098121455566
DECLARE @lat decimal(18,15) = 33.6023416376439

DECLARE @g geography = geography::STGeomFromText('POINT(' + CAST(@lng as Varchar(50)) + ' ' + CAST(@lat as varchar(50)) + ')', 4326)


print 'decimal '
print CAST(@lng as Varchar(50))

print 'geography'
print @g.Long

OUTPUT:
decimal
-117.098121455566000
geography
-117.098


Thanks in advance.

Danger44
Starting Member

2 Posts

Posted - 2011-03-03 : 19:51:23
Figured it out.

Don't use 'print' to output the Lat and Long values from the geography object. It gets truncated.

In addition, when inserting geography data types into a table, don't use floats as the lat and lng values. Use a decimal(18,15) if you want hardcore accuracy. For some reason floats get truncated once in the geography object.
Go to Top of Page
   

- Advertisement -