I have a polygon in python shapely that I would like to buffer with a 100 foot buffer.

If the polygon is stored as a series of WGS84 lon/lat points how would I go about calculating the distance of the 100ft buffer?

I can't find anything searching google and seek guidance on the algorithm.


First, I will assume that your points are in WGS84 = EPSG: 4326. Convert the lon/lat points to UTM meters using pyproj. First we need to get the correct projection. The issue is that to convert to UTM you need to know your UTM zone. That is something you can look up separately; UTM zone will depend on the longitude of the initial shape.

import pyproj
import shapely.geometry as shpgeo

proj = pyproj.Proj(proj="utm", zone=???, ellps="WGS84", datum="WGS84)

I use a standard helper function to convert Polygons and MultiPolygons to and from UTM. The arguments are a shapely Polygon or MultiPolygon object and a pyProj Proj object.

def toFromUTM(shp, proj, inv=False):
    geoInterface = shp.__geo_interface__

    shpType = geoInterface['type']
    coords = geoInterface['coordinates']
    if shpType == 'Polygon':
        newCoord = [[proj(*point, inverse=inv) for point in linring] for linring in coords]
    elif shpType == 'MultiPolygon':
        newCoord = [[[proj(*point, inverse=inv) for point in linring] for linring in poly] for poly in coords]

    return shpgeo.shape({'type': shpType, 'coordinates': tuple(newCoord)})

Using this function, you can convert your shape (initial_polygon) to UTM, buffer it in meters (100 feet is 30.48 meters), then convert back to lon/lat if you so desire

init_shape_utm = toFromUTM(initial_polygon, proj)
buffer_shape_utm = init_shape_utm.buffer(30.48)
buffer_shape_lonlat = toFromUTM(buffer_shape_utm, proj, inv=True)

The output will be a shapely Polygon (or MultiPolygon) buffered to 100 feet, with coordinates in the WGS84 lon/lat system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.