982 points · by sebg · 5y ago · 74 comments
I had a go at doing roughly the same thing a couple of years ago [0]. It was mostly straightforward, but the part I really struggled with were rendering the sea. The encoding of OSM coastline is quite quirky [1]. When the edge of the rendering intersects with the coastline it's very tricky to compute which side of a coastline is sea and which is land. As an example - how would you render this [2]?
I wasn't sure how I could solve this, so I wrote up a more abstract formulation of the problem here [3], and asked for help. I think the proposed solution make sense, but I think I would have to implement it by rendering individual pixels and wouldn't be able to lean on a higher level graphics library.
I'm looking forward to seeing how the author solved this problem.
[0] https://twitter.com/willsewell_/status/1172523752699113473
[1] https://wiki.openstreetmap.org/wiki/Tag:natural%3Dcoastline#...
[2] https://www.openstreetmap.org/#map=15/22.0330/88.8819
[3] https://leetcode.com/discuss/general-discussion/1104642/im-s...
You will have to pre scan the ways for instance where they change from ascending to descending. Here the sea will spilt into a left and right section. Make a list of these and sort them from top to bottom.
While generating triangles, check that list to where you should split.
I was hoping for some more documentation apart from the usage examples, although those are much appreciated too.
Agreed. This is a good library but it is let down by lack of documentation. Reading the source doesn't help, e.g. this is "explaining" the parameters in the plot function:
# Whether to use a backup for the layers
backup = None,
# Custom postprocessing function on layers
postprocessing = None,
# Radius (in case of circular plot)
radius = None,
These sorts of comments merely repeat what's in the code and are worse than useless.This stuff is amazing.
I think I want there to be a professional software "continuing-education" [#] service. A course I do each 6 months that just gets me to run something for an hour (from astronomy to 3d-printing).
I know i could do it myself but the 10 -20 hours spent on each install wasted though bad configs seems something I would happily pay to avoid.
[#] Not a "re-education" camp. Although I know few devs I could send to one if someone provides seed funding. ;-)
Install with
pip install git+https://github.com/abey79/vsketch#egg=vsketch
pip install git+https://github.com/marceloprates/prettymaps.git
If prettymaps needs vsketch, why does it not put it into its setup.py? pip install git+https://github.com/abey79/vsketch#egg=vsketch
... into setup.py instead? FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/lib/python3.7/dist-packages/numpy-1.19.5.dist-info/METADATA'Runtime > Restart Runtime
!pip install 'numpy>=1.3.0,<2.0.0' --force-reinstall
Now the maps work! import matplotlib.pyplot as plt
from prettymaps import plot
Also use this at the end to save your map. plt.savefig('my-map.png')Maybe a marketplace for such maps would allow artists to document their cities/neighborhoods.
imgurl = "https://a.tile.openstreetmap.org/{0}/{1}/{2}.png".format(zoom, xtile, ytile)
the tricky part is to known which xtile, ytile to fetch, but Stack Overflow has the answer [1].Then you can draw over them with `PIL` and also `cairo`, in order to lay SVG shapes onto the map. Cairo is somewhat hard to grasp, because it is outdated, but it draws perfectly smooth lines.
fig, ax = plt.subplots(figsize = (12, 12), constrained_layout = True)
fig is not defined
import matplotlib.pyplot as plt
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot....
1: https://plotly.com/python/ 2: https://seaborn.pydata.org/
Seaborn is good if you want something pretty and static with matplotlib underneath but do not want to mess with defaults too much.