Skip to content

Commit

Permalink
Rebuild index in FC.sort()
Browse files Browse the repository at this point in the history
  • Loading branch information
Sakharov committed Feb 8, 2024
1 parent 4b1ad36 commit 0b05e7a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions aeronet_vector/aeronet_vector/featurecollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def __getitem__(self, item):
def __len__(self):
return len(self.features)

def _valid(self, features):
# TODO: make it static?
@staticmethod
def _valid(features):
valid_features = []
for f in features:
if not f.geometry.get('coordinates'): # remove possible empty shapes
Expand Down Expand Up @@ -81,6 +81,9 @@ def sort(self, key: Callable, reverse: bool = False):
key (Callable): sorting function
reverse (bool): if True, ascending sorting order, else descending"""
self.features.sort(key=key, reverse=reverse)
self.index = rtree.index.Index()
for i, f in enumerate(self.features):
self.index.add(i, f.bounds, f.shape)

def extend(self, fc):
"""Extends collection with another collection (inplace)
Expand Down

0 comments on commit 0b05e7a

Please sign in to comment.