您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

python – 使用Cartopy在地图上显示图像时的投影问题

5b51 2022/1/14 8:20:43 python 字数 5361 阅读 491 来源 www.jb51.cc/python

我有一些我想用Cartopy显示的卫星图像数据.我已成功按照图像示例详细介绍了here.导致此代码:import numpy as np import matplotlib.pyplot as plt import cartopy.crs as ccrs fig = plt.figure(figsize=(12, 12)) img_extent = (-7

概述

我有一些我想用cartopy显示的卫星图像数据.我已成功按照图像示例详细介绍了here.导致此代码

import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs

fig = plt.figure(figsize=(12,12))
img_extent = (-77,-59,9,26)

ax = plt.axes(projection=ccrs.PlateCarree())
# image data coming from server,code not shown
ax.imshow(img,origin='upper',extent=img_extent)
ax.set_xmargin(0.05)
ax.set_ymargin(0.10)

# mark a kNown place to help us geo-locate ourselves
ax.plot(-117.1625,32.715,'bo',markersize=7)
ax.text(-117,33,'San Diego')

ax.coastlines()
ax.gridlines()

plt.show() 

代码生成以下图像

我的问题是卫星图像数据不在PlateCarree投影中,而是墨卡托投影.

但是当我得到轴对象时

ax = plt.axes(projection=ccrs.Mercator())

我失去了海岸线.

我看到了here报告的问题.但是

ax.set_global()

得到这张图片的结果:

数据不存在,圣地亚哥位置错误.纬度/经度范围也发生了变化.我究竟做错了什么?

发布讨论更新

主要问题是我没有使用transform_points方法在目标投影中正确指定图像范围.我还必须具体说明菲尔建议的imshow方法中的坐标参考系统.这是正确的代码

import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs

proj = ccrs.Mercator()
fig = plt.figure(figsize=(12,12))
extents = proj.transform_points(ccrs.Geodetic(),np.array([-77,-59]),np.array([9,26]))

img_extents = (extents[0][0],extents[1][0],extents[0][6],extents[1][7] ) 

ax = plt.axes(projection=proj)
# image data coming from server,extent=img_extents,transform=proj)

ax.set_xmargin(0.05)
ax.set_ymargin(0.10)

# mark a kNown place to help us geo-locate ourselves
ax.plot(-117.1625,markersize=7,transform=ccrs.Geodetic())
ax.text(-117,'San Diego',transform=ccrs.Geodetic())

ax.coastlines()
ax.gridlines()

plt.show() 

导致这个正确地理投影的卫星图像:

所以在你的情况下,plt.imshow应该有一个transform = ccrs.Mercator()关键字参数(你可能需要一个更具体的参数化墨卡托实例).如果您的范围是大地测量(拉特和长子),则必须将边界框转换为墨卡托坐标,但除此之外,其他所有区域都应按预期工作.

注意:我将去更新example以包含变换参数;-)(PR:https://github.com/SciTools/cartopy/pull/343)

HTH

总结

以上是编程之家为你收集整理的python – 使用Cartopy在地图上显示图像时的投影问题全部内容,希望文章能够帮你解决python – 使用Cartopy在地图上显示图像时的投影问题所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶