Skip to content

Commit

Permalink
Merge 88d09ef into 910455c
Browse files Browse the repository at this point in the history
  • Loading branch information
giplessis committed Jun 15, 2019
2 parents 910455c + 88d09ef commit d235482
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/rasterstats/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def gen_zonal_stats(
zone_func=None,
raster_out=False,
prefix=None,
geojson_out=False, **kwargs):
geojson_out=False,
properties=None, **kwargs):
"""Zonal statistics of raster values aggregated to vector geometries.
Parameters
Expand Down Expand Up @@ -112,6 +113,9 @@ def gen_zonal_stats(
with zonal stats appended as additional properties.
Use with `prefix` to ensure unique and meaningful property names.
properties: list of str, , optional
Property names of the geo-like python objects to be used in the user-defined stats.
Returns
-------
generator of dicts (if geojson_out is False)
Expand Down Expand Up @@ -146,6 +150,8 @@ def gen_zonal_stats(
features_iter = read_features(vectors, layer)
for _, feat in enumerate(features_iter):
geom = shape(feat['geometry'])
if properties:
prop_dic = {k: feat['properties'][k] for k in properties}

if 'Point' in geom.type:
geom = boxify_points(geom, rast)
Expand Down Expand Up @@ -254,7 +260,10 @@ def gen_zonal_stats(

if add_stats is not None:
for stat_name, stat_func in add_stats.items():
feature_stats[stat_name] = stat_func(masked)
try:
feature_stats[stat_name] = stat_func(masked, prop_dic)
except:
feature_stats[stat_name] = stat_func(masked)

if raster_out:
feature_stats['mini_raster_array'] = masked
Expand Down

0 comments on commit d235482

Please sign in to comment.