Git Product home page Git Product logo

prettymapp's Introduction

prettymapp 🖼️

Prettymapp is a webapp and Python package to create beautiful maps from OpenStreetMap data


🎈 Try it out here: prettymapp on streamlit 🎈



Based on the prettymaps project

Prettymapp is based on a rewrite of the fantastic prettymaps project by @marceloprates. All credit for the original idea, designs and implementation go to him. The prettymapp rewrite focuses on speed and adapted configuration to interface with the webapp. It drops more complex configuration options in favour of improved speed, reduced code complexity and simplified configuration interfaces. It is partially tested and adds a streamlit webapp component.

Running the app locally

git clone https://github.com/chrieke/prettymapp.git
cd prettymapp
pip install -r streamlit-prettymapp/requirements.txt
streamlit run streamlit-prettymapp/app.py

Python package

You can also use prettymapp without the webapp, directly in Python. This lets you customize the functionality or build your own application.

Installation:

pip install prettymapp

Define the area, download and plot the OSM data:

from prettymapp.geo import get_aoi
from prettymapp.osm import get_osm_geometries
from prettymapp.plotting import Plot
from prettymapp.settings import STYLES

aoi = get_aoi(address="Praça Ferreira do Amaral, Macau", radius=1100, rectangular=False)
df = get_osm_geometries(aoi=aoi)

fig = Plot(
    df=df,
    aoi_bounds=aoi.bounds,
    draw_settings=STYLES["Peach"]
).plot_all()

fig.savefig("map.jpg")

You can also plot exported OSM XML files e.g. from openstreetmap.org:

from prettymapp.osm import get_osm_geometries_from_xml

df = get_osm_geometries_from_xml(filepath="Berlin.osm")
aoi_bounds = df.total_bounds
...

To customize the map appearance, use the additional arguments of the Plot class (e.g. shape, contour_width etc.). Check the preconfigured styles and webapp examples for inspiration.

prettymapp's People

Contributors

chrieke avatar eltociear avatar jrieke avatar smilebasti avatar tdiekel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

prettymapp's Issues

Potential performance issue: Unreliable performance of .loc in pandas 2.0.3

Issue Description:

Hello.
I have discovered a performance degradation in the .loc function of pandas version 2.0.3 when .loc handling big DataFrame with non-unique indexes. When using pandas more than 4 indexes, .loc drastically increases to X1000 times. And I notice that requirements.txt, shows that it depends on pandas version 2.0.3. I am not sure whether this performance problem in pandas will affect this repository. I found some discussions on GitHub related to this issue, including #54550 and #54746.
I also found that prettymapp/osm.py used the influenced api. There may be more files used the influenced api.

Suggestion

I would recommend considering an upgrade to a different version of pandas >= 2.1 or exploring other solutions to optimize the performance of .loc .
Any other workarounds or solutions would be greatly appreciated.
Thank you!

Requirements.txt updates

Recreating the requirements from my pc I get:

attrs==21.4.0
certifi==2022.6.15
charset-normalizer==2.1.0
click==8.1.3
click-plugins==1.1.1
cligj==0.7.2
cycler==0.11.0
Fiona==1.8.21
fonttools==4.34.4
geopandas==0.11.1
idna==3.3
kiwisolver==1.4.4
matplotlib==3.5.2
munch==2.5.0
networkx==2.8.5
numpy==1.23.1
osmnx==1.2.1
packaging==21.3
pandas==1.4.3
Pillow==9.2.0
prettymapp==0.0.1
pyparsing==3.0.9
pyproj==3.3.1
python-dateutil==2.8.2
pytz==2022.1
requests==2.28.1
Rtree==1.0.0
Shapely==1.8.2
six==1.16.0
urllib3==1.26.11

Please let me know if it is correct.
Best regards

Error on submit

Hello there, I'm getting an error on the streamlit app when submitting a new location for generation. Sharing the error code below.

requests.exceptions.ConnectionError: This app has encountered an error. The original error message is redacted to prevent data leaks. Full error details have been recorded in the logs (if you're on Streamlit Cloud, click on 'Manage app' in the lower right of your app).
Traceback:

File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 542, in _run_script
exec(code, module.dict)
File "/mount/src/prettymapp/streamlit-prettymapp/app.py", line 167, in
aoi = get_aoi(address=address, radius=radius, rectangular=rectangular)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/mount/src/prettymapp/prettymapp/geo.py", line 47, in get_aoi
lat, lon = geocode(address)
^^^^^^^^^^^^^^^^
File "/home/adminuser/venv/lib/python3.11/site-packages/osmnx/geocoder.py", line 45, in geocode
response_json = _nominatim._nominatim_request(params=params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/adminuser/venv/lib/python3.11/site-packages/osmnx/_nominatim.py", line 106, in _nominatim_request
response = requests.get(
^^^^^^^^^^^^^
File "/home/adminuser/venv/lib/python3.11/site-packages/requests/api.py", line 73, in get
return request("get", url, params=params, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/adminuser/venv/lib/python3.11/site-packages/requests/api.py", line 59, in request
return session.request(method=method, url=url, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/adminuser/venv/lib/python3.11/site-packages/requests/sessions.py", line 589, in request
resp = self.send(prep, **send_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/adminuser/venv/lib/python3.11/site-packages/requests/sessions.py", line 703, in send
r = adapter.send(request, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/adminuser/venv/lib/python3.11/site-packages/requests/adapters.py", line 519, in send
raise ConnectionError(e, request=request)

Peach style having different zorders than the other styles

Hi,

thank you for this fantastic app/package! I just stumbled across a minor issue with the Peach style not showing a waterway in blue while the other styles do so (does not happen with every waterway). I had a quick look and it might have to do with the different zorders in this specific style. Is there a reason for that?

Export image

can you add the possibility to export image in SVG or other file type?

Index Issue

Hi,

I am quite new to python, and I am trying to create a python script in Visual Studio. But I am receiving the following error message. Is there a solution?

Many thanks
Blake
image

Known issues FAQ

Somer water areas are not shown or cut off

OSM does not provide ocean geometries via the API (status proposed), this is why some coastal areas seem to cut off water area. No good solution as of right now.

Converting elements to geometries can be very slow

Here's a log from a short prettymapp script, where it takes more than 25 minutes to turn the 430k OSM elements into 15k geometries:

run log
$ python test.py
2023-08-22 12:49:24 Retrieved response from cache file "cache/53357fd0e0ac99711e0cc9ad382774d108ad5f1c.json"
2023-08-22 12:49:24 Geocoded "Portland, ME, USA" to (43.6592687, -70.2572642)
get_aoi: 0.03806114196777344s
2023-08-22 12:49:24 Projected GeoDataFrame to +proj=utm +zone=19 +ellps=WGS84 +datum=WGS84 +units=m +no_defs +type=crs
2023-08-22 12:49:24 Projected GeoDataFrame to epsg:4326
2023-08-22 12:49:24 Requesting data within polygon from API in 1 request(s)
2023-08-22 12:49:25 Retrieved response from cache file "cache/fcafbd21a00421565ded846c08f8d131196d0635.json"
2023-08-22 12:49:25 Got all geometries data within polygon from API in 1 request(s)
2023-08-22 12:49:25 Converting 430154 elements in JSON responses to geometries
2023-08-22 13:15:43 14956 geometries created in the dict
2023-08-22 13:15:43 74 untagged geometries removed
2023-08-22 13:15:45 Created r-tree spatial index for 14882 geometries
2023-08-22 13:15:45 Identified 3537 geometries inside polygon
2023-08-22 13:15:45 11345 geometries removed by the polygon filter
2023-08-22 13:15:45 11811 geometries removed by the tag filter
2023-08-22 13:15:46 3030 geometries in the final GeoDataFrame
done
/Users/llimllib/.local/share/asdf/installs/python/3.10.12/lib/python3.10/site-packages/geopandas/tools/clip.py:67: FutureWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`
  clipped.loc[
get_osm_geometries: 1581.8291890621185s
plot: 0.26825881004333496s
plot: 2.8084590435028076s

Here's the full script (I manually edited prettymapp/osm.py to enable console logging - not sure how to do it otherwise):

test.py
from prettymapp.geo import get_aoi
from prettymapp.osm import get_osm_geometries
from prettymapp.plotting import Plot
from prettymapp.settings import STYLES

import time

t1 = time.time()

aoi = get_aoi(address="Portland, ME, USA", radius=1100, rectangular=False)
t2 = time.time()
print(f"get_aoi: {t2-t1}s")

df = get_osm_geometries(aoi=aoi)
t3 = time.time()
print(f"get_osm_geometries: {t3-t2}s")

fig = Plot(df=df, aoi_bounds=aoi.bounds, draw_settings=STYLES["Peach"]).plot_all()
t4 = time.time()
print(f"plot: {t4-t3}s")

fig.savefig("map.jpg")
t5 = time.time()
print(f"plot: {t5-t4}s")

Is there any way that could be sped up, or is it just a necessary cost?

edit: I ran the code under a profiler, and I didn't notice elarlier that all of the time is spent in osmnx, which spends it all in shapely:

profile report
In [8]: s.print_stats(15)
Tue Aug 22 14:45:31 2023    profile.log

         8894101 function calls (8720818 primitive calls) in 1557.185 seconds

   Ordered by: cumulative time
   List reduced from 7775 to 15 due to restriction <15>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
   1125/1    0.004    0.000 1557.186 1557.186 {built-in method builtins.exec}
        1    0.000    0.000 1557.186 1557.186 test.py:1(<module>)
        1    0.059    0.059 1553.203 1553.203 prettymapp/prettymapp/osm.py:13(get_osm_geometries)
        1    0.028    0.028 1552.342 1552.342 site-packages/osmnx/geometries.py:236(geometries_from_polygon)
        1    0.175    0.175 1551.998 1551.998 site-packages/osmnx/geometries.py:330(_create_gdf)
        9    0.000    0.000 1548.878  172.098 site-packages/osmnx/geometries.py:690(_parse_relation_to_multipolygon)
        9    0.012    0.001 1548.587  172.065 site-packages/osmnx/geometries.py:839(_subtract_inner_polygons_from_outer_polygons)
     3243    0.015    0.000 1381.099    0.426 site-packages/shapely/geometry/base.py:689(difference)
     5854 1380.992    0.236 1381.002    0.236 site-packages/shapely/topology.py:66(__call__)
     9612  165.742    0.017  165.756    0.017 site-packages/shapely/predicates.py:11(__call__)
     3244    0.010    0.000  165.423    0.051 site-packages/shapely/geometry/base.py:815(within)

feature req: Plot from an osm file

Hi! The prettymapp & prettymaps are great projects that plot impressive maps 🥰
Now I need to make a map plot using prettymapp, and I prefer to download the osm file in advance, because the network is not good and I prefer making all the resources local, also, the osm file I want to plot is very big (~80 MB). I wonder if prettymapp can add an interface to pass in the osm file path and parse it offline? Or, may I know the walkaround in current situation? Thank you!

Addresses

When I enter an address and submit, it runs for a few seconds and nothing happens

Error running app

Not able to access to the app.

It shows 'Oh no.
Error running app. If this keeps happening, please contact support.'

Any thoughts? I tried using different browsers but did not help.

No Output

I tried to generate a map but it shows a broken image with 0.
image

Gallery

Would be great to link out or show a preview of a prettymapps gallery from social media etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.