Skip to content

Commit 044491f

Browse files
adds support for geocodes: Geohash and Maidenhead (QTH/IARU)
1 parent 90e35cd commit 044491f

File tree

8 files changed

+1437
-1009
lines changed

8 files changed

+1437
-1009
lines changed

README.md

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44

55
Python-based CLI tool to index raster files to DGGS in parallel, writing out to Parquet.
66

7-
Currently this supports the H3 and rHEALPix DGGSs. Contributions (particularly for additional DGGSs), suggestions, bug reports and strongly worded letters are all welcome.
7+
Currently this supports the following DGGSs and geocode systems:
8+
9+
- [H3](https://h3geo.org/)
10+
- [rHEALPix](https://datastore.landcareresearch.co.nz/dataset/rhealpix-discrete-global-grid-system)
11+
- [Geohash](https://en.wikipedia.org/wiki/Geohash)
12+
- [Maidenhead Locator System](https://en.wikipedia.org/wiki/Maidenhead_Locator_System)
13+
14+
Contributions (particularly for additional DGGSs), suggestions, bug reports and strongly worded letters are all welcome.
815

916
![Example use case for raster2dggs, showing how an input raster can be indexed at different DGGS resolutions, while retaining information in separate, named bands](docs/imgs/raster2dggs-example.png "Example use case for raster2dggs, showing how an input raster can be indexed at different H3 resolutions, while retaining information in separate, named bands")
1017

@@ -23,8 +30,11 @@ Options:
2330
--help Show this message and exit.
2431
2532
Commands:
26-
h3 Ingest a raster image and index it to the H3 DGGS.
27-
rhp Ingest a raster image and index it to the rHEALPix DGGS.
33+
geohash Ingest a raster image and index it using Geohash.
34+
h3 Ingest a raster image and index it to the H3 DGGS.
35+
maidenhead Ingest a raster image and index it using the Maidenhead...
36+
rhp Ingest a raster image and index it to the rHEALPix DGGS.
37+
2838
```
2939

3040
```
@@ -96,6 +106,9 @@ Output is in the Apache Parquet format, a directory with one file per partition.
96106

97107
For a quick view of your output, you can read Apache Parquet with pandas, and then use h3-pandas and geopandas to convert this into a GeoPackage for visualisation in a desktop GIS, such as QGIS. The Apache Parquet output is indexed by the DGGS column, so it should be ready for association with other data prepared in the same DGGS.
98108

109+
<details>
110+
<summary>For rHEALPix DGGS output...</summary>
111+
99112
```python
100113
>>> import pandas as pd
101114
>>> import h3pandas
@@ -118,6 +131,10 @@ h3_09
118131
[5656 rows x 10 columns]
119132
>>> o.h3.h3_to_geo_boundary().to_file('~/Downloads/Sen2_Test_h3-9.gpkg', driver='GPKG')
120133
```
134+
</details>
135+
136+
<details>
137+
<summary>For rHEALPix DGGS output...</summary>
121138

122139
For rHEALPix DGGS output, you can use [`rHP-Pandas`](https://github.com/manaakiwhenua/rHP-Pandas):
123140

@@ -143,6 +160,54 @@ R88727068808 22 39 43 80 146 163 177 198 165 83
143160
[223104 rows x 10 columns]
144161
>>> o.rhp.rhp_to_geo_boundary().to_file('~/Downloads/Sen2_Test_rhp-11.gpkg', driver='GPKG')
145162
```
163+
</details>
164+
165+
<details>
166+
<summary>For Geohash output...</summary>
167+
168+
For Geohash output, you can use [`python-geohash`] or other similar Geohash library. Example:
169+
170+
```python
171+
import pandas as pd
172+
import geohash
173+
from shapely.geometry import Point, box
174+
import geopandas as gpd
175+
o = pd.read_parquet('./tests/data/output/8/sample_geohash')
176+
177+
178+
def geohash_to_geometry(gh, mode="polygon"):
179+
lat, lon, lat_err, lon_err = geohash.decode_exactly(gh)
180+
181+
if mode == "point":
182+
return Point(lon, lat)
183+
elif mode == "polygon":
184+
return box(lon - lon_err, lat - lat_err, lon + lon_err, lat + lat_err)
185+
else:
186+
raise ValueError("mode must be 'point' or 'polygon'")
187+
188+
o["geometry"] = o["geohash_08"].apply(lambda gh: geohash_to_geometry(gh, mode="polygon"))
189+
190+
'''
191+
band geohash_08 1 2 3 geometry
192+
0 u170f2sq 0 0 0 POLYGON ((4.3238067626953125 52.16686248779297...
193+
1 u170f2sr 0 0 0 POLYGON ((4.3238067626953125 52.16703414916992...
194+
2 u170f2sw 0 0 0 POLYGON ((4.324150085449219 52.16686248779297,...
195+
3 u170f2sx 0 0 0 POLYGON ((4.324150085449219 52.16703414916992,...
196+
4 u170f2sy 0 0 0 POLYGON ((4.324493408203125 52.16686248779297,...
197+
... ... .. .. .. ...
198+
232720 u171mc2g 0 0 0 POLYGON ((4.472808837890625 52.258358001708984...
199+
232721 u171mc2h 0 0 0 POLYGON ((4.471778869628906 52.25852966308594,...
200+
232722 u171mc2k 0 0 0 POLYGON ((4.4721221923828125 52.25852966308594...
201+
232723 u171mc2s 0 0 0 POLYGON ((4.472465515136719 52.25852966308594,...
202+
232724 u171mc2u 0 0 0 POLYGON ((4.472808837890625 52.25852966308594,...
203+
204+
[232725 rows x 5 columns]
205+
'''
206+
207+
gdf = gpd.GeoDataFrame(o, geometry="geometry", crs="EPSG:4326")
208+
gdf.to_file('sample.gpkg')
209+
```
210+
</details>
146211

147212
## Installation
148213

@@ -196,7 +261,7 @@ Two sample files have been uploaded to an S3 bucket with `s3:GetObject` public p
196261
- `s3://raster2dggs-test-data/Sen2_Test.tif` (sample Sentinel 2 imagery, 10 bands, rectangular, Int16, LZW compression, ~10x10m pixels, 68.6 MB)
197262
- `s3://raster2dggs-test-data/TestDEM.tif` (sample LiDAR-derived DEM, 1 band, irregular shape with null data, Float32, uncompressed, 10x10m pixels, 183.5 MB)
198263

199-
You may use these for testing. However you can also test with local files too, which will be faster.
264+
You may use these for testing. However you can also test with local files too, which will be faster. A good, small (5 MB) sample image is available [here](https://github.com/mommermi/geotiff_sample).
200265

201266
## Example commands
202267

0 commit comments

Comments
 (0)