Skip to content

Commit

Permalink
Merge branch 'chrieke:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
smilebasti authored Apr 18, 2024
2 parents bf43344 + 961aae5 commit 47dc8b2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
7 changes: 5 additions & 2 deletions prettymapp/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ def explode_multigeometries(df: GeoDataFrame) -> GeoDataFrame:
df_multi = df[mask]
for _, row in df_multi.iterrows():
df_temp = GeoDataFrame(
pd.DataFrame.from_records([row.to_dict()] * len(row.geometry.geoms)), crs="EPSG:4326"
pd.DataFrame.from_records([row.to_dict()] * len(row.geometry.geoms)),
crs="EPSG:4326",
)
df_temp.geometry = list(row.geometry.geoms)
outdf = GeoDataFrame(pd.concat([outdf, df_temp], ignore_index=True), crs="EPSG:4326")
outdf = GeoDataFrame(
pd.concat([outdf, df_temp], ignore_index=True), crs="EPSG:4326"
)

outdf = outdf.reset_index(drop=True)
return outdf
13 changes: 11 additions & 2 deletions prettymapp/osm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@
settings.log_console = False


def get_osm_geometries(aoi: Polygon) -> GeoDataFrame:
def get_osm_tags():
tags: dict = {}
for d in LC_SETTINGS.values(): # type: ignore
for k, v in d.items(): # type: ignore
try:
tags.setdefault(k, []).extend(v)
except TypeError: # e.g. "building": True
tags[k] = v
return tags

df = features_from_polygon(polygon=aoi, tags=tags)

def cleanup_osm_df(df: GeoDataFrame, aoi: Polygon) -> GeoDataFrame:
df = df.droplevel(level=0)
df = df[~df.geometry.geom_type.isin(["Point", "MultiPoint"])]

Expand Down Expand Up @@ -47,3 +49,10 @@ def get_osm_geometries(aoi: Polygon) -> GeoDataFrame:
)

return df


def get_osm_geometries(aoi: Polygon) -> GeoDataFrame:
tags = get_osm_tags()
df = features_from_polygon(polygon=aoi, tags=tags)
df = cleanup_osm_df(df, aoi)
return df
8 changes: 4 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pandas==2.0.3 #osmnx subdependecies are partially unpinned
numpy==1.25.2
osmnx==1.6.0
matplotlib==3.7.2
pandas==2.2.1 #osmnx subdependecies are partially unpinned
osmnx==1.9.1
pyogrio==0.7.2
matplotlib==3.8.3
2 changes: 1 addition & 1 deletion streamlit-prettymapp/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
streamlit==1.26.0
streamlit==1.32.2
streamlit-image-select==0.6.0
prettymapp
4 changes: 3 additions & 1 deletion streamlit-prettymapp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
from prettymapp.settings import STYLES


@st.cache_data(show_spinner=False, hash_funcs={Polygon: lambda x: json.dumps(x.__geo_interface__)})
@st.cache_data(
show_spinner=False, hash_funcs={Polygon: lambda x: json.dumps(x.__geo_interface__)}
)
def st_get_osm_geometries(aoi):
"""Wrapper to enable streamlit caching for package function"""
df = get_osm_geometries(aoi=aoi)
Expand Down

0 comments on commit 47dc8b2

Please sign in to comment.