Skip to content

Commit

Permalink
update crop examples
Browse files Browse the repository at this point in the history
  • Loading branch information
atedstone committed Jan 18, 2024
1 parent 6fcd2a2 commit fd67028
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions examples/handling/georeferencing/crop_raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
# **First option:** using the vector as a reference to match, we reproject the raster. We simply have to pass the :class:`~geoutils.Vector`
# as single argument to :func:`~geoutils.Raster.crop`. See :ref:`core-match-ref` for more details.

rast.crop(vect)
rast.crop(vect, inplace=True)

# %%
# Now the bounds should be the same as that of the vector (within the size of a pixel as the grid was not warped).
Expand All @@ -46,7 +46,7 @@
# **Second option:** we can pass other ``crop_geom`` argument to :func:`~geoutils.Raster.crop`, including another :class:`~geoutils.Raster` or a
# simple :class:`tuple` of bounds. For instance, we can re-crop the raster to be smaller than the vector.

rast.crop((rast.bounds.left + 1000, rast.bounds.bottom, rast.bounds.right, rast.bounds.top - 500))
rast.crop((rast.bounds.left + 1000, rast.bounds.bottom, rast.bounds.right, rast.bounds.top - 500), inplace=True)

rast.show(ax="new", cmap="Purples")
vect.show(ref_crs=rast, fc="none", ec="k", lw=2)
6 changes: 4 additions & 2 deletions examples/handling/georeferencing/crop_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# **First option:** using the raster as a reference to match, we crop the vector. We simply have to pass the :class:`~geoutils.Raster` as single argument to
# :func:`~geoutils.Vector.crop`. See :ref:`core-match-ref` for more details.

vect.crop(rast)
vect.crop(rast, inplace=True)

# %%
# .. note::
Expand All @@ -47,7 +47,9 @@
# simple :class:`tuple` of bounds.

bounds = rast.get_bounds_projected(out_crs=vect.crs)
vect.crop(crop_geom=(bounds.left + 0.5 * (bounds.right - bounds.left), bounds.bottom, bounds.right, bounds.top))
vect.crop(
crop_geom=(bounds.left + 0.5 * (bounds.right - bounds.left), bounds.bottom, bounds.right, bounds.top), inplace=True
)

rast.show(ax="new", cmap="Greys_r", alpha=0.7)
vect.show(ref_crs=rast, fc="none", ec="tab:purple", lw=3)

0 comments on commit fd67028

Please sign in to comment.