[HN Gopher] Prettymaps: Small Python library to draw customized ...
       ___________________________________________________________________
        
       Prettymaps: Small Python library to draw customized maps from
       OpenStreetMap data
        
       Author : sebg
       Score  : 674 points
       Date   : 2021-08-25 12:48 UTC (10 hours ago)
        
 (HTM) web link (github.com)
 (TXT) w3m dump (github.com)
        
       | pgroves wrote:
       | Looks really nice. The big blob of parameters in the kwargs looks
       | pretty intimidating to get correct. Maybe consider a builder
       | object for the config:
       | https://en.wikipedia.org/wiki/Builder_pattern. It would probably
       | be easier to document, too (document the setter methods of the
       | Builder rather than try to explain the nested dict). Feel free to
       | ignore me.
        
       | TekMol wrote:
       | 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?
        
         | myidealab wrote:
         | Were you able to run the 2nd cell in Google Colab? I get the
         | following error:                   FileNotFoundError: [Errno 2]
         | No such file or directory: '/usr/local/lib/python3.7/dist-
         | packages/numpy-1.19.5.dist-info/METADATA'
        
           | sails wrote:
           | Need to restart the runtime.
           | 
           | Runtime > Restart Runtime
        
             | myidealab wrote:
             | Thanks for the suggestion. In addition to restarting the
             | runtime, I installed numpy independently:
             | !pip install 'numpy>=1.3.0,<2.0.0' --force-reinstall
             | 
             | Now the maps work!
        
           | TekMol wrote:
           | No idea. As soon as I click on something in that Colab thing,
           | it tells me to make a Google account.
        
         | nightpool wrote:
         | Probably because it requires an unreleased HEAD version instead
         | of something from PyPi?
        
           | TekMol wrote:
           | Isn't setup.py a normal python script? Can't they put the
           | same line they have in the description ...
           | pip install git+https://github.com/abey79/vsketch#egg=vsketch
           | 
           | ... into setup.py instead?
        
             | [deleted]
        
             | marbu wrote:
             | Yes, but it's not a good practice to specify full git url
             | in setup.py, where I would expect to have sheer module name
             | and version constraints if necessary. There is a convention
             | about overriding requirements from setup.py via
             | requirements.txt file, but here the author just decided to
             | note it in a readme file instead to avoid the need to clone
             | his repository manually.
        
               | newman314 wrote:
               | So I don't do too much with Python but is it accepted
               | practice now to use Pipfile or do most folks still use
               | requirements.txt and/or setup.py?
        
               | TekMol wrote:
               | the author just decided to note it in a readme file
               | instead to avoid the need to clone his repository
               | manually
               | 
               | Isn't it the other way round? Because the dependency is
               | noted in the readme, one has to clone his repo manually?
               | 
               | If it was in the setup.py, one could just run setup.py
               | and everything would be set up.
        
         | martinky24 wrote:
         | For some reason it was commented out, and the author didn't say
         | why:
         | 
         | https://github.com/marceloprates/prettymaps/commit/c8b1f3f13...
        
       | nathancahill wrote:
       | Beautiful. I wish there was a way to simplify OSM roads. For
       | example, southbound/northbound highways are correctly stored as
       | separate roads in OSM. But to draw an atlas, it's often enough to
       | show the single highway.
        
         | maxerickson wrote:
         | There are tools to do that sort of feature generalization.
         | https://github.com/migurski/Skeletron is one that comes to
         | mind.
        
       | bhelkey wrote:
       | I love the look of this! I don't think I have a use case for this
       | library but it looks fun to play with.
        
       | pasabagi wrote:
       | This is great! I played around a bit with openstreetmap data a
       | month ago, and I couldn't find anything so straightforward.
        
       | twoslide wrote:
       | Beautiful, different from what I've seen with other OSM data.
       | Dying to be made into a web app
        
       | willsewell wrote:
       | This are beautiful.
       | 
       | 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...
        
         | dabreegster wrote:
         | Especially if you're trying to clip your entire map to some
         | boundary, rendering the ocean is hard. https://github.com/a-b-
         | street/abstreet/issues/32 has some examples of "flooded" maps
         | when the heuristics get the inversion wrong.
         | https://github.com/a-b-street/abstreet/blob/9761373c4b215485...
         | is my incomplete attempt to deal with these partial
         | multipolygons.
        
         | simon04 wrote:
         | You might want to look into OSMCoastline, a separate piece of
         | software written specifically to make the coastline usable for
         | renders: https://osmcode.org/osmcoastline/
        
         | mistrial9 wrote:
         | make a constant water layer as a seperate process; this is a
         | known pain point, land-use / land cover has some similar
         | challenges
        
       | lifeisstillgood wrote:
       | Knowledge, and _capability_ are like the surface of a balloon.
       | Each day the balloon is expanded and it is only after a while you
       | realise how far away from the surface point you are on, all the
       | other surface points have reached. I mean i toyed with python and
       | maps back in the day, and my intuition for how good looking you
       | could make one of these is completely off.
       | 
       | 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. ;-)
        
       | TheRealNGenius wrote:
       | Looks absolutely beautiful
        
       | skocznymroczny wrote:
       | Porto Alegre map reminds me of GTA: San Andreas map
        
       | hasmanean wrote:
       | I'd love to see hand drawn thematic maps (similar to amusement
       | park maps) for specific regions.
       | 
       | Maybe a marketplace for such maps would allow artists to document
       | their cities/neighborhoods.
        
         | [deleted]
        
       | avnigo wrote:
       | I don't know what I was expecting, but those really are pretty
       | maps!
       | 
       | I was hoping for some more documentation apart from the usage
       | examples, although those are much appreciated too.
        
         | cabalamat wrote:
         | > I was hoping for some more documentation
         | 
         | 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.
        
           | [deleted]
        
         | ahmedbaracat wrote:
         | Came here to just say that they are super beautiful. Amazing
         | color palettes and styles.
        
       | mistrial9 wrote:
       | python matplotlib lives another day
        
         | kzrdude wrote:
         | Every day with seaborn
        
         | bfung wrote:
         | Tangential but curious - was there discussions to replace
         | matplotlib with something else?
        
       | jimjimjimjim wrote:
       | Have you thought about building a site where users could order
       | framed posters of any address they like using the output of this
       | library? I think that would be cool
        
         | mtmail wrote:
         | https://www.mapify.cc/ ,
         | https://mapisart.com/products/personalized-map-framed and
         | there's a couple of other such services.
        
         | adamhp wrote:
         | Not only cool, but easy to monetize 8-)
        
         | maddimini wrote:
         | There are _plenty_ of such services, e.g.,
         | https://www.mapiful.com
        
           | ryantgtg wrote:
           | I looked into making a site like this a couple years ago, but
           | yeah the market already seemed saturated.
        
         | switch007 wrote:
         | If they haven't, I'm sure about 5 MVPs will be online by the
         | end of the week thanks to this comment. It definitely looks
         | like art!
        
       | lloydatkinson wrote:
       | Running it in the Google colab thing (whatever that is) results
       | in:
       | 
       | fig, ax = plt.subplots(figsize = (12, 12), constrained_layout =
       | True)
       | 
       | fig is not defined
        
         | petschge wrote:
         | Looks like you need to load matplotlib with
         | 
         | import matplotlib.pyplot as plt
        
       | smnrchrds wrote:
       | Semi-related question: what do you use for map visualizations
       | like those on Our World in Data. The maps there are well-
       | designed, with mouseover and colourization based on values. Eg:
       | https://ourworldindata.org/explorers/coronavirus-data-explor...
        
         | wiredfool wrote:
         | Pretty sure it's d3 of one form or another.
        
           | smnrchrds wrote:
           | D3 is pretty low level. I am sure the more high-level user-
           | friendly stuff use if under the hood, but I don't know where
           | to find them.
        
         | maxerickson wrote:
         | https://github.com/owid/owid-grapher
        
       | qwertox wrote:
       | They are really beautiful. I wonder how hard it would be to draw
       | them in xkcd sketch-style.
       | 
       | https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot....
        
       | swah wrote:
       | Dev is here: https://twitter.com/marceloprates_
        
       | zwieback wrote:
       | Gorgeous! I've been wanting an artistic map of Portland will
       | unleash this lib on OSM data.
        
       | protonpopsicle wrote:
       | really lovely work
        
       | vavooom wrote:
       | Very impressive. Considerable competitor to some of the mapping
       | programs available in GGPlot.
        
       | pjot wrote:
       | Osmnx[0] is is one of the most interesting and academically
       | complete packages I've come across!
       | 
       | [0]: https://github.com/gboeing/osmnx
        
       | metalliqaz wrote:
       | Those are handsome results. Cool project!
        
       | NelsonMinar wrote:
       | It's fun to see a fresh new take on how to draw maps in Python.
       | I'm still mired in 10 year old concepts from when this stuff was
       | much harder. This project just looks joyful.
        
       | Freak_NL wrote:
       | The option of not just setting a fixed colour for certain
       | features (like a building), but supplying a palette of colours
       | for the renderer to randomly use is interesting. It makes the
       | output playful. I don't think I've seen that feature before in
       | OpenStreetMap renderers.
        
         | anigbrowl wrote:
         | That contributes massively to readability.
        
       | humanistbot wrote:
       | Is this supposed to take 3-5 minutes each to generate a single
       | map? Because that is what I'm seeing in the colab notebook.
        
         | kingofpandora wrote:
         | Are you rendering a large area? OSM data can be big...
        
       | ssss999 wrote:
       | 908
        
       | agencies wrote:
       | Does anyone have a simple way to make rendered images from osm
       | data? Usually it involves postgres, but I wish there was a
       | renderer that could use the vector tiles directly...
        
         | nielsole wrote:
         | OSMs source of truth is not organized around vector tiles, i
         | believe. https://github.com/dfyz/osm-renderer might be similar
         | to what you are looking for
        
         | mistrial9 wrote:
         | if you think postgres is challenging, try mapnik directly!
        
         | mtmail wrote:
         | https://github.com/systemed/tilemaker can generate vector tiles
         | directly from *.osm.pbf files. Then serve the vector tiles with
         | leaflet+mapbox-gl-leaflet, mapbox gl js, openlayers 3 or
         | similar. https://github.com/mapbox/awesome-vector-tiles
        
         | qwertox wrote:
         | The simplest is to fetch the OSM tiles directly (and cache
         | them!)                  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.
         | 
         | [1] https://stackoverflow.com/a/28530369
        
       ___________________________________________________________________
       (page generated 2021-08-25 23:00 UTC)