Python 使顶部的geopandas DataFrame绘图与光栅绘图正确匹配

Python 使顶部的geopandas DataFrame绘图与光栅绘图正确匹配,python,matplotlib,geopandas,rasterio,Python,Matplotlib,Geopandas,Rasterio,我试图在同一个图的OSMap.tif文件顶部绘制Pumps.shp数据 我尝试使用rasterio.plot()和geopandas.plot()方法以及matplotlibs子图 问题是打印不匹配,光栅文件在轴的范围(01000)内打印,而shp在实际坐标范围内打印(x轴及其周围约50000) 两个对象中的CR相等,且坐标在同一范围内。为什么会这样?我做错了什么 这是我的密码 import rasterio as rast import rasterio.plot as rsplo

我试图在同一个图的OSMap.tif文件顶部绘制Pumps.shp数据

我尝试使用rasterio.plot()和geopandas.plot()方法以及matplotlibs子图

问题是打印不匹配,光栅文件在轴的范围(01000)内打印,而shp在实际坐标范围内打印(x轴及其周围约50000)

两个对象中的CR相等,且坐标在同一范围内。为什么会这样?我做错了什么

这是我的密码

   import rasterio as rast
   import rasterio.plot as rsplot
   import geopandas as gpd
   src=rast.open("OSMap.tif")
   data=gpd.read_file("Pumps.shp")
   fig,ax=plt.subplots()
   rsplot.show(src,ax=ax)
   data.plot(ax=ax)
   plt.show()
这是调用src.bounds的结果:

边界框(左=528765.0,下=180466.0,右=529934.0,上=181519.0)

这是数据的结果。边界

(528765.0180466.01529934.0181519.0)

这是两者的crs:


CRS({'lon_0':-2,'y_0':-100000,'k':0.9996012717,'lat_0':49,'proj':'tmerc','wktext':True,'datum':'OSGB36','no_defs':True,'x_0':400000,'units':'m')

我对
rasterio 0.36.0
也有同样的问题。我第一次尝试平移和缩放光栅,但更喜欢平移shapefile

我的代码如下所示:

import geopandas as gpd
import matplotlib.pyplot as plt
import rasterio

image = rasterio.open('input.tif') # with tgw world file
shapefile = gpd.read_file('input.shp')

# coordinates and scaling factors
scale_x = image.transform[1]
scale_y = image.transform[5]
x0 = image.transform[0]
y0 = image.transform[3]

# translates back shapefile
shapefile.geometry = shapefile.translate(-x0, -y0)
shapefile.geometry = shapefile.scale(-1.0/scale_x, -1.0/scale_y, origin=(0, 0, 0))

# plots both elements
fig, ax = plt.subplots()
ax = rasterio.plot.show(image.read(), with_bounds=True, ax=ax)
shapefile.plot(ax=ax)

使用matplotlib imshow而不是光栅显示。将光栅边界作为imshow的“extent”参数传递。

我在链接到的页面上找不到两个输入文件。它位于第一个zip上,上面写着:一个zip文件,矢量数据作为shapefile@重要提示您使用的是什么版本的
rasterio
?并不是说这似乎特别可能是问题所在,而是
rasterio.plot.show
仅在0.32中开始使用光栅的范围。@jdmcbr我使用的是版本0.36