-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #678 from CodeForPhilly/lebovits/issu31-add-neighb…
…oring-properties-count Lebovits/issu31 add neighboring properties count
- Loading branch information
Showing
4 changed files
with
38 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import warnings | ||
|
||
import geopandas as gpd | ||
import networkx as nx | ||
from libpysal.weights import Queen | ||
|
||
|
||
def contig_neighbors(primary_featurelayer): | ||
|
||
parcels = primary_featurelayer.gdf | ||
|
||
with warnings.catch_warnings(): | ||
warnings.filterwarnings("ignore", category=FutureWarning) | ||
warnings.filterwarnings("ignore", category=UserWarning, message="The weights matrix is not fully connected") | ||
|
||
w = Queen.from_dataframe(parcels) | ||
|
||
g = w.to_networkx() | ||
|
||
# Calculate the number of contiguous neighbors for each feature in parcels | ||
n_contiguous = [len(nx.node_connected_component(g, i)) for i in range(len(parcels))] | ||
|
||
primary_featurelayer.gdf['n_contiguous'] = n_contiguous | ||
|
||
return primary_featurelayer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters