Skip to content

Instantly share code, notes, and snippets.

@matthewhanson

matthewhanson/calc-footprint.py Secret

Created Oct 20, 2020
Embed
What would you like to do?
def image_boundary(filename, scale=1, tolerance=0.005):
# open source data
src = rasterio.open(filename)
# generate datamask
arr = src.read(
1, out_shape=(int(src.shape[0] / scale), int(src.shape[1] / scale))
)
arr[numpy.where(arr != 0)] = 1
transform = src.transform * A.scale(scale)
for geom, val in rasterio.features.shapes(arr, transform=transform):
geometry = shape(
transform_geom(src.crs, "EPSG:4326", geom, precision=3)
)
if val == 1:
geometry = geometry.simplify(tolerance, preserve_topology=True)
return mapping(geometry)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment