1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > 经纬度坐标转换高斯-克吕格平面坐标

经纬度坐标转换高斯-克吕格平面坐标

时间:2019-10-20 18:37:31

相关推荐

经纬度坐标转换高斯-克吕格平面坐标

文章目录

前言主要代码使用示例参考链接

原作者链接:/jianyi7659/article/details/7583339

前言

支持将地理坐标(经纬度坐标)转换到高斯-克吕格投影下的平面坐标,如北京54平面坐标、西安80平面坐标、大地2000平面坐标。

主要代码

代码已经封装成了dojo模块(类),方便在使用ArcGIS JS API时引用该坐标转换模块。

LatLong2GaussKruger.js

/*** WGS-84椭球经纬度坐标转高斯-克吕格平面坐标*/define(["dojo/_base/declare"], function (declare) {return declare(null, {//基本变量定义a: 0,//'椭球体长半轴b: 0,// '椭球体短半轴f: 0, //'扁率e: 0,// '第一偏心率e: 0, //'第二偏心率FE: 0,//'东偏移FN: 0,//'北偏移L0: 0,//'中央经度W0: 0,//'原点纬线k0: 0,//'比例因子// PI: 3.14159265358979,/*** 用于初始化椭球参数* @param {*} TuoqiuCanshu 枚举类型,提供北京54、西安80、WGS84、CGCS2000椭球参数* @param {*} CentralMeridian 中央经线* @param {*} OriginLatitude 原点纬度,如果是标准的分幅,则该参数是0* @param {*} EastOffset 东偏移* @param {*} NorthOffset 北偏移*/constructor: function (TuoqiuCanshu, CentralMeridian, OriginLatitude, EastOffset, NorthOffset) {/** Canshu* Beijing54 = 0;Krassovsky (北京54采用) 6378245 6356863.0188Xian80 = 1;IAG 75(西安80采用) 6378140 6356755.2882WGS84 = 2;WGS 84 6378137 6356752.3142CGCS2000 = 3*/if (TuoqiuCanshu == 0)//北京五四{a = 6378245;b = 6356863.0188;}if (TuoqiuCanshu == 1)// '西安八零{a = 6378140;b = 6356755.2882;}if (TuoqiuCanshu == 2)//'WGS84{a = 6378137;b = 6356752.3142;}if (TuoqiuCanshu == 3)//'CGCS2000{a = 6378137;b = 6356752.314140356;}f = (a - b) / a;//扁率//e = Math.sqrt(1 - Math.pow((b / a) ,2));//'第一偏心率e = Math.sqrt(2 * f - Math.pow(f, 2));//'第一偏心率//eq = Math.sqrt(Math.pow((a / b) , 2) - 1);//'第二偏心率e1 = e / Math.sqrt(1 - Math.pow(e, 2));//'第二偏心率L0 = CentralMeridian;//中央经W0 = OriginLatitude;//原点纬线k0 = 1;//'比例因子FE = EastOffset;//东偏移FN = NorthOffset;//北偏移},/*** 经纬度转高斯-克吕格平面坐标* @param {*} J 经度* @param {*} W 维度*/JWgetGK: function (J, W) {//'给出经纬度坐标,转换为高克投影坐标var resultP = {};var BR = (W - W0) * Math.PI / 180;//纬度弧长var lo = (J - L0) * Math.PI / 180; //经差弧度var N = a / Math.sqrt(1 - Math.pow((e * Math.sin(BR)), 2)) //卯酉圈曲率半径//求解参数svar B0;var B2;var B4;var B6;var B8;var C = Math.pow(a, 2) / b;B0 = 1 - 3 * Math.pow(e1, 2) / 4 + 45 * Math.pow(e1, 4) / 64 - 175 * Math.pow(e1, 6) / 256 + 11025 * Math.pow(e1, 8) / 16384;B2 = B0 - 1B4 = 15 / 32 * Math.pow(e1, 4) - 175 / 384 * Math.pow(e1, 6) + 3675 / 8192 * Math.pow(e1, 8);B6 = 0 - 35 / 96 * Math.pow(e1, 6) + 735 / 2048 * Math.pow(e1, 8);B8 = 315 / 1024 * Math.pow(e1, 8);s = C * (B0 * BR + Math.sin(BR) * (B2 * Math.cos(BR) + B4 * Math.pow((Math.cos(BR)), 3) + B6 * Math.pow((Math.cos(BR)), 5) + B8 * Math.pow((Math.cos(BR)), 7)));var t = Math.tan(BR);var g = e1 * Math.cos(BR);var XR = s + Math.pow(lo, 2) / 2 * N * Math.sin(BR) * Math.cos(BR) + Math.pow(lo, 4) * N * Math.sin(BR) * Math.pow((Math.cos(BR)), 3) / 24 * (5 - Math.pow(t, 2) + 9 * Math.pow(g, 2) + 4 * Math.pow(g, 4)) + Math.pow(lo, 6) * N * Math.sin(BR) * Math.pow((Math.cos(BR)), 5) * (61 - 58 * Math.pow(t, 2) + Math.pow(t, 4)) / 720;var YR = lo * N * Math.cos(BR) + Math.pow(lo, 3) * N / 6 * Math.pow((Math.cos(BR)), 3) * (1 - Math.pow(t, 2) + Math.pow(g, 2)) + Math.pow(lo, 5) * N / 120 * Math.pow((Math.cos(BR)), 5) * (5 - 18 * Math.pow(t, 2) + Math.pow(t, 4) + 14 * Math.pow(g, 2) - 58 * Math.pow(g, 2) * Math.pow(t, 2));resultP.x = YR + FE;resultP.y = XR + FN;return resultP;},/*** 高斯-克吕格平面转经纬度坐标* @param {*} X * @param {*} Y */GKgetJW: function (X, Y) {//'给出高克投影坐标,转换为经纬度坐标var resultP = {};var El1 = (1 - Math.sqrt(1 - Math.pow(e, 2))) / (1 + Math.sqrt(1 - Math.pow(e, 2)));var Mf = (Y - FN) / k0;//真实坐标值var Q = Mf / (a * (1 - Math.pow(e, 2) / 4 - 3 * Math.pow(e, 4) / 64 - 5 * Math.pow(e, 6) / 256));//角度Bf = Q + (3 * El1 / 2 - 27 * Math.pow(El1, 3) / 32) * Math.sin(2 * Q) + (21 * Math.pow(El1, 2) / 16 - 55 * Math.pow(El1, 4) / 32) * Math.sin(4 * Q) + (151 * Math.pow(El1, 3) / 96) * Math.sin(6 * Q) + 1097 / 512 * Math.pow(El1, 4) * Math.sin(8 * Q);Rf = a * (1 - Math.pow(e, 2)) / Math.sqrt(Math.pow((1 - Math.pow((e * Math.sin(Bf)), 2)), 3));Nf = a / Math.sqrt(1 - Math.pow((e * Math.sin(Bf)), 2));//卯酉圈曲率半径Tf = Math.pow((Math.tan(Bf)), 2);D = (X - FE) / (k0 * Nf);Cf = Math.pow(e1, 2) * Math.pow((Math.cos(Bf)), 2);var B = Bf - Nf * Math.tan(Bf) / Rf * (Math.pow(D, 2) / 2 - (5 + 3 * Tf + 10 * Cf - 9 * Tf * Cf - 4 * Math.pow(Cf, 2) - 9 * Math.pow(e1, 2)) * Math.pow(D, 4) / 24 + (61 + 90 * Tf + 45 * Math.pow(Tf, 2) - 256 * Math.pow(e1, 2) - 3 * Math.pow(Cf, 2)) * Math.pow(D, 6) / 720);var L = CentralMeridian * Math.PI / 180 + 1 / Math.cos(Bf) * (D - (1 + 2 * Tf + Cf) * Math.pow(D, 3) / 6 + (5 - 2 * Cf + 28 * Tf - 3 * Math.pow(Cf, 2) + 8 * Math.pow(e1, 2) + 24 * Math.pow(Tf, 2)) * Math.pow(D, 5) / 120);var Bangle = B * 180 / Math.PI;var Langle = L * 180 / Math.PI;resultP.x = Langle;//RW * 180 / Math.PI;resultP.y = Bangle + W0;//RJ * 180 / Math.PI;return resultP;}});});

使用示例

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>坐标转换模块</title><link rel="stylesheet" href="/4.11/esri/themes/light/main.css" /></head><style>html,body,#viewDiv {height: 100%;width: 100%;margin: 0;padding: 0;}.horizontal-toolbar{position: absolute;top: 30px;right: 75px;/* width: 100px; */height: 50px;overflow: hidden;background-color: white;border-radius: 4px;z-index: 100;}.horizontal-toolbar>li{position: relative;margin: 5px;list-style: none; float: left;width: 46px;height: 46px;}</style><script>var package_path = window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/'));//var package_path = window.location.pathname.replace(/\/[^\/]*$/,"");var dojoConfig = {packages: [{name: "modules",location: package_path + '/modules'}]};</script><script src="/4.12/"></script><script>var map,measureTool;require(["modules/LatLong2GaussKruger","esri/Map","esri/views/MapView","esri/config"], function (LatLong2GaussKruger, Map, MapView, esriConfig) {const map = new Map({basemap: "streets",});const view = new MapView({container: "viewDiv",map: map,zoom: 5,center: [90, 45]});convertTool = new LatLong2GaussKruger(3,114,0,500000,0);});function convert () {console.log("经纬度坐标:113.554688,22.25256")let coord = convertTool.JWgetGK(113.554688,22.25256);console.log("转换后:" + coord.x + "," + coord.y);}</script><body><div id="viewDiv" style="position:relative;"><ul class="horizontal-toolbar"><li onclick="convert()">坐标转换</li></ul></div></body></html>

经过与ArcGIS Server的几何服务投影功能的结果对比,结果<0.0001

参考链接

/jianyi7659/article/details/7583339

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。