我尝试使用python中的shape或geojson文件剪辑tiff文件。剪切图像的代码是-
from datetime import date
import geopandas as gpd
import rasterio
import rasterio.features
import rasterio.warp
from shapely.geometry import MultiPolygon, Polygon
import subprocess
import matplotlib.pyplot as plt
import geopandas as gpd
from rasterio.mask import mask
nReserve = gpd.read_file('poly.shp')
# the polygon GeoJSON geometry
nReserve_proj = nReserve.to_crs({'init': 'epsg:32643'})
with rasterio.open("RGBNew.tiff") as src:
out_image, out_transform = rasterio.mask.mask(src, nReserve_proj.geometry,crop=True)
out_meta = src.meta.copy()
out_meta.update({"driver": "GTiff",
"height": out_image.shape[1],
"width": out_image.shape[2],
"transform": out_transform})
with rasterio.open("RGB_masked.tif", "w", **out_meta) as dest:
dest.write(out_image)
创建上述使用的形状文件的代码是-
^{pr2}$但我得到了一个错误-
File "tryWithNewEPSG.py", line 24, in out_image, out_transform = mask(src, geoms, crop=True) File "/home/ubuntu/.local/lib/python2.7/site-packages/rasterio/mask.py", line 181, in mask pad=pad) File "/home/ubuntu/.local/lib/python2.7/site-packages/rasterio/mask.py", line 87, in raster_geometry_mask raise ValueError('Input shapes do not overlap raster.') ValueError: Input shapes do not overlap raster.
我正在用代码检查epsg-
import rasterio
with rasterio.open('NDVI.tif') as src:
print (src.crs)
我甚至试过把两者的epsg都改为4326,但还是没用。在
out_image, out_transform = rasterio.mask.mask(src, nReserve_proj.geometry,crop=True)
out_meta = src.meta.copy()
out_meta.update({"driver": "GTiff",
"height": out_image.shape[1],
问题在于创建形状文件的方法;请使用以下代码创建形状文件-
在坐标中提及坐标;确保要剪裁的tiff具有爱普生:4326您可以使用转换代码-
^{pr2}$在哪里NDVIData.tiff文件是我最初的口角蒂芙是我和新epsg 4326的新口角。在
现在尝试运行剪辑代码
相关问题 更多 >
编程相关推荐