File tree Expand file tree Collapse file tree 2 files changed +20
-7
lines changed Expand file tree Collapse file tree 2 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ dependencies:
3030 - zstd
3131 - xarray=2022.3
3232 - pandana
33+ - h3-py<4
3334 - pip
3435 - pip :
3536 - pulp
Original file line number Diff line number Diff line change 1+ from packaging .version import Version
2+
3+
14def _build_from_h3 (ids , order = 1 ):
25 """Generate Graph from H3 hexagons.
36
@@ -30,14 +33,23 @@ def _build_from_h3(ids, order=1):
3033
3134 neighbors = {}
3235 weights = {}
33- for ix in ids :
34- rings = h3 .hex_range_distances (ix , order )
35- for i , ring in enumerate (rings ):
36- if i == 0 :
37- neighbors [ix ] = []
38- weights [ix ] = []
39- else :
36+ if Version (h3 .__version__ ) > Version ("4.0" ):
37+ for ix in ids :
38+ neighbors [ix ] = []
39+ weights [ix ] = []
40+ for i in range (1 , order + 1 ):
41+ ring = h3 .grid_ring (ix , i )
4042 neighbors [ix ].extend (list (ring ))
4143 weights [ix ].extend ([i ] * len (ring ))
44+ else :
45+ for ix in ids :
46+ rings = h3 .hex_range_distances (ix , order )
47+ for i , ring in enumerate (rings ):
48+ if i == 0 :
49+ neighbors [ix ] = []
50+ weights [ix ] = []
51+ else :
52+ neighbors [ix ].extend (list (ring ))
53+ weights [ix ].extend ([i ] * len (ring ))
4254
4355 return neighbors , weights
You can’t perform that action at this time.
0 commit comments