Readit News logoReadit News
westnordost commented on Mapping latitude and longitude to country, state, or city   austinhenley.com/blog/coo... · Posted by u/azhenley
jillesvangurp · 7 months ago
Nice approach. It reminds me of an approach I saw used to resolve coordinates to countries. Instead of loading all country polygons, the team created a bitmap and used colors to map each pixel to a country code. The bitmap wasn't super large and compresses pretty nicely in png format. This worked well enough and it dumbed down the country lookup to simply figuring out the color for a coordinate. Neat trick. And you could probably figure out if you are dealing with an edge case by simply looking at neighboring pixels and fall back to something more expensive if you hit one of those.

And of course with edge cases, there are lots of them but mostly it's fine. One case that comes to mind is that of the border town of Baarle-Nassau On the border with the Netherlands and Belgium. This village has some of the weirdest borders in the world. There are Belgian exclaves inside Dutch enclaves. In some cases the border runs through houses and you can enter in one country and leave in another. Some of the exclaves are just a few meters. There are a few more examples like this around the world.

Another issue is the fractal nature of polygons. I once found a polygon for New Zealand that was around 200MB that broke my attempts to index it. This doesn't matter of course for resolving country codes because it is an island. But it's a reason I implemented the Douglas Peucker algorithm to simplify the polygon mentioned in the article at some point.

westnordost · 7 months ago
The bitmap approach you describe allows for immediate (i.e. O(1) ) lookup of region by coordinate, which is pretty neat. Space-efficiency-wise, a bitmap (+ index that maps color to country) might not be the most efficient data structure, though, as there are more than 256 countries, so you already need 16 bits for each pixel instead of 8. Then, you have the additional complexity of if you actually want the bitmap to be viewable by humans, you need to make sure that the colors for neighbouring countries at least are sufficiently distinct.

Anyway, a Kotlin library I wrote uses a similar technique to make requests for the majority of locations immediate, while also handling the edge cases - i.e. when querying a location near a border.

https://github.com/westnordost/countryboundaries (also available in Rust)

What it does is to slice up the input geometry (e.g. a GeoJson) into many small cells in a raster. So, when querying for a location, one doesn't need to do point-in-polygon checks for potentially huge polygons, but just for those little slices that are in the cell one is querying for. And of course, if a country completely covers a cell, we don't even need to do any point-in-polygon check anymore. All this slicing is done in a preprocessing step, so the actual library consumes a serialized data structure that is already in this sliced-up format.

I needed it to be fast because in my app I display a lot of POIs on the map for which there is logic that is dependent on in which country/state the POI is located.

westnordost commented on What's New in Kotlin 2.0.0   kotlinlang.org/docs/whats... · Posted by u/farmerbb
smallerfish · 2 years ago
I'm a big fan of Kotlin, but the developer experience in the IDE has been pretty rocky recently, various of their secondary libraries are semi-abandoned, and their ecosystem documentation is a mixed bag at best. My ideal for the next 12 months would be for them to focus solely on quality. There's incredible potential, but they're going to shoot themselves in the foot if they don't get on top of this soon.
westnordost · 2 years ago
Are you thinking of certain secondary libraries in particular?
westnordost commented on What's New in Kotlin 2.0.0   kotlinlang.org/docs/whats... · Posted by u/farmerbb
fifteen1506 · 2 years ago
I noticed [JetBrains] appears to have an UI framework which works on all 3 desktop OS and 2 mobile OS.

Does anyone have hands-on experience?

westnordost · 2 years ago
You probably mean Compose Multiplatform?

That is a fork, or rather, extension to Jetpack Compose, Google's declarative UI framework for Android. It uses Skia for rendering but has an the identical API to Jetpack Compose, hence from the point of view of a framework user, there is nothing new about it (other than that it works on Android, iOS, desktop OSs and web).

westnordost commented on Overpass Turbo: A Web Based Data Mining Tool for OpenStreetMap   overpass-turbo.eu/... · Posted by u/stefankuehnel
westnordost · 2 years ago
Regarding data mining tools for OpenStreetMap, there is also a tool with which one can use SPARQL syntax. This means that one could conflate data with wikidata or other data sources easily, too:

QLever: https://qlever.cs.uni-freiburg.de/osm-planet

Actually, there are two. Sophox is around for longer:

Sophox: https://sophox.org/

westnordost commented on OpenStreepMap 2012 vs. 2022   2012.osmz.ru/#15/40.7822/... · Posted by u/curiousfab
hashtag-til · 3 years ago
I wonder how to go about to collaborate to the OSM ecosystem with code. Does anyone know what are the cool projects within OSM in C/C++? (i.e. not web stuff)
westnordost · 3 years ago
The most accessible general-purpose map app for end users (Android and iOS) is written in C/C++. This is pretty high on the cool and useful scale: https://organicmaps.app/

Both map renderers Tangram-ES and Maplibre-GL - https://github.com/tangrams/tangram-es and - https://github.com/maplibre/maplibre-gl-native are also written in C/C++.

Finally, most routing software, such as OSRM or Valhalla are written in C/C++.

westnordost commented on In Defense of OpenStreetMap's Data Model   stevecoast.substack.com/p... · Posted by u/SteveCoast
westnordost · 4 years ago
Just for context, here is the current OSM data model in a nutshell:

There are three data types - nodes, ways and relations. All of the three can have any number of "tags" (i.e. a map<string, string>), which define their semantic meaning. For example, a way with `barrier=fence` is a fence. This stuff is documented in the openstreetmap wiki.

A node is a point with a longitude and a latitude.

A way is a sequence of nodes.

A relation is a collections of any number of nodes, ways or other relations. Each member of this collection can be assigned a "role" (string). Again, the semantics of what each role means is documented in the openstreetmap wiki.

To modify data, simply new versions of the edited data are uploaded via the API.

---

The most prominent point that stands out here is that only nodes have actual geometry.

This means that...

1. to get the geometry of a way (e.g a building, a road, a landuse, ...), data users first need to get the locations of all the nodes the way references. For relations, it is even one more step.

2. in order to edit the course of a way, editors actually edit the location of the nodes of which the way consists of, not the way itself. This means (amongst other things) that the VCS history of that way does not contain such changes

westnordost commented on Maplibre: community-driven Mapbox GL fork   maplibre.org/... · Posted by u/klokan
DrBenCarson · 5 years ago
Forgive me if obvious—where are you pulling the underlying data from? Is the data itself OS licensed?
westnordost · 5 years ago
Where the SDK pulls its data from is not hardcoded.

The SDK is just a library, used to render vector map tiles, usually in the MVT-format: https://docs.mapbox.com/vector-tiles/specification/

Most maps rendered with such an SDK are based on OpenStreetMap data.

westnordost commented on Maplibre: community-driven Mapbox GL fork   maplibre.org/... · Posted by u/klokan
westnordost · 5 years ago
If it is true that Apple will soon drop OpenGL and only support Metal:

Will the SDK also work on iOS and Mac then, i.e. has Metal support?

westnordost commented on StreetComplete: Easy to use editor of OpenStreetMap data   github.com/streetcomplete... · Posted by u/rjzzleep
blendergeek · 5 years ago
If you like Street Complete, please consider sponsoring it on Libera Pay [0], Github Sponsors [1], or Patreon [2]. For the last year, it was funded by OSMF by a grant to help develop alternative OSM editors. This grant has come to an end so they no longer have funding other than donations.

[0] https://liberapay.com/westnordost

[1] https://github.com/sponsors/westnordost

[2] https://www.patreon.com/westnordost

westnordost · 5 years ago
(Author here:) I got many emails about new patrons/sponsors yesterday and was astonished where this was all coming from, now I know!

Thank you for posting this and thank you all for your support! This helps me a lot to find the time to maintain the app, in general a kind of work that I think is often underestimated, also in terms of time invested.

For example, Google recently kicked the app out of their app store for spurious reasons so I had to act quickly to get it back ASAP. I kept track of the issue (and am still updating it, it's not over yet) here:

https://github.com/streetcomplete/StreetComplete/issues/2909

This may be an interesting read and shed some light on how the Google Play Store team works and handles policy violations and appeals.

westnordost commented on StreetComplete: Easy to use editor of OpenStreetMap data   github.com/streetcomplete... · Posted by u/rjzzleep
pabs3 · 5 years ago
Is there anything like this for the PinePhone or Librem 5?
westnordost · 5 years ago
Doesn't it run in anbox?

u/westnordost

KarmaCake day19June 19, 2021View Original