Double or decimal for latitude/longitude values in C#

前端 未结 4 1569
臣服心动
臣服心动 2020-12-24 04:02

What is the best data type to use when storing geopositional data in C#? I would use decimal for it\'s exactness, but operations on decimal floating point numbers are slower

4条回答
  •  我在风中等你
    2020-12-24 04:59

    I faced this question quite a while ago when i started with spacial programming. I read a book a while ago 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 when working in your application with spacial data. then to save the data use this in sql

    CREATE TABLE myGeoTable
    {
    LatLonPoint GEOMETRY 
    }
    

    else, if you are using something else that isnt sql just convert the point to hexadecimal and store it. I know after a long time using spacial that this is the safest.

提交回复
热议问题