WGS84 Buffer in Meters¶
Sometimes you’re working with location data which is often expressed as latitude and longitude. Coordinate systems that measure location in these terms (like the World Geodetic System (WGS84)) use angular measurement, there are many operations such as buffering; or querying length or area, that are much more natural to perform in terms of linear measurements (e.g. meters).
In this example we’ll start with a latitude and a longitude and create a
point
. Then we’ll create a
buffer polygon (an approximate circle around that point). Even though the
point geometry is in WGS-84, we’ll define the
buffer
radius in meters.
The polygon
buffer will be defined
in the same coordinate system as the buffer (WGS-84) but we’ll be able to
query its area
in terms
of meters.
from shapeit import SrPoint
from shapeit.measure import Units
# Create a point from a latitude-longitude pair.
wgs84 = SrPoint.from_lat_lon(lat=45.553670, lon=-94.142430)
# We'll create a high `resolution` buffer so we can get a close
# approximation of the area.
buffer = wgs84.buffer(5, Units.METERS, resolution=1000)
# The buffer is still in WGS-84.
print(f"The buffer's SRID is: {buffer.srid}")
# The equation for the area of a circle tells us that the buffer's
# area should be approximately 78.54 meters.
print(f"The buffer area is: {buffer.area(units=Units.METERS)}")
The buffer's SRID is: 4326
The buffer area is: 78.53978404108517