-
-
Save mxttwoods/22ba96b490bb56d1074c477e32b7464e to your computer and use it in GitHub Desktop.
Python code to convert a geographic point into a circular buffer with radius in meters.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from shapely.geometry import Point | |
| from functools import partial | |
| from shapely.ops import transform | |
| import pyproj | |
| def buffer_in_meters(lng, lat, radius): | |
| proj_meters = pyproj.Proj(init='epsg:3857') | |
| proj_latlng = pyproj.Proj(init='epsg:4326') | |
| project_to_meters = partial(pyproj.transform, proj_latlng, proj_meters) | |
| project_to_latlng = partial(pyproj.transform, proj_meters, proj_latlng) | |
| pt_latlng = Point(lng, lat) | |
| pt_meters = transform(project_to_meters, pt_latlng) | |
| buffer_meters = pt_meters.buffer(radius) | |
| buffer_latlng = transform(project_to_latlng, buffer_meters) | |
| return buffer_latlng |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment