Skip to content

Commit

Permalink
rework point path to use GeoSeries.within()
Browse files Browse the repository at this point in the history
  • Loading branch information
atmorling committed Aug 22, 2024
1 parent 76370f1 commit 8a13710
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ecoscope/analysis/feature_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

def calculate_feature_density(selection, grid, geometry_type="point"):
def clip_density(cell):
result = selection.clip_by_rect(*cell.bounds)
result = result[~result.is_empty]
if geometry_type == "point":
return result.geometry.count()
result = selection.geometry.within(cell)
result = result[result]
return result.count()
elif geometry_type == "line":
result = selection.clip_by_rect(*cell.bounds)
result = result[~result.is_empty]
return result.geometry.length.sum()
else:
raise ValueError("Unsupported geometry type")
Expand Down

0 comments on commit 8a13710

Please sign in to comment.