问题描述
我正在构建一个需要大量谷歌地图图像的项目.我将这些函数定义为在另一个将自动收集图像的函数中使用.纬度变化很好,但我注意到经度略有偏差.这是近似墨卡托投影方法的产物吗?我的印象是我使用的转换非常准确,除了接近极点.
I'm building a project requiring large amounts of google maps images. I defined these functions to be used in another function that will automatically collect images. The latitude changes nicely, but I've noticed the longitude is slightly off. Is that an artifact of the approximate Mercator projection method? I was under the impression that the conversion I've used was pretty accurate except on approaching the poles.
import math
import os
import DLMaps
#Finds the distance covered in a Static Maps image pixel
def PixDist(zoom,scale=2):
earthCirc = 40075.0 #in Km's
base = 256 #size of google maps at zoom = 0
return earthCirc/(base*scale*(2**zoom))
#Finds the Km distance to the next google static maps image based on size of images,
# and distance per pixel
def DistNextImage(distpp, scale=2, size=640):
return distpp*scale*size
#returns a new Lat, Lon co-ordinate given a starting point, km distance change and
# a NESW direction, values 1-4 being used to represent corresponding direction.
def NewLatLon(lat,lon, dist, direction):
if direction==1:
dist = dist/110.54 #approximate change in latitude mercator projection
lat = lat + dist #heading north
elif direction == 2:
dist = dist/(110.32 * math.cos(math.pi*lat/180.0)) #approx change in lon
lon = lon + dist
elif direction==3:
dist = dist/110.54 #approximate change in latitude mercator projection
lat = lat - dist #heading south
elif direction ==4:
dist = dist/(110.32 * math.cos(math.pi*lat/180.0)) #approx change in lon
lon = lon - dist
return lat, lon
推荐答案
地球不是真正的椭球体,坐标系统的数量很多,从一个系统到另一个系统的传递远非简单.您可以查看 pyproj 众所周知的 proj.4 库的 Python 接口,以便从经纬度(我假设 WGS84 ...)到几乎任何其他坐标,当然包括墨卡托.您可以尝试自己滚动,但有很多警告,例如不同的起源子午线,参考椭球的细微差异,您几乎没有希望获得正确和准确的结果.
The earth is not a true ellipsoid, there are a high number of coordinate systems, and passing from one system to another one is far from simple. You could have a look to pyproj a Python interface to the well known proj.4 library to convert from Lat-Lon (I assume WGS84 ...) to almost any other coordinate including of course Mercator. You could try to roll your own, but there are so many caveats such as different origin meridians, slight differences in reference ellipsoid, that you have little hope to have correct and accurate results.
但是您在 维基百科
这篇关于墨卡托投影略微偏离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!