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 26, 2024
1 parent 74e544a commit 7fd296c
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 7fd296c

Please sign in to comment.