commit d7312f89a7219b81d46e963fbfe1c2a8da3ca2ce Author: jfwang Date: Thu Jan 11 15:39:54 2018 +0800 add project diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cf7bd3f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +bin/ +obj/ +packages/ \ No newline at end of file diff --git a/.vs/GPSConvert/v15/.suo b/.vs/GPSConvert/v15/.suo new file mode 100644 index 0000000..0276563 Binary files /dev/null and b/.vs/GPSConvert/v15/.suo differ diff --git a/.vs/GPSConvert/v15/sqlite3/storage.ide b/.vs/GPSConvert/v15/sqlite3/storage.ide new file mode 100644 index 0000000..9e08fb5 Binary files /dev/null and b/.vs/GPSConvert/v15/sqlite3/storage.ide differ diff --git a/.vs/config/applicationhost.config b/.vs/config/applicationhost.config new file mode 100644 index 0000000..b92437b --- /dev/null +++ b/.vs/config/applicationhost.config @@ -0,0 +1,1039 @@ + + + + + + + +
+
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ + +
+
+
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/GPSConvert.sln b/GPSConvert.sln new file mode 100644 index 0000000..5025faa --- /dev/null +++ b/GPSConvert.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26730.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GPSConvert", "GPSConvert\GPSConvert.csproj", "{04279795-9EE5-4D5F-919D-F691800BACE1}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {04279795-9EE5-4D5F-919D-F691800BACE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {04279795-9EE5-4D5F-919D-F691800BACE1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {04279795-9EE5-4D5F-919D-F691800BACE1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {04279795-9EE5-4D5F-919D-F691800BACE1}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {52A57F2C-C03E-484D-B2F8-4DD9F53E5A35} + EndGlobalSection +EndGlobal diff --git a/GPSConvert/GPSConvert.ashx b/GPSConvert/GPSConvert.ashx new file mode 100644 index 0000000..f1a001a --- /dev/null +++ b/GPSConvert/GPSConvert.ashx @@ -0,0 +1 @@ +<%@ WebHandler Language="C#" CodeBehind="GPSConvert.ashx.cs" Class="GPSConvert.GPSConvert" %> diff --git a/GPSConvert/GPSConvert.ashx.cs b/GPSConvert/GPSConvert.ashx.cs new file mode 100644 index 0000000..53818ef --- /dev/null +++ b/GPSConvert/GPSConvert.ashx.cs @@ -0,0 +1,268 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace GPSConvert +{ + /// + /// GPSConvert 的摘要说明 + /// + public class GPSConvert : IHttpHandler + { + + public void ProcessRequest(HttpContext context) + { + + //DFMGps g = new DFMGps() { lng = "104.03.40.95", lat = "30.39.46.04" }; + //Gps g = new Gps() { lng = 104.0613755710, lat = 30.6627876858 };//谷歌地球 + //Gps g = new Gps() { lng = 104.0638732910, lat = 30.660359565 };//腾讯高德 + //Gps g = new Gps() { lng = 104.0703438917, lat = 30.6664848935 };//百度 + Gps g = new Gps(); + GpsConvert gs; + int _gt = 0; + //0:谷歌地球,1:腾讯高德,2:百度 + if (int.TryParse(context.Request["t"], out _gt)) + ; + try + { + string[] _g = context.Request["g"].Split(','); + if (double.TryParse(_g[0], out g.lng) && double.TryParse(_g[1], out g.lat)) + gs = new GpsConvert(g, (GpsType)_gt); + else + gs = new GpsConvert(new DFMGps() { lng = _g[0], lat = _g[1] }); + context.Response.ContentType = "text/plain"; + context.Response.Write(JsonConvert.SerializeObject(gs)); + context.Response.End(); + } + catch (Exception) + { + + throw new Exception("invaild parameter"); + } + + + } + + public bool IsReusable + { + get + { + return false; + } + } + + + + //WGS-84,GCJ-02,BD-09 + public class Gps + { + + public double lng;//经度 + public double lat;//纬度 + } + //度分秒格式坐标 + public class DFMGps + { + + public string lng;//经度 + public string lat;//纬度 + } + + public enum GpsType + { + + Wgs84 = 0, + Gcj02 = 1, + Bd09 = 2 + }; + + public class GpsConvert + { + + + public DFMGps _dfm = new DFMGps(); //度分秒坐标 + public Gps Wgs84 = new Gps(); //WGS-84 + public Gps Gcj02 = new Gps();//GCJ-02 中国坐标偏移标准 Google Map、高德、腾讯使用 + public Gps Bd09 = new Gps();//BD-09 百度坐标偏移标准,Baidu Map使用 + private double PI = Math.PI; + private double xPI = Math.PI * 3000.0 / 180.0; + + + + public GpsConvert(DFMGps _v) + { + _dfm = _v; + DfmToWgs84(); + Wgs84ToGcj02(); + Gcj02ToBd09(); + } + public GpsConvert(Gps _v, GpsType type) + { + if (type == GpsType.Wgs84) + { + Wgs84 = _v; + Wgs84ToDfm(); + Wgs84ToGcj02(); + Gcj02ToBd09(); + } + else if (type == GpsType.Gcj02) + { + Gcj02 = _v; + Gcj02ToWgs84(); + Wgs84ToDfm(); + Gcj02ToBd09(); + } + else if (type == GpsType.Bd09) + { + Bd09 = _v; + Bd09ToGcj02(); + Gcj02ToWgs84(); + Wgs84ToDfm(); + } + } + + private Gps delta(Gps t) + { + var a = 6378245.0; // a: 卫星椭球坐标投影到平面地图坐标系的投影因子。 + var ee = 0.00669342162296594323; // ee: 椭球的偏心率。 + var dLat = this.transformLat(t.lng - 105.0, t.lat - 35.0); + var dLng = this.transformLng(t.lng - 105.0, t.lat - 35.0); + var radLat = t.lat / 180.0 * PI; + var magic = Math.Sin(radLat); + magic = 1 - ee * magic * magic; + var sqrtMagic = Math.Sqrt(magic); + return new Gps() { lat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * PI), lng = (dLng * 180.0) / (a / sqrtMagic * Math.Cos(radLat) * PI) }; + } + + + //WGS-84 to GCJ-02 + private void Wgs84ToGcj02() + { + if (Wgs84 == null || this.outOfChina(Wgs84)) + Gcj02 = Wgs84; + var t = this.delta(Wgs84); + Gcj02.lng = t.lng + Wgs84.lng; + Gcj02.lat = t.lat + Wgs84.lat; + } + + //GCJ-02 to WGS-84 + private void Gcj02ToWgs84() + { + if (Gcj02 == null || this.outOfChina(Gcj02)) + Wgs84 = Gcj02; + var t = this.delta(Gcj02); + Wgs84.lng = Gcj02.lng - t.lng; + Wgs84.lat = Gcj02.lat - t.lat; + } + + //GCJ-02 to BD-09 + private void Gcj02ToBd09() + { + double x = Gcj02.lng; + double y = Gcj02.lat; + double z = Math.Sqrt(x * x + y * y) + 0.00002 * Math.Sin(y * xPI); + double theta = Math.Atan2(y, x) + 0.000003 * Math.Cos(x * xPI); + Bd09.lng = z * Math.Cos(theta) + 0.0065; + Bd09.lat = z * Math.Sin(theta) + 0.006; + } + //BD-09 to GCJ-02 + private void Bd09ToGcj02() + { + double x = Bd09.lng - 0.0065; + double y = Bd09.lat - 0.006; + double z = Math.Sqrt(x * x + y * y) - 0.00002 * Math.Sin(y * xPI); + double theta = Math.Atan2(y, x) - 0.000003 * Math.Cos(x * xPI); + Gcj02.lng = z * Math.Cos(theta); + Gcj02.lat = z * Math.Sin(theta); + } + + //WGS-84 to 度分秒坐标 + private void Wgs84ToDfm() + { + _dfm.lng = TranDegreeToDMs(Wgs84.lng); + _dfm.lat = TranDegreeToDMs(Wgs84.lat); + } + + + //度分秒坐标 to WGS-84 + private void DfmToWgs84() + { + Wgs84.lng = TranDMsToDegree(_dfm.lng); + Wgs84.lat = TranDMsToDegree(_dfm.lat); + } + + + private double TranDMsToDegree(string _dms) + { + string[] dms = _dms.Split('.'); + if (dms.Length == 4) + return double.Parse(dms[0]) + double.Parse(dms[1]) / 60 + double.Parse(dms[2] + "." + dms[3] ?? "0") / 3600; + else if (dms.Length == 3) + return double.Parse(dms[0]) + double.Parse(dms[1]) / 60 + double.Parse(dms[2]) / 3600; + else if (dms.Length == 2) + return double.Parse(_dms); + else + return 0d; + + } + + + private static string TranDegreeToDMs(double d) + { + int Degree = Convert.ToInt16(Math.Truncate(d));//度 + d = d - Degree; + int M = Convert.ToInt16(Math.Truncate((d) * 60));//分 + int S = Convert.ToInt16(Math.Round((d * 60 - M) * 60)); + if (S == 60) + { + M = M + 1; + S = 0; + } + if (M == 60) + { + M = 0; + Degree = Degree + 1; + } + string rstr = Degree.ToString() + "."; + if (M < 10) + rstr = rstr + "0" + M.ToString(); + else + rstr = rstr + M.ToString(); + if (S < 10) + rstr = rstr + "0" + S.ToString(); + else + rstr = rstr + S.ToString(); + return rstr; + } + + private bool outOfChina(Gps _t) + { + if (_t.lng < 72.004 || _t.lng > 137.8347) + return true; + if (_t.lat < 0.8293 || _t.lat > 55.8271) + return true; + return false; + } + + private double transformLat(double x, double y) + { + double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.Sqrt(Math.Abs(x)); + ret += (20.0 * Math.Sin(6.0 * x * PI) + 20.0 * Math.Sin(2.0 * x * PI)) * 2.0 / 3.0; + ret += (20.0 * Math.Sin(y * PI) + 40.0 * Math.Sin(y / 3.0 * PI)) * 2.0 / 3.0; + ret += (160.0 * Math.Sin(y / 12.0 * PI) + 320 * Math.Sin(y * PI / 30.0)) * 2.0 / 3.0; + return ret; + } + + private double transformLng(double x, double y) + { + double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.Sqrt(Math.Abs(x)); + ret += (20.0 * Math.Sin(6.0 * x * PI) + 20.0 * Math.Sin(2.0 * x * PI)) * 2.0 / 3.0; + ret += (20.0 * Math.Sin(x * PI) + 40.0 * Math.Sin(x / 3.0 * PI)) * 2.0 / 3.0; + ret += (150.0 * Math.Sin(x / 12.0 * PI) + 300.0 * Math.Sin(x / 30.0 * PI)) * 2.0 / 3.0; + return ret; + } + } + } +} \ No newline at end of file diff --git a/GPSConvert/GPSConvert.csproj b/GPSConvert/GPSConvert.csproj new file mode 100644 index 0000000..1b9bebf --- /dev/null +++ b/GPSConvert/GPSConvert.csproj @@ -0,0 +1,130 @@ + + + + + + Debug + AnyCPU + + + 2.0 + {04279795-9EE5-4D5F-919D-F691800BACE1} + {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + GPSConvert + GPSConvert + v4.6.1 + true + + + + + + + + + + + true + full + false + bin\ + DEBUG;TRACE + prompt + 4 + + + true + pdbonly + true + bin\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.5\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll + + + + False + ..\..\NGAReptile\jfwang.NGAReptile\bin\Debug\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + + + + + + Web.config + + + Web.config + + + + + + + + GPSConvert.ashx + + + + + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + + + + + True + True + 60977 + / + http://localhost:60977/ + False + False + + + False + + + + + + + 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 + + + + + + \ No newline at end of file diff --git a/GPSConvert/GPSConvert.csproj.user b/GPSConvert/GPSConvert.csproj.user new file mode 100644 index 0000000..11da173 --- /dev/null +++ b/GPSConvert/GPSConvert.csproj.user @@ -0,0 +1,37 @@ + + + + true + + + + + + + + + + + + + + CurrentPage + True + False + False + False + + + + + + + + + True + True + + + + + \ No newline at end of file diff --git a/GPSConvert/Properties/AssemblyInfo.cs b/GPSConvert/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..af22876 --- /dev/null +++ b/GPSConvert/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过下列特性集 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("GPSConvert")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("GPSConvert")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +// 对 COM 组件不可见。如果需要 +// 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID +[assembly: Guid("04279795-9ee5-4d5f-919d-f691800bace1")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 内部版本号 +// 修订版本 +// +// 可以指定所有值,也可以使用“修订号”和“内部版本号”的默认值, +// 方法是按如下所示使用 "*": +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/GPSConvert/Web.Debug.config b/GPSConvert/Web.Debug.config new file mode 100644 index 0000000..b9a9fde --- /dev/null +++ b/GPSConvert/Web.Debug.config @@ -0,0 +1,31 @@ + + + + + + + + + + \ No newline at end of file diff --git a/GPSConvert/Web.Release.config b/GPSConvert/Web.Release.config new file mode 100644 index 0000000..755e745 --- /dev/null +++ b/GPSConvert/Web.Release.config @@ -0,0 +1,32 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/GPSConvert/Web.config b/GPSConvert/Web.config new file mode 100644 index 0000000..05cf607 --- /dev/null +++ b/GPSConvert/Web.config @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/GPSConvert/packages.config b/GPSConvert/packages.config new file mode 100644 index 0000000..3c85c3a --- /dev/null +++ b/GPSConvert/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file