为了账号安全,请及时绑定邮箱和手机立即绑定

将纬度/经度点转换为墨卡托投影上的像素(x,y)

将纬度/经度点转换为墨卡托投影上的像素(x,y)

摇曳的蔷薇 2019-08-09 17:25:00
将纬度/经度点转换为墨卡托投影上的像素(x,y)我正在尝试将纬度/长点转换为2d点,以便我可以将它显示在世界的图像上 - 这是一个墨卡托投影。我已经看到了各种方法来做这个以及关于堆栈溢出的一些问题 - 我尝试了不同的代码片段,虽然我得到了像素的正确经度,但纬度总是偏离 - 似乎变得更加合理。我需要公式来考虑图像大小,宽度等。我试过这段代码:double minLat = -85.05112878;double minLong = -180;double maxLat = 85.05112878;double maxLong = 180;// Map image size (in points)double mapHeight = 768.0;double mapWidth = 991.0;// Determine the map scale (points per degree)double xScale = mapWidth/ (maxLong - minLong);double yScale = mapHeight / (maxLat - minLat);// position of map image for pointdouble x = (lon - minLong) * xScale;double y = - (lat + minLat) * yScale;System.out.println("final coords: " + x + " " + y);在我尝试的例子中,纬度似乎偏差约30px。任何帮助或建议?更新基于这个问题:Lat / lon到xy我试图使用提供的代码,但我仍然有一些纬度转换的问题,经度很好。int mapWidth = 991;int mapHeight = 768;double mapLonLeft = -180;double mapLonRight = 180;double mapLonDelta = mapLonRight - mapLonLeft;double mapLatBottom = -85.05112878;double mapLatBottomDegree = mapLatBottom * Math.PI / 180;double worldMapWidth = ((mapWidth / mapLonDelta) * 360) / (2 * Math.PI);double mapOffsetY = (worldMapWidth / 2 * Math.log((1 + Math.sin(mapLatBottomDegree)) / (1 - Math.sin(mapLatBottomDegree))));double x = (lon - mapLonLeft) * (mapWidth / mapLonDelta);double y = 0.1;if (lat < 0) {    lat = lat * Math.PI / 180;    y = mapHeight - ((worldMapWidth / 2 * Math.log((1 + Math.sin(lat)) / (1 - Math.sin(lat)))) - mapOffsetY);} else if (lat > 0) {    lat = lat * Math.PI / 180;    lat = lat * -1;    y = mapHeight - ((worldMapWidth / 2 * Math.log((1 + Math.sin(lat)) / (1 - Math.sin(lat)))) - mapOffsetY);    System.out.println("y before minus: " + y);    y = mapHeight - y;} else {    y = mapHeight / 2;}System.out.println(x);System.out.println(y);当使用原始代码时,如果纬度值为正,则返回负点,因此我稍微修改了它并用极端纬度测试 - 应该是点0和点766,它工作正常。然而,当我尝试不同的纬度值ex:58.07(在英国北部)时,它显示为西班牙北部。
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 1873 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号