Rasterization¶
In [37]:
Copied!
from rasvec import rasterize_by_raster
import rasterio as rio
from rasterio.plot import show
import matplotlib.pyplot as plt
import geopandas as gpd
from rasvec import rasterize_by_raster
import rasterio as rio
from rasterio.plot import show
import matplotlib.pyplot as plt
import geopandas as gpd
In [67]:
Copied!
raster_path = 'sample_data/raster/ras.tif'
vector_path = 'sample_data/vector/vec_buffer/buffer.shp'
output='output.tif'
raster_path = 'sample_data/raster/ras.tif'
vector_path = 'sample_data/vector/vec_buffer/buffer.shp'
output='output.tif'
In [68]:
Copied!
ras = rio.open(raster_path)
vec = gpd.read_file(vector_path)
ras = rio.open(raster_path)
vec = gpd.read_file(vector_path)
In [69]:
Copied!
fig, ax = plt.subplots()
show(ras, ax=ax)
vec.plot(ax=ax, facecolor='none', edgecolor='red')
plt.axis('off')
plt.tight_layout()
fig, ax = plt.subplots()
show(ras, ax=ax)
vec.plot(ax=ax, facecolor='none', edgecolor='red')
plt.axis('off')
plt.tight_layout()
In [73]:
Copied!
rasterize_by_raster(raster_path=raster_path, vector_path=vector_path, output_path=output)
rasterize_by_raster(raster_path=raster_path, vector_path=vector_path, output_path=output)
In [72]:
Copied!
rasterized = rio.open(output)
show(rasterized, cmap='grey')
rasterized = rio.open(output)
show(rasterized, cmap='grey')
Out[72]:
<Axes: >