I use the Rasterio to cut out roofs of buildings, roofs are polygons. I would like to set up crs of felled roofs. Is it possible to do that by Rasterio?
I can set up crs of layer, layer.crs = 'epsg:2180', but how can I do that for raster file?
My code to cutting out roofs of buildings:
def cutting_out(df, start, end):
for index, row in df.iloc[start:end].iterrows():
if len(row['1_5000_pi025']) == 1:
#1url
coo = shapely.wkt.loads(row['geometry'])
multiplier = int(row['liczba_kon'])
coo_buffer = coo.buffer(3 * multiplier)
lokalnyid = row['lokalnyid']
tiff = str(row['1_5000_pi025'][0])
with rasterio.open(f'/mnt/qnap/geo_tiff_1_5000_p025/{tiff}') as src:
out_image, out_transform = rasterio.mask.mask(src, [coo_buffer], crop=True)
out_meta = src.meta
out_meta.update(
{
"driver": "GTiff",
"height": out_image.shape[1],
"width": out_image.shape[2],
"transform": out_transform,
}
)
with rasterio.open(f'/mnt/qnap/geo_tiff_roofs_testy3/{lokalnyid}'+'_025'+'.tif', "w", **out_meta) as dest:
dest.write(out_image)
src.crs
is notNone
it will automatically get written todest.crs
, ifsrc.crs
isNone
and you know it isepsg:2180
, just add"crs": "epsg:2180"
toout_meta.update