Rasterize shapefiles#

Importing the necessary packages:

import matplotlib.pyplot as plt

import imod

Get the example shapes

temp_dir = imod.util.temporary_directory()
lakes = imod.data.lakes_shp(temp_dir)

We’ll need a dummy grid which we will use as a reference for for rasterizing the shapefile. We are just going to create one with the convenience function.

xmin = 90950.0
xmax = 115650.0
dx = 100

ymin = 445850.0
ymax = 467550.0
dy = -100.0

like_2d = imod.util.empty_2d(dx, xmin, xmax, dy, ymin, ymax)

Rasterrize the shapes

lake_grid = imod.prepare.rasterize(lakes, like=like_2d)

# Plot
fig, ax = plt.subplots()
lake_grid.plot.imshow(ax=ax)
dx = 100.0, dy = -100.0
<matplotlib.image.AxesImage object at 0x00000289B6033550>

To rasterize on a different grid, create a dummy grid

dx_coarse = 200
dy_coarse = -200
like_2d_coarse = imod.util.empty_2d(dx_coarse, xmin, xmax, dy_coarse, ymin, ymax)

lake_grid_coarse = imod.prepare.rasterize(lakes, like=like_2d_coarse)

# Plot
fig, ax = plt.subplots()
lake_grid_coarse.plot.imshow(ax=ax)
dx = 200.0, dy = -200.0
<matplotlib.image.AxesImage object at 0x00000289B31A1CD0>

Total running time of the script: (0 minutes 0.703 seconds)

Gallery generated by Sphinx-Gallery