Note
Go to the end to download the full example code.
Reproject a vector#
This example demonstrates the reprojection of a vector using geoutils.Vector.reproject()
.
We open a raster and vector.
import geoutils as gu
filename_rast = gu.examples.get_path("everest_landsat_b4_cropped")
filename_vect = gu.examples.get_path("everest_rgi_outlines")
rast = gu.Raster(filename_rast)
vect = gu.Vector(filename_vect)
The two objects are in different projections.
Driver: GTiff
Opened from file: /home/docs/checkouts/readthedocs.org/user_builds/geoutils/checkouts/stable/examples/data/Everest_Landsat/LE71400412000304SGS00_B4_cropped.tif
Filename: /home/docs/checkouts/readthedocs.org/user_builds/geoutils/checkouts/stable/examples/data/Everest_Landsat/LE71400412000304SGS00_B4_cropped.tif
Loaded? False
Modified since load? False
Grid size: 492, 315
Number of bands: 1
Data types: uint8
Coordinate system: ['EPSG:32645']
Nodata value: None
Pixel interpretation: Area
Pixel size: 30.0, 30.0
Upper left corner: 483430.0, 3093260.0
Lower right corner: 498190.0, 3102710.0
Filename: /home/docs/checkouts/readthedocs.org/user_builds/geoutils/checkouts/stable/examples/data/Everest_Landsat/15_rgi60_glacier_outlines.gpkg
Coordinate system: EPSG:4326
Extent: [86.70393205700003, 27.847778695000045, 87.11409458600008, 28.14549759700003]
Number of features: 86
Attributes: ['RGIId', 'GLIMSId', 'BgnDate', 'EndDate', 'CenLon', 'CenLat', 'O1Region', 'O2Region', 'Area', 'Zmin', 'Zmax', 'Zmed', 'Slope', 'Aspect', 'Lmax', 'Status', 'Connect', 'Form', 'TermType', 'Surging', 'Linkages', 'Name', 'geometry']
Let’s plot the two in their original projection.
First option: using the raster as a reference to match, we reproject the vector. We simply have to pass the Raster
as an argument
to reproject()
. See Match-reference functionality for more details.
We can plot the vector in its new projection.
vect_reproj.plot(ax="new", fc="none", ec="tab:purple", lw=3)
Second option: we can pass the georeferencing argument dst_crs
to reproject()
(an EPSG code can be passed directly as
int
).
# Reproject in UTM zone 45N.
vect_reproj = vect.reproject(crs=32645)
vect_reproj
Total running time of the script: (0 minutes 0.411 seconds)