Geocode-sqlite: Geocode rows in an SQLite database table
github.com
github.com
geocode-sqlite does support non-OSM hosted instances of Nominatum so find an alternative if you have large or regular geocoding tasks.
[1] https://operations.osmfoundation.org/policies/nominatim/
nominatum = Nominatum(user_agent="this-is-me", domain="nominatum.local.dev", scheme="http")
I have not tried it myself, thus if it fails, could you please report on what goes wrong there?
It's called Nominatim, not Nominatum. If you run into issues then reporting it on github repository might be the best option. It's not clear if the HN user is the author of the library.
https://postgis.net/ https://postgis.net/docs/postgis_usage.html#PostGIS_Geograph...
If approximate distances (with known error bounds that depend on lat/long) is appropriate then string prefix matching on GeoHash[1] is easy and quite beautiful in many ways.
Basically locations within the same X character string code will be within a known lat/long square of each other. The longer the string the smaller the lat/long square.
[1] https://www.movable-type.co.uk/scripts/geohash.html, https://en.wikipedia.org/wiki/Geohash
The quite simple algorithm would be to calculate the distance of each point to the reference point and use these values for filtering or sorting respectively. But there should exist more sophisticated algorithms, like prefiltering or presorting the original set before applying more complex calculations or using other types of coordinate systems as latitude/longitude.
A trivial example would be if the filtering distance is more than half of the sphere circumference; in this case we do not need to calculate anything at all, because every point must be inside the distance. Or if we are using latitude/longitude notation and our reference point is on a pole, then we can just use the latitude for sorting without the need of distance calculation. One can easily think of some other special cases where specific alorithms may be used to speed up the operation.
Furthermore, I can think of a prefiltering algorithm for the latitude/longitude notation, where I calculate the coordinates of the four points directly north, south, west and east of the reference point in the given surface distance. Let us call them the "Noth point, "South point", "West point" and "East point". Then I exclude all points with coordinates west of the West point, east from the East point, north from the North point and south from the South point. Likewise I calculate the coordinates directly north-west, north-east, south-west, and south-east of the reference point in the given surface distance; all points within the minimum latitude/longitude range are within the given surface distance. Therefore I need only to perform the full calculation for the remaining points. (Special care must be taken if we cross the equator or the zero-meridian, of course.)
This is just a simple optimization that I came up with myself. I suppose, however, that a number of experts have already thought much more deeply about this group of problems. What interests me, is to learn about their solutions. An Internet search led me, for instance, to forum posts that recomment k-d trees to determine k nearest neighbors on a sphere. But I could not find a deeper analysis of this strategy regarding its computational efficiency anywhere.
Less tongue in cheek, if you enjoy algorithms make sure to read The Art of Computer Programming.