Mapbox 在平铺中查找世界/地理坐标的像素坐标
我试图用它来获取空间中特定点的高程。我使用Mapbox 在平铺中查找世界/地理坐标的像素坐标,mapbox,gis,geospatial,mercator,Mapbox,Gis,Geospatial,Mercator,我试图用它来获取空间中特定点的高程。我使用mercantile.tile获取包含我在缩放级别15处的点的tile的坐标,-43º,-22º(为简单起见)为1245418527,然后mercantile.xy获取相应的世界坐标:-4806237.7150042495,-2621281.225786047 -4806237.7150042495/256(磁贴大小)的整数部分不应该等于包含该点的磁贴的x坐标,即12454?如果这个计算结果正确,我想我在寻找对应于结果小数部分的像素列(x轴),就像124
mercantile.tile
获取包含我在缩放级别15处的点的tile的坐标,-43º,-22º
(为简单起见)为1245418527
,然后mercantile.xy
获取相应的世界坐标:-4806237.7150042495,-2621281.225786047
-4806237.7150042495/256
(磁贴大小)的整数部分不应该等于包含该点的磁贴的x坐标,即12454
?如果这个计算结果正确,我想我在寻找对应于结果小数部分的像素列(x轴),就像12454,5的127列(256*0,5)。然而,除法的结果是-18774.366(奇怪的是,它很接近瓷砖y坐标,但看起来像是巧合)。我错过了什么
作为替代方案,我考虑使用
mercantile.bounds
,将第一个和最后一个像素列指定给最西和最东的经度,并通过插值找到我的位置,但我想检查我的方法是否正确/推荐。我对点高程感兴趣,所以这里所说的一切也都是关于Y轴的。以下是我到目前为止得到的:
def correct_altitude_mode(kml):
with open(kml, "r+") as f:
txt = f.read()
if re.search("(?<=<altitudeMode>)relative(?=<\/altitudeMode>)", txt):
lat = round(float(find_with_re("latitude", txt)), 5)
lng = round(float(find_with_re("longitude", txt)), 5)
alt = round(float(find_with_re("altitude", txt)), 5)
z = 15
tile = mercantile.tile(lng, lat, z)
westmost, southmost, eastmost, northmost = mercantile.bounds(tile)
pixel_column = np.interp(lng, [westmost, eastmost], [0,256])
pixel_row = np.interp(lat, [southmost, northmost], [256, 0])
response = requests.get(f"https://api.mapbox.com/v4/mapbox.terrain-rgb/{z}/{tile.x}/{tile.y}.pngraw?access_token=pk.eyJ1IjoibWFydGltcGFzc29zIiwiYSI6ImNra3pmN2QxajBiYWUycW55N3E1dG1tcTEifQ.JFKSI85oP7M2gbeUTaUfQQ")
buffer = BytesIO(response.content)
tile_img = png.read_png_int(buffer)
_,R,G,B = (tile_img[int(pixel_row), int(pixel_column)])
print(tile_img[int(pixel_row), int(pixel_column)])
height = -10000 + ((R * 256 * 256 + G * 256 + B) * 0.1)
print(f"R:{R},G:{G},B:{B}\n{height}")
plt.hlines(pixel_row, 0.0, 256.0, colors="r")
plt.vlines(pixel_column, 0.0, 256.0, colors="r")
plt.imshow(tile_img)
def正确高度模式(kml):
开放式(kml,“r+”)为f:
txt=f.read()
如果重新搜索(“(?我只是认为我所说的一切都适用于缩放级别0,因为我假设像素坐标=世界坐标。880163m似乎不是地球上任何一点的合理高度