我正在尝试在 python 中导入 .asc 文件以使用 shapefile 对其进行剪辑。对于剪辑,我将使用:
import earthpy.clip as cl
clip = cl.clip_shp(shp_file, asc_file)
但是这不起作用,因为我的 .asc 没有 CRS。 .asc 的 header 如下所示:
ncols 1900
nrows 1400
xllcorner 182900
yllcorner 326300
cellsize 10
NODATA_value -999.990
这就是我导入 .asc 文件的方式
import rasterio as rio
asc_loc = r'file.asc'
raster = rio.open(asc_loc)
print(raster.crs)
打印显示none
问题:如何将 CRS 添加到导入的 .asc 文件中? (最好使用 rastario 或 geopandas。)
最佳答案
将 CRS 添加到栅格
import rasterio.crs
crs = rasterio.crs.CRS({"init": "epsg:19914"})
with rasterio.open('/path/to/file.format') as src:
src.crs = crs
print (src.crs)
如果这不起作用,并且由于 CRS 永远不会保存到 asc.file,
更好地使用gdal_translate首先,从命令行转换为 Geotiff,然后再将栅格与 rasterio
一起使用:
gdal_translate -of "GTiff" -a_srs EPSG:19914 in.asc out.tif
关于python - 添加投影导入的 .asc 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58749115/