国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

[C#]利用糾偏數據來處理地球坐標(WGS-84)與火星坐標(GCJ-02)轉換

2019-11-14 16:18:03
字體:
來源:轉載
供稿:網友

關鍵代碼:

using System;using System.Collections;using System.Collections.Generic;using System.IO;using YanZhiwei.DotNet2.Utilities.Models;namespace YanZhiwei.DotNet2.Utilities.Common{    /// <summary>    /// 地圖糾偏數據幫助類    /// </summary>    public class MapOffsetDataHelper    {        #region 構造函數以及變量        PRivate string offsetFullPath = string.Empty;        /// <summary>        /// 構造函數        /// </summary>        /// <param name="path">糾偏數據文件路徑</param>        public MapOffsetDataHelper(string path)        {            offsetFullPath = path;        }        #endregion        #region 私有方法        private void GetOffsetData(Action<MapCoord> mapCoordHanlder)        {            using (FileStream stream = new FileStream(offsetFullPath, FileMode.OpenOrCreate, Fileaccess.Read))            {                using (BinaryReader reader = new BinaryReader(stream))                {                    int _size = (int)stream.Length / 8;                    for (int i = 0; i < _size; i++)                    {                        byte[] _source = reader.ReadBytes(8);                        MapCoord _coord = ToCoord(_source);                        mapCoordHanlder(_coord);                    }                }            }        }        /// <summary>        /// 將字節轉化為具體的數據對象        /// </summary>        /// <param name="bytes">bytes</param>        /// <returns>MapCoord</returns>        private MapCoord ToCoord(byte[] bytes)        {            //經度,緯度,x偏移量,y偏移量 【均兩個字節】            MapCoord _coord = new MapCoord();            byte[] _b1 = new byte[2], _b2 = new byte[2], _b3 = new byte[2], _b4 = new byte[2];            Array.Copy(bytes, 0, _b1, 0, 2);            Array.Copy(bytes, 2, _b2, 0, 2);            Array.Copy(bytes, 4, _b3, 0, 2);            Array.Copy(bytes, 6, _b4, 0, 2);            _coord.Lon = BitConverter.ToInt16(_b1, 0);            _coord.Lat = BitConverter.ToInt16(_b2, 0);            _coord.X_off = BitConverter.ToInt16(_b3, 0);            _coord.Y_off = BitConverter.ToInt16(_b4, 0);            return _coord;        }        #endregion         #region 獲取糾偏數據集合        /// <summary>        /// 獲取糾偏數據集合        /// </summary>        /// <returns>糾偏數據集合</returns>        public List<MapCoord> GetMapCoordList()        {            List<MapCoord> _mapCoordList = new List<MapCoord>();            GetOffsetData(c => _mapCoordList.Add(c));            return _mapCoordList;        }        /// <summary>        /// 獲取糾偏數據集合        /// </summary>        /// <returns>糾偏數據集合</returns>        public ArrayList GetMapCoordArrayList()        {            ArrayList _mapCoordArrayList = new ArrayList();            GetOffsetData(c => _mapCoordArrayList.Add(c));            return _mapCoordArrayList;        }        #endregion    }}

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

using System.Collections;using YanZhiwei.DotNet2.Utilities.Models;using YanZhiwei.DotNet2.Utilities.Tool;namespace YanZhiwei.DotNet2.Utilities.Common{    /// <summary>    /// 地圖糾偏 幫助類    /// </summary>    public class MapOffsetHelper    {        /*         *參考:         *1.http://www.apkbus.com/forum.php?mod=viewthread&tid=137621&extra=page%3D1&page=1         *2.http://yanue.net/post-122.html         *3.http://go2log.com/2011/08/30/%E4%B8%AD%E5%9B%BD%E5%9C%B0%E5%9B%BE%E5%81%8F%E7%A7%BB%E6%A0%A1%E6%AD%A3php%E7%AE%97%E6%B3%95/         *4.http://www.devdiv.com/ios_gps_google_-blog-60266-10835.html         */        #region 構造函數以及變量        private ArrayList mapCoordArrayList;        /// <summary>        /// 構造函數        /// </summary>        /// <param name="offsetData">糾偏數據</param>        public MapOffsetHelper(ArrayList offsetData)        {            mapCoordArrayList = offsetData;        }        #endregion        #region 私有方法        private MapCoord QueryOffSetData(LatLngPoint point)        {            MapCoord _search = new MapCoord();            _search.Lat = (int)(point.LatY * 100);            _search.Lon = (int)(point.LonX * 100);            MapOffsetComparer rc = new MapOffsetComparer();            int _findedIndex = mapCoordArrayList.BinarySearch(0, mapCoordArrayList.Count, _search, rc);            MapCoord _findedCoord = (MapCoord)mapCoordArrayList[_findedIndex];            return _findedCoord;        }        #endregion         #region 地球坐標(WGS-84)轉火星坐標 (GCJ-02)        /// <summary>        /// 地球坐標(WGS-84)轉火星坐標 (GCJ-02)        /// </summary>        /// <param name="wgsPoint">地球坐標(WGS-84)</param>        /// <returns>火星坐標 (GCJ-02)</returns>        public LatLngPoint WGS84ToGCJ02(LatLngPoint wgsPoint)        {            MapCoord _findedCoord = QueryOffSetData(wgsPoint);            double _pixY = MapHelper.LatToPixel(wgsPoint.LatY, 18);            double _pixX = MapHelper.LonToPixel(wgsPoint.LonX, 18);            _pixY += _findedCoord.Y_off;            _pixX += _findedCoord.X_off;            double _lat = MapHelper.PixelToLat(_pixY, 18);            double _lng = MapHelper.PixelToLon(_pixX, 18);            return new LatLngPoint(_lat, _lng);        }        #endregion        #region 火星坐標轉 (GCJ-02)地球坐標(WGS-84)        /// <summary>        /// 火星坐標轉 (GCJ-02)地球坐標(WGS-84)        /// </summary>        /// <param name="gcjPoint">火星坐標轉 (GCJ-02)</param>        /// <returns>地球坐標(WGS-84)</returns>        public LatLngPoint GCJ02ToWGS84(LatLngPoint gcjPoint)        {            MapCoord _findedCoord = QueryOffSetData(gcjPoint);            double _pixY = MapHelper.LatToPixel(gcjPoint.LatY, 18);            double _pixX = MapHelper.LonToPixel(gcjPoint.LonX, 18);            _pixY -= _findedCoord.Y_off;            _pixX -= _findedCoord.X_off;            double _lat = MapHelper.PixelToLat(_pixY, 18);            double _lng = MapHelper.PixelToLon(_pixX, 18);            return new LatLngPoint(_lat, _lng);        }        #endregion    }}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 鄂伦春自治旗| 阿合奇县| 微山县| 阿城市| 上杭县| 海盐县| 库尔勒市| 东明县| 天水市| 玛沁县| 临洮县| 沂南县| 峨山| 旺苍县| 谢通门县| 陵川县| 建湖县| 江源县| 鄂尔多斯市| 邓州市| 修水县| 汉沽区| 桐梓县| 营口市| 全州县| 南通市| 中山市| 通州区| 吴川市| 蒲江县| 赤城县| 罗源县| 荔浦县| 洪泽县| 介休市| 咸丰县| 清涧县| 孝昌县| 宜君县| 南岸区| 个旧市|