Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double or decimal for latitude/longitude values in C#

What is the best data type to use when storing geopositional data in C#? I would use decimal for its exactness, but operations on decimal floating point numbers are slower then binary floating point numbers (double).

I read that most of the time you won't need any more than 6 or 7 digits of precision for latitude or longitude. Does the inexactness of doubles even matter then or can it be ignored?

like image 564
KRTac Avatar asked Jan 21 '15 13:01

KRTac


People also ask

Should latitude be float or double?

you will not have to do any rounding on your longitude or latitude values, so use whichever one you want. Double is more precise, so let that be the most important factor in your decision.

Can latitude and longitude have decimals?

Decimal degrees (DD) express latitude and longitude geographic coordinates as decimal fractions and are used in many Geographic Information Systems (GIS), web mapping applications such as Google Maps, and GPS devices. Decimal degrees are an alternative to using degrees, minutes, and seconds (DMS).

How many decimal places should latitude and longitude be?

Longitude and latitude coordinates are stored with 15 decimal digits right of the decimal points.

Which property returns the longitude as a decimal number?

The GeolocationCoordinates interface's read-only longitude property is a double-precision floating point value which represents the longitude of a geographical position, specified in decimal degrees.


1 Answers

Go for double, there are several reasons.

  • Trigonometric functions are available only for double
  • Precision of double (range of 100 nanometers) is far beyond anything you'll ever require for Lat/Lon values
  • GeoCoordinate Class and third-Party modules (e.g. DotSpatial) also use double for coordinates
like image 134
Wernfried Domscheit Avatar answered Sep 19 '22 21:09

Wernfried Domscheit