js坐标转换WGS84(大地坐标系BLH)转空间直角坐标系XYZ
重新编辑我
点击查看详细内容
// 坐标转换 WGS84经纬度 => 大地坐标系BLH XYZ
var pi_180 = Math.PI / 180;
var _180_pi = 180 / Math.PI;
var projectionTypes = {};
projectionTypes.bj54 = {
a:6378245,//长半轴
e2:0.006693421622966//第一偏心率平方
};
projectionTypes.wgs84 = {
a:6378135,//长半轴
e2:0.00669437999013//第一偏心率平方
};
var myparams = {
dx : 31.4,
dy : -144.3,
dz : -74.8,
rx : 0,
ry : 0,
rz : 0.814,
m : -0.38
};
function _BLH2XYZ(blhObj){//将大地坐标喜欢换为空间直角坐标系
// var e2 = projectionTypes[projectionType].e2;//第一偏心率平方值
var e2 = 0.00669437999013;
// var a = projectionTypes[projectionType].a;//长半轴
var a=6378135;//长半轴
var N = a / Math.sqrt(1 - e2 * Math.sin(blhObj.b * pi_180) * Math.sin(blhObj.b * pi_180));
var X = (N + blhObj.h) * Math.cos(blhObj.b * pi_180) * Math.cos(blhObj.l * pi_180);
var Y = (N + blhObj.h) * Math.cos(blhObj.b * pi_180) * Math.sin(blhObj.l * pi_180);
var Z = [N * (1 - e2 ) + blhObj.h] * Math.sin(blhObj.b * pi_180);
var resultObj = {};
resultObj.X = X;
resultObj.Y = Y;
resultObj.Z = Z;
return resultObj;
}
var polygonPoints =
[
[118.22166324000011,33.94018013200008],
[118.22166694800001,33.940138392000051],
[118.22167282000009,33.940096924000045],
[118.22168107000005,33.940055637000057],
[118.22170407500005,33.939955487000077],
[118.2217123260001,33.939914291000036],
[118.22171830600007,33.93987282300003],
[118.22172190500009,33.939831083000058],
[118.22175552400006,33.939267271000062],
[118.22175661300003,33.939258077000034],
[118.22544694300007,33.939262686000063],
[118.22536301900004,33.940659324000023],
[118.2216439660001,33.940503869000054],
[118.22166324000011,33.94018013200008]
];
var newPolygonsArray = [];
var arrlen = polygonPoints.length;
console.log(111,arrlen)
for(var i = 0;i<arrlen;i++){
// console.log(polygonPoints[i])
var temp = polygonPoints[i].push(0);
var blhobj = {b:polygonPoints[i][0],l:polygonPoints[i][1],h:polygonPoints[i][2]};
var xyz = _BLH2XYZ(blhobj);
var litarr = [xyz.X,xyz.Y];
newPolygonsArray.push(litarr);
}
console.log("WWWWWWWWW",newPolygonsArray)
for(let i=0;i<newPolygonsArray.length;i++){
console.log(newPolygonsArray[i])
}
// 结果
// [-2508762.3877196563, -1688373.3218629]
// [-2508763.9197682994, -1688371.6975169708]
// [-2508765.620088954, -1688370.2037195012]
// [-2508767.508796714, -1688368.8482179488]
// [-2508772.3340561124, -1688365.7242519162]
// [-2508774.2201614925, -1688364.3727831203]
// [-2508775.929276027, -1688362.8848971743]
// [-2508777.4524383997, -1688361.2545638504]
// [-2508796.8051914386, -1688338.4102690013]
// [-2508797.1648267615, -1688338.0673958578]
// [-2509097.6557210106, -1688540.581141801]
// [-2509049.6587237557, -1688597.1412485857]
// [-2508751.277772253, -1688386.4403409816]
// [-2508762.3877196563, -1688373.3218629]