Double or decimal for latitude / longitude values ​​in C #

What is the best data type for storing geolocation data in C #? I would use decimal precision for it, but operations with decimal floating-point numbers are slower than binary floating-point numbers (double).

I read that most of the time you will no longer need 6 or 7 digits of accuracy for latitude or longitude. Does fuzziness of doubles even matter or can be ignored?

+43
c # latitude-longitude
Jan 21 '15 at 13:12
source share
3 answers

Go twice, there are several reasons.

  • Trigonometric Functions Available Only for Doubles
  • The precision of the double is far superior to anything you will ever need for Lat / Lon values.
  • Third-party modules (e.g. DotSpatial ) also use double for coordinates
+57
Jan 22 '15 at 16:13
source share
β€” -

The double has up to 15 decimal digits of accuracy. So, suppose that three of these digits will be to the left of the decimal point for lat / long values ​​(max. 180deg). This leaves 12 digits of precision on the right. Since the lat / long degree is ~ 111 km, 5 of these 12 digits will give accuracy to the counter. Another 3 digits would give millimeter accuracy. The remaining 4 digits will get an accuracy of up to about 100 nanometers. Since double will win in terms of performance and memory, I see no reason to even consider using decimal numbers.

+18
Jan 21 '15 at
source share

I came across this question recently when I started with spatial programming. Some time ago I read a book that led me to this.

//sql server has a really cool dll that deals with spacial data such like //geography points and so on. //add this namespace Using Microsoft.SqlServer.Types; 

//SqlGeography.Point(dblLat, dblLon, srid)

 var lat_lon_point = Microsoft.SqlServer.Types.SqlGeography.Point(lat, lon, 4326); 

This is the best way to work with your spatial space. then to save data use this in sql

 CREATE TABLE myGeoTable { LatLonPoint GEOMETRY } 

else if you use something else that isnt sql just convert the dot to hex and save it. After a long time, I know that this is the safest.

+3
Jan 21 '15 at 13:36
source share



All Articles