Reputation: 482
I'm trying to import an .asc file in python to clip it with a shapefile. For the clipping I'll use:
import earthpy.clip as cl
clip = cl.clip_shp(shp_file, asc_file)
However this won't work since my .asc doesn't have a CRS. This is how the header of the .asc looks like:
ncols 1900
nrows 1400
xllcorner 182900
yllcorner 326300
cellsize 10
NODATA_value -999.990
This is how I import the .asc file
import rasterio as rio
asc_loc = r'file.asc'
raster = rio.open(asc_loc)
print(raster.crs)
The print shows none
Question: how can I add a the CRS to an imported .asc file? (Preferably with rastario or geopandas.)
Upvotes: 3
Views: 2457
Reputation: 2196
To add a CRS to a raster
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)
If that doesn't work, and since the CRS will never be saved to an asc.file,
better use gdal_translate first, from the command line, to convert to Geotiff, before using the raster with rasterio
:
gdal_translate -of "GTiff" -a_srs EPSG:19914 in.asc out.tif
Upvotes: 3