簡體   English   中英

ValueError:輸入形狀不與柵格重疊。 Geopandas/Rasterio,屏蔽時可能出現 CRS 錯誤

[英]ValueError: Input shapes do not overlap raster. Geopandas/Rasterio, possible CRS error when masking

我正在使用這個數據集: https://sedac.ciesin.columbia.edu/data/set/gpw-v4-population-density-rev11/data-download (世界網格化人口密度)

有了這個 map: https://data.humdata.org/dataset/uganda-administrative-boundaries-as-of-17-08-2018 (烏干達行政邊界 shapefile)

我已將烏干達 map 剪裁到我需要的區域,如下所示:

shape_records = uganda.shapeRecords()
desired_shapes = []

for s in shape_records:
    for x in s.record:
        if 'FORT PORTAL' in str(x):
            desired_shapes.append(s)

將它們加載到單個 geopandas dataframe 中:

forgpd=[]
for x in desired_shapes:
    forgpd.append(x.__geo_interface__)

gdf = gpd.GeoDataFrame.from_features(forgpd, crs=4326)

然后我正在閱讀帶有rasterio.tif世界人口文件。

gpw = rio.open('UgandaData/gpw_v4_population_density_rev11_2020_30_sec.tif')
gpw_region = gpw.read(1, window=gpw.window(*box))

我想裁剪它,使用這個:

from rasterio import mask as msk

region_mask, region_mask_tf = msk.mask(dataset=gpw, shapes=gdf.geometry, all_touched=True, filled=True, crop=True) #error here
region_mask = np.where(region_mask < 0, 0, region_mask).squeeze()

我收到以下錯誤:

WindowError: windows do not intersect
ValueError: Input shapes do not overlap raster.

這是我的crs:

Gridded population of world: CRS.from_epsg(4326)

Uganda(Fort Portal) : 
<Geographic 2D CRS: EPSG:4326>
Name: WGS 84
Axis Info [ellipsoidal]:
- Lat[north]: Geodetic latitude (degree)
- Lon[east]: Geodetic longitude (degree)
Area of Use:
- name: World
- bounds: (-180.0, -90.0, 180.0, 90.0)
Datum: World Geodetic System 1984
- Ellipsoid: WGS 84
- Prime Meridian: Greenwich

不同之處在於我沒有為網格化的世界人口指定 WGS 84 嗎? 如果是這樣,這是如何指定的?

問題是 shapefile 在 UTM 坐標中,而柵格是世界坐標系(緯度/經度)。 即使您將epsg:4326 crs 分配給gdf ,它的坐標仍在 UTM 中。 您可以像這樣手動轉換這些。

否則,您可以使用 QGIS 將世界柵格重新投影到EPSG:21096 (基於烏干達 shapefile 中的 UTM 區域的估計),或者您可以使用gdalwarp

更改光柵上的投影后,代碼的 rest 工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM