manaakiwhenua / rhealpixdggs-py

rHEALPixdggs-py implements code to both define an rHEALPix DGGS Reference System and to perform topological queries on its Identfiers. Our roadmap is for v1.0 to be fully compliant with OGC Topic 21 v2.0 / ISO 19170-1:2020.
GNU Lesser General Public License v3.0
18 stars 4 forks source link

Use as a polygon geohash? #13

Open weiji14 opened 3 years ago

weiji14 commented 3 years ago

Kia ora! I realize this library is still young but just had a question on using rHEALPix as a sortable polygon "geohash". I've been looking for a way to consistently index/name some polygon features (whose outlines can change slightly over time), and tried using the rhealpixdggs.conversion.get_finest_containing_cell added in #12, but it doesn't seem to work for some of the polygons I've tried.

import geopandas as gpd
import rhealpixdggs.conversion

gdf: gpd.GeoDataFrame = gpd.read_file(filename="lakeconway.geojson")
polygon: shapely.geometry.Polygon = gdf.loc[0].geometry

rhealpixdggs.conversion.get_finest_containing_cell(polygon=polygon)
# returns None instead of string like S1234567

Sample polygon is lakeconway.geojson.zip (using EPSG:4326). This is a location rather close to the South Pole (about Lat: 84.°S, Lon: 150°W). My question is whether rHEALPix-py is able to handle polar projections with some tweaking, or if there are some inherent limitations with the system.

alpha-beta-soup commented 8 months ago

This is a key usecase, a clear method to do this will be part of v0.6.0.

ppKrauss commented 6 months ago

Hello, we can collaborate with the "binary Geohash", as described for example in this article
https://mmcloughlin.com/posts/geohash-assembly
PS: is possible to adapt to binary, the neighbours operations are also fast and non-geometrical operations, as demonstrated here.

Ideally, we would also like to use PostgreSQL/PostGIS instead of Python. With PostGIS we can use PROJ's rHEALPix by registered SRID for inverse.

Binary Geohash and human representations

Other bases, in addition to the classic Geohash base32, can be used to express the cell identifier as a geocode, see for example base32nvu or base16h at this interactive illustration:

image

image

So, we can use a system of square grids with \~23 hierarchical levels, very useful for multifunctional applications.

For a complete, bit by bit cell representation... We can duplicate the number of hierarchical levels (\~45) using the "degenerated grid" (rectangular), to express base32 and to quadtree applications:

image

Any "integer level", with indexes i, can be transformed into a "half level" with indexes j:

image

PS: the transformation is valid also for Hilbert curves, so is possible to express a "Hilbert Geohash", when application need continuous intervals — and the application is not concerned with aperiodicity in the degenerated grid.


Practical example of the use of the binary Geohash encode, with PostgreSQL in bigint (64 bits integer) or varbit type, and translating it to humans with base16h, for a postal address point in Brasil, national grid:

image