Work in meters#
Most files arrive in WGS 84 (degrees), but field work happens in meters. shapelib gives you three levels of convenience.
Let the methods handle it#
Measurements are geodesic and meter-based methods reproject internally —
calculate_length, calculate_area, buffer_m need nothing from
you:
lines = read_file("lines.shp") # WGS 84
lines.calculate_length() # accurate, no reprojection needed
Reproject temporarily — temp_crs#
For a metric operation in the middle of a workflow, the temp_crs
context manager switches the CRS and guarantees it switches back:
with lines.temp_crs(lines.estimate_utm_crs() or "EPSG:31982"):
# coordinates are in meters inside this block
...
Reproject explicitly#
When a whole pipeline works in meters (like the line tools, whose thresholds are in CRS units), convert once and convert back at the end:
lines.to_utm() # project to the detected UTM zone
# ... metric work here ...
lines.to_original_crs() # back to the CRS the file was read with
to_wgs84() is also available as a shortcut to EPSG:4326.
Note
to_utm() picks the UTM zone from the data. For data spanning
multiple UTM zones, choose the CRS yourself with geopandas’
to_crs.