-
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 branch 'staging' into codewritingcow/624-add-aria-label-to-save…
…d-button
- Loading branch information
Showing
31 changed files
with
704 additions
and
181 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from datetime import datetime, timedelta | ||
|
||
import geopandas as gpd | ||
import jenkspy | ||
import pandas as pd | ||
import requests | ||
from classes.featurelayer import FeatureLayer | ||
from constants.services import CENSUS_BGS_URL, PERMITS_QUERY | ||
|
||
from config.config import USE_CRS | ||
|
||
|
||
def dev_probability(primary_featurelayer): | ||
|
||
census_bgs_gdf = gpd.read_file(CENSUS_BGS_URL) | ||
census_bgs_gdf = census_bgs_gdf.to_crs(USE_CRS) | ||
|
||
base_url = "https://phl.carto.com/api/v2/sql" | ||
response = requests.get(f"{base_url}?q={PERMITS_QUERY}&format=GeoJSON") | ||
|
||
if response.status_code == 200: | ||
try: | ||
permits_gdf = gpd.GeoDataFrame.from_features(response.json(), crs='EPSG:4326') | ||
print("GeoDataFrame created successfully.") | ||
except Exception as e: | ||
print(f"Failed to convert response to GeoDataFrame: {e}") | ||
return primary_featurelayer | ||
else: | ||
truncated_response = response.content[:500] | ||
print(f"Failed to fetch permits data. HTTP status code: {response.status_code}. Response text: {truncated_response}") | ||
return primary_featurelayer | ||
|
||
permits_gdf = permits_gdf.to_crs(USE_CRS) | ||
|
||
joined_gdf = gpd.sjoin(permits_gdf, census_bgs_gdf, how="inner", predicate='within') | ||
|
||
permit_counts = joined_gdf.groupby('index_right').size() | ||
census_bgs_gdf['permit_count'] = census_bgs_gdf.index.map(permit_counts) | ||
census_bgs_gdf['permit_count'] = census_bgs_gdf['permit_count'].fillna(0) | ||
|
||
# Classify development probability using Jenks natural breaks | ||
breaks = jenkspy.jenks_breaks(census_bgs_gdf['permit_count'], n_classes=3) | ||
census_bgs_gdf['dev_rank'] = pd.cut(census_bgs_gdf['permit_count'], bins=breaks, labels=['Low', 'Medium', 'High']) | ||
|
||
updated_census_bgs = FeatureLayer( | ||
name="Updated Census Block Groups", | ||
gdf=census_bgs_gdf[['permit_count', 'dev_rank', 'geometry']], | ||
use_wkb_geom_field="geometry", | ||
cols=["permit_count", "dev_rank"] | ||
) | ||
|
||
updated_census_bgs.gdf = updated_census_bgs.gdf.to_crs(USE_CRS) | ||
|
||
primary_featurelayer.spatial_join(updated_census_bgs) | ||
|
||
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
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 |
---|---|---|
@@ -1,20 +1,25 @@ | ||
import geopandas as gpd | ||
from classes.featurelayer import FeatureLayer | ||
from config.config import USE_CRS | ||
from constants.services import NBHOODS_URL | ||
|
||
from config.config import USE_CRS | ||
|
||
|
||
def nbhoods(primary_featurelayer): | ||
phl_nbhoods = gpd.read_file(NBHOODS_URL) | ||
phl_nbhoods.rename(columns={"mapname": "neighborhood"}, inplace=True) | ||
|
||
# Correct the column name to uppercase if needed | ||
if 'MAPNAME' in phl_nbhoods.columns: | ||
phl_nbhoods.rename(columns={"MAPNAME": "neighborhood"}, inplace=True) | ||
|
||
phl_nbhoods = phl_nbhoods.to_crs(USE_CRS) | ||
|
||
nbhoods = FeatureLayer("Neighborhoods") | ||
nbhoods.gdf = phl_nbhoods | ||
|
||
red_cols_to_keep = ["neighborhood", "geometry"] | ||
nbhoods.gdf = nbhoods.gdf[red_cols_to_keep] | ||
|
||
primary_featurelayer.spatial_join(nbhoods) | ||
|
||
return primary_featurelayer |
Oops, something went wrong.