Hacker News new | ask | show | jobs
by willsewell 1761 days ago
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...

4 comments

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.
Potentially dumb suggestion: what if one just declares anything that has a significant chunk of non-bridge or non-tunnel street on it land? It's not a universal solution but perhaps sufficient for the application?
I recently made a map (using Generic Mapping Tools) of one of the Aleutian Islands in Alaska, for one of my dad’s grad students to use in a paper. That would constitute a good example of where you couldn’t just tell my # of built structures (since at certain zoom levels, there are none!)
Sure, but are you likely to have users want to A/B test traffic light configurations there? My suggestion was very specific to the application in question.
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/
A simple solution is paint the sea with triangles of which one side is perfectly horizontal. And always work bottom to top.

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.

make a constant water layer as a seperate process; this is a known pain point, land-use / land cover has some similar challenges