Merge pull request #135 from marceloprates/pr/Milziade/134

Pr/milziade/134
This commit is contained in:
Marcelo de Oliveira Rosa Prates
2025-06-29 17:05:19 -03:00
committed by GitHub
13 changed files with 162 additions and 130 deletions

View File

@@ -71,7 +71,7 @@ import prettymaps
plot = prettymaps.plot('Stad van de Zon, Heerhugowaard, Netherlands')
```
Fetching geodataframes took 13.76 seconds
Fetching geodataframes took 13.61 seconds
@@ -94,7 +94,7 @@ plot = prettymaps.plot(
)
```
Fetching geodataframes took 4.71 seconds
Fetching geodataframes took 6.24 seconds
@@ -369,7 +369,7 @@ plot = prettymaps.plot(
)
```
Fetching geodataframes took 28.29 seconds
Fetching geodataframes took 29.71 seconds
@@ -393,7 +393,7 @@ plot = prettymaps.plot(
)
```
Fetching geodataframes took 10.83 seconds
Fetching geodataframes took 12.37 seconds
@@ -413,7 +413,7 @@ plot = prettymaps.plot('Centro Histórico, Porto Alegre', show = False)
plot.geodataframes['building']
```
Fetching geodataframes took 11.94 seconds
Fetching geodataframes took 16.02 seconds
@@ -741,7 +741,7 @@ plot.geodataframes['building'][
].geometry[0]
```
/opt/hostedtoolcache/Python/3.11.12/x64/lib/python3.11/site-packages/geopandas/geoseries.py:648: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`
/opt/hostedtoolcache/Python/3.11.13/x64/lib/python3.11/site-packages/geopandas/geoseries.py:648: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`
val = getattr(super(), mtd)(*args, **kwargs)
@@ -788,7 +788,7 @@ for ax,building in zip(np.concatenate(axes),buildings):
ax.autoscale(); ax.axis('off'); ax.axis('equal')
```
Fetching geodataframes took 12.50 seconds
Fetching geodataframes took 13.25 seconds
@@ -819,7 +819,7 @@ _ = plot.ax.set_title(
)
```
Fetching geodataframes took 12.74 seconds
Fetching geodataframes took 13.47 seconds
Use **plotter** mode to export a pen plotter-compatible SVG (thanks to abey79's amazing [vsketch](https://github.com/abey79/vsketch) library)
@@ -838,7 +838,7 @@ plot = prettymaps.plot(
)
```
Fetching geodataframes took 3.91 seconds
Fetching geodataframes took 4.21 seconds
@@ -862,7 +862,7 @@ plot = prettymaps.plot(
)
```
Fetching geodataframes took 26.94 seconds
Fetching geodataframes took 29.60 seconds
@@ -963,13 +963,13 @@ plot = prettymaps.multiplot(
)
```
Fetching geodataframes took 8.62 seconds
Fetching geodataframes took 8.72 seconds
Fetching geodataframes took 5.93 seconds
Fetching geodataframes took 7.96 seconds
Fetching geodataframes took 8.74 seconds
Fetching geodataframes took 8.96 seconds
@@ -997,7 +997,7 @@ plot = prettymaps.plot(
)
```
Fetching geodataframes took 47.61 seconds
Fetching geodataframes took 49.74 seconds
make: Entering directory '/home/runner/work/prettymaps/prettymaps/notebooks/SRTM1'
@@ -1014,11 +1014,11 @@ plot = prettymaps.plot(
gdalbuildvrt -q -overwrite SRTM1.vrt cache/N21/N21W158.tif
make: Leaving directory '/home/runner/work/prettymaps/prettymaps/notebooks/SRTM1'
make: Entering directory '/home/runner/work/prettymaps/prettymaps/notebooks/SRTM1'
cp SRTM1.vrt SRTM1.286507e05dd14c97a364976914d44158.vrt
cp SRTM1.vrt SRTM1.cccd6d23120f43349362779587d61590.vrt
make: Leaving directory '/home/runner/work/prettymaps/prettymaps/notebooks/SRTM1'
make: Entering directory '/home/runner/work/prettymaps/prettymaps/notebooks/SRTM1'
gdal_translate -q -co TILED=YES -co COMPRESS=DEFLATE -co ZLEVEL=9 -co PREDICTOR=2 -projwin -157.90125854957773 21.364471426268267 -157.81006761682832 21.244615177105388 SRTM1.286507e05dd14c97a364976914d44158.vrt /home/runner/work/prettymaps/prettymaps/notebooks/elevation.tif
rm -f SRTM1.286507e05dd14c97a364976914d44158.vrt
gdal_translate -q -co TILED=YES -co COMPRESS=DEFLATE -co ZLEVEL=9 -co PREDICTOR=2 -projwin -157.90125854957773 21.364471426268267 -157.81006761682832 21.244615177105388 SRTM1.cccd6d23120f43349362779587d61590.vrt /home/runner/work/prettymaps/prettymaps/notebooks/elevation.tif
rm -f SRTM1.cccd6d23120f43349362779587d61590.vrt
make: Leaving directory '/home/runner/work/prettymaps/prettymaps/notebooks/SRTM1'
@@ -1052,7 +1052,7 @@ plot = prettymaps.plot(
)
```
Fetching geodataframes took 18.23 seconds
Fetching geodataframes took 21.24 seconds

72
app.py
View File

@@ -5,6 +5,16 @@ import sys
import os
import io
def download_svg():
"""
Creates additional map in SVG format
"""
fig_path = "/tmp/generated_map_download.svg"
plt.savefig(fig_path, format="svg", bbox_inches="tight", dpi=150)
return fig_path
# Set Streamlit to use the wide layout
st.set_page_config(layout="wide")
@@ -65,8 +75,10 @@ with cols[0]:
page_size_col, dpi_col = st.columns(2)
with page_size_col:
page_size = st.selectbox(
"Page Size", ["A4", "A5", "Square"], index = 0
#, "A3", "A2", "A1", "Custom"], index=0
"Page Size",
["A4", "A5", "Square"],
index=0,
# , "A3", "A2", "A1", "Custom"], index=0
)
with dpi_col:
dpi = st.number_input("DPI", min_value=50, max_value=300, value=100, step=50)
@@ -130,7 +142,7 @@ with cols[1]:
use_container_width=True,
)
if button: # or "last_image" in st.session_state:
if button:
hillshade_params = (
{
"azdeg": azdeg,
@@ -166,23 +178,43 @@ with cols[1]:
with open(fig_path, "wb") as f:
f.write(st.session_state.last_image.getbuffer())
# Provide a download button
with open(fig_path, "rb") as file:
btn = st.download_button(
label="Download Map",
data=file,
file_name=f"{query}.png",
mime="image/png",
use_container_width=True,
)
# Save SVG for persistent download
svg_path = download_svg()
st.session_state.last_png_path = fig_path
st.session_state.last_svg_path = svg_path
st.image(st.session_state.last_image, use_container_width=True)
# Always show download buttons (disabled if no image)
png_ready = "last_png_path" in st.session_state and os.path.exists(
st.session_state["last_png_path"]
)
svg_ready = "last_svg_path" in st.session_state and os.path.exists(
st.session_state["last_svg_path"]
)
btn_cols = st.columns(2)
with btn_cols[0]:
st.download_button(
label="Download PNG",
data=open(st.session_state["last_png_path"], "rb") if png_ready else b"",
file_name=f"{query}.png",
mime="image/png",
use_container_width=True,
disabled=not png_ready,
)
with btn_cols[1]:
st.download_button(
label="Download SVG",
data=open(st.session_state["last_svg_path"], "rb") if svg_ready else b"",
file_name=f"{query}.svg",
mime="image/svg",
use_container_width=True,
disabled=not svg_ready,
)
# Always show image (generated or placeholder)
if st.session_state.get("last_image"):
st.image(st.session_state.last_image, use_container_width=True)
else:
if st.session_state.last_image:
st.image(st.session_state.last_image, use_container_width=True)
else:
st.image(
"https://github.com/marceloprates/prettymaps/blob/main/prints/app_placeholder.png?raw=true",
use_container_width=True,
)
st.image(
"https://github.com/marceloprates/prettymaps/blob/main/pictures/app_placeholder.png?raw=true",
use_container_width=True,
)

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 MiB

After

Width:  |  Height:  |  Size: 3.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 MiB

After

Width:  |  Height:  |  Size: 2.4 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 779 KiB

After

Width:  |  Height:  |  Size: 779 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 MiB

After

Width:  |  Height:  |  Size: 6.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.3 MiB

After

Width:  |  Height:  |  Size: 2.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 MiB

After

Width:  |  Height:  |  Size: 2.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 913 KiB