Skip to content

Commit

Permalink
Port maup to Shapely 2.0 (#72)
Browse files Browse the repository at this point in the history
This brings maup's dependencies up to date with GerryChain's:
Shapely 1.x and Python 3.7 are now unsupported.

---------

Co-authored-by: Parker J. Rule <[email protected]>
  • Loading branch information
InnovativeInventor and pjrule authored Feb 8, 2023
1 parent 56ed11c commit ba757a6
Show file tree
Hide file tree
Showing 5 changed files with 709 additions and 600 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: [3.8, 3.9, '3.10', 3.11]
os: [ubuntu-latest, macOS-latest]

steps:
Expand Down
10 changes: 3 additions & 7 deletions maup/indexed_geometries.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ def get_geometries(geometries):
class IndexedGeometries:
def __init__(self, geometries):
self.geometries = get_geometries(geometries)
for i, geometry in self.geometries.items():
geometry.index = i
self.spatial_index = STRtree(self.geometries)
self.index = self.geometries.index

def query(self, geometry):
relevant_indices = [geom.index for geom in self.spatial_index.query(geometry)]
relevant_geometries = self.geometries.loc[relevant_indices]
relevant_indices = [index for index in self.spatial_index.query(geometry)]
relevant_geometries = self.geometries.iloc[relevant_indices]
return relevant_geometries

def intersections(self, geometry):
Expand All @@ -46,11 +43,10 @@ def assign(self, targets):
)
]
if groups:
return pandas.concat(groups).reindex(self.index)
return pandas.concat(groups).reindex(self.geometries.index)
else:
return geopandas.GeoSeries()


def enumerate_intersections(self, targets):
target_geometries = get_geometries(targets)
for i, target in progress(target_geometries.items(), len(target_geometries)):
Expand Down
Loading

0 comments on commit ba757a6

Please sign in to comment.