我正在尝试在python中导入.asc文件,以用shapefile对其进行剪辑。对于剪辑,我将使用:
import earthpy.clip as cl
clip = cl.clip_shp(shp_file, asc_file)
但是,由于我的.asc没有CRS,因此无法使用。 .asc的标题如下所示:
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
问题:如何从导入的.asc文件添加或更改CRS? (最好使用rastario或geopandas。)
向栅格添加CRS
.prj
如果不起作用,并且由于CRS永远不会保存到asc。file,
最好先在命令行中使用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)
,然后再将栅格与gdal_translate结合使用,以转换为Geotiff:
rasterio