对于proj4js库和大多数与地理空间相关的东西来说都是非常新的,所以我对所有的命名约定和不同类型的坐标系都很熟悉。
本质上,我试图从多边形中获取一组UTM经纬度坐标,并将它们转换为WGS84,以便在military grid reference system中获得相应的区域。
我试过了
const corrdinates = [ [ [ -1.5321158470515384, 52.34135509678963 ],
[ 0.0777579252987236, 52.310366914514184 ],
[ 0.01125412258311688, 51.324523354307196 ],
[ -1.5638793748853044, 51.354439389788006 ],
[ -1.5321158470515384, 52.34135509678963 ] ] ]
function latLngToMgrsUtmZones(coords) {
try {
coords[0] = coords[0].map((p) =>
proj4(
"WGS84",
`utm`,
p
)
);
console.log('coords', coords);
} catch (err) {
console.log(err);
}
}
latLngToMgrsUtmZones(coordinates);但这只会返回utm。我认为只需要将投影名称传递给proj4js,它就会对其进行转换。
如何使用这个库来做这件事呢?
发布于 2021-07-09 10:31:39
根据你的坐标列表,UTM区域是31。UTM区域proj4定义字符串将是:-
"+proj=utm +zone=31 +datum=WGS84 +units=m +no_defs"你可以定义一个新的'proj4‘定义,如下所示:
// add a definition of a UTM zone
proj4.defs("EPSG:32631","+proj=utm +zone=31 +datum=WGS84 +units=m +no_defs");然后,麻烦的函数可以更新为:
function latLngToMgrsUtmZones(coords) {
try {
coords[0] = coords[0].map((p) =>
proj4(
"WGS84",
"EPSG:32631",
p
)
);
console.log('coords', coords);
} catch (err) {
console.log("ERR: "+err);
}
}如果你运行
latLngToMgrsUtmZones(coordinates);你会得到:-
coords: [
[
[ 191321.4903300695, 5808679.516222329 ],
[ 300798.59040295583, 5799580.45321534 ],
[ 291767.8812803207, 5690155.850511101 ],
[ 182274.43537953158, 5699133.648491979 ],
[ 191321.4903300695, 5808679.516222329 ]
]
]https://stackoverflow.com/questions/66798747
复制相似问题