vector2dggs 0.26.2__tar.gz → 0.27.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/PKG-INFO +4 -2
  2. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/README.md +3 -1
  3. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/pyproject.toml +1 -1
  4. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/vector2dggs/common.py +41 -8
  5. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/COPYING +0 -0
  6. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/COPYING.LESSER +0 -0
  7. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/vector2dggs/__init__.py +0 -0
  8. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/vector2dggs/a5.py +0 -0
  9. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/vector2dggs/cli.py +0 -0
  10. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/vector2dggs/cli_factory.py +0 -0
  11. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/vector2dggs/constants.py +0 -0
  12. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/vector2dggs/geohash.py +0 -0
  13. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/vector2dggs/h3.py +0 -0
  14. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/vector2dggs/indexerfactory.py +0 -0
  15. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/vector2dggs/indexers/__init__.py +0 -0
  16. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/vector2dggs/indexers/a5vectorindexer.py +0 -0
  17. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/vector2dggs/indexers/geohashvectorindexer.py +0 -0
  18. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/vector2dggs/indexers/h3vectorindexer.py +0 -0
  19. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/vector2dggs/indexers/rhpvectorindexer.py +0 -0
  20. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/vector2dggs/indexers/s2vectorindexer.py +0 -0
  21. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/vector2dggs/indexers/vectorindexer.py +0 -0
  22. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/vector2dggs/katana.py +0 -0
  23. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/vector2dggs/rHP.py +0 -0
  24. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/vector2dggs/s2.py +0 -0
  25. {vector2dggs-0.26.2 → vector2dggs-0.27.0}/vector2dggs/spikes.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vector2dggs
3
- Version: 0.26.2
3
+ Version: 0.27.0
4
4
  Summary: CLI DGGS indexer for vector geospatial data
5
5
  License: LGPL-3.0-or-later
6
6
  License-File: COPYING
@@ -51,7 +51,7 @@ Description-Content-Type: text/markdown
51
51
 
52
52
  # vector2dggs
53
53
 
54
- [![pypi](https://img.shields.io/pypi/v/vector2dggs?label=vector2dggs)](https://pypi.org/project/vector2dggs/)
54
+ [![pypi](https://img.shields.io/pypi/v/vector2dggs?label=vector2dggs)](https://pypi.org/project/vector2dggs/) [![DOI](https://zenodo.org/badge/619451613.svg)](https://doi.org/10.5281/zenodo.24149888)
55
55
 
56
56
  Python-based CLI tool to index vector files to DGGS in parallel, writing out to Parquet.
57
57
 
@@ -239,6 +239,8 @@ So `intersects` and `within` are exact with respect to each backend's own model
239
239
 
240
240
  Output is in the Apache Parquet format, a directory with one file per partition. With `--geo point` or `--geo polygon` output will be written as GeoParquet (v1.1.0) with the respective geometry types. GeoParquet can be visualised using desktop GIS tools.
241
241
 
242
+ Within each file, rows are sorted by cell ID and the cell ID column is written with Parquet's delta encoding (`DELTA_BINARY_PACKED` for `--cell-id uint64`, `DELTA_BYTE_ARRAY` for strings). Sorted cell IDs differ from their neighbours by small, regular increments, so the identifier column, which would otherwise dominate a file, costs a few bits per row. These are standard Parquet (v2) encodings, read by pyarrow, DuckDB, Polars, Spark, GDAL and R's arrow among others.
243
+
242
244
  The Apache Parquet output is indexed by an ID column (which you can specify), so it should be ready for two intended use-cases:
243
245
  - Joining attribute data from the original feature-level data onto computed DGGS cells.
244
246
  - Joining other data to this output on the DGGS cell ID. (The output has a column like `{dggs}_\d`, e.g. `h3_09` or `h3_12` according to the target resolution, zero-padded to account for the maximum resolution of the DGGS).
@@ -1,6 +1,6 @@
1
1
  # vector2dggs
2
2
 
3
- [![pypi](https://img.shields.io/pypi/v/vector2dggs?label=vector2dggs)](https://pypi.org/project/vector2dggs/)
3
+ [![pypi](https://img.shields.io/pypi/v/vector2dggs?label=vector2dggs)](https://pypi.org/project/vector2dggs/) [![DOI](https://zenodo.org/badge/619451613.svg)](https://doi.org/10.5281/zenodo.24149888)
4
4
 
5
5
  Python-based CLI tool to index vector files to DGGS in parallel, writing out to Parquet.
6
6
 
@@ -188,6 +188,8 @@ So `intersects` and `within` are exact with respect to each backend's own model
188
188
 
189
189
  Output is in the Apache Parquet format, a directory with one file per partition. With `--geo point` or `--geo polygon` output will be written as GeoParquet (v1.1.0) with the respective geometry types. GeoParquet can be visualised using desktop GIS tools.
190
190
 
191
+ Within each file, rows are sorted by cell ID and the cell ID column is written with Parquet's delta encoding (`DELTA_BINARY_PACKED` for `--cell-id uint64`, `DELTA_BYTE_ARRAY` for strings). Sorted cell IDs differ from their neighbours by small, regular increments, so the identifier column, which would otherwise dominate a file, costs a few bits per row. These are standard Parquet (v2) encodings, read by pyarrow, DuckDB, Polars, Spark, GDAL and R's arrow among others.
192
+
191
193
  The Apache Parquet output is indexed by an ID column (which you can specify), so it should be ready for two intended use-cases:
192
194
  - Joining attribute data from the original feature-level data onto computed DGGS cells.
193
195
  - Joining other data to this output on the DGGS cell ID. (The output has a column like `{dggs}_\d`, e.g. `h3_09` or `h3_12` according to the target resolution, zero-padded to account for the maximum resolution of the DGGS).
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "vector2dggs"
3
- version = "0.26.2"
3
+ version = "0.27.0"
4
4
  description = "CLI DGGS indexer for vector geospatial data"
5
5
  authors = [
6
6
  "James Ardo <ardoj@landcareresearch.co.nz>",
@@ -1,4 +1,5 @@
1
1
  import contextlib
2
+ import io
2
3
  import json
3
4
  import logging
4
5
  import math
@@ -631,6 +632,32 @@ def _drop_duplicate_cells(
631
632
  return kept.drop_columns([const.EDGE_COLUMN]) if edged else kept
632
633
 
633
634
 
635
+ def _cell_column_encoding(schema: pa.Schema, cell_col: str) -> dict[str, Any]:
636
+ """pyarrow writer options that delta-encode the cell ID column.
637
+
638
+ Sorted cell IDs step by small regular increments (or share long prefixes,
639
+ as strings), which DELTA_BINARY_PACKED / DELTA_BYTE_ARRAY store in a few
640
+ bits each; the default encoding stores them whole. Naming an encoding
641
+ requires dictionary encoding to be listed per column, so every other leaf
642
+ column is named, keeping the default for all of them.
643
+ """
644
+ buf = io.BytesIO()
645
+ pq.write_table(schema.empty_table(), buf)
646
+ leaves = pq.ParquetFile(buf).schema
647
+ others = [
648
+ leaves.column(i).path
649
+ for i in range(len(leaves))
650
+ if leaves.column(i).path != cell_col
651
+ ]
652
+ integer = pa.types.is_integer(schema.field(cell_col).type)
653
+ return {
654
+ "use_dictionary": others,
655
+ "column_encoding": {
656
+ cell_col: "DELTA_BINARY_PACKED" if integer else "DELTA_BYTE_ARRAY"
657
+ },
658
+ }
659
+
660
+
634
661
  def _merge_partition_files(
635
662
  partition_dir: Path,
636
663
  compression: str,
@@ -644,8 +671,9 @@ def _merge_partition_files(
644
671
  ) -> tuple[int, set[tuple[Any, ...]]]:
645
672
  """
646
673
  Merges all Parquet files within a single hive partition directory into one
647
- file, dropping any duplicate (feature, cell) rows and returning how many
648
- were dropped together with the feature ids that survived. Preserves and correctly aggregates GeoParquet 'geo' metadata
674
+ file, sorted by cell ID with the cell column delta-encoded, dropping any
675
+ duplicate (feature, cell) rows and returning how many were dropped
676
+ together with the feature ids that survived. Preserves and correctly aggregates GeoParquet 'geo' metadata
649
677
  (bbox, geometry_types) if present. When a compactor is given, the merged
650
678
  rows are compacted here — the hive write already routes a parent cell's
651
679
  every row into this directory, and the resolution floor stops compaction
@@ -655,7 +683,7 @@ def _merge_partition_files(
655
683
 
656
684
  Deduplication belongs here because a cell and its duplicates share a
657
685
  parent, so the hive write has already gathered them into this one
658
- directory. A single-file directory with nothing to drop is left alone.
686
+ directory.
659
687
  """
660
688
  compacting = indexer is not None
661
689
  files = sorted(partition_dir.glob("*.parquet"))
@@ -710,13 +738,9 @@ def _merge_partition_files(
710
738
  tables = [t.cast(unified_schema) for t in tables]
711
739
  table = pa.concat_tables(tables)
712
740
 
713
- edged = const.EDGE_COLUMN in table.column_names
714
741
  resolved = _drop_duplicate_cells(table, id_fields, dggs_col)
715
742
  dropped = table.num_rows - resolved.num_rows
716
743
  table = resolved
717
- if len(files) == 1 and not compacting and not dropped and not edged:
718
- # nothing to merge and nothing to drop: leave the file as written
719
- return 0, _ids_in(table, id_fields)
720
744
 
721
745
  if base_geo_meta is not None:
722
746
  col_meta = base_geo_meta["columns"]["geometry"].copy()
@@ -766,8 +790,17 @@ def _merge_partition_files(
766
790
  if geom_fn is not None:
767
791
  table = _with_geoparquet_metadata(table)
768
792
 
793
+ # Cell ID order: the delta-encoded ID column and the compression of every
794
+ # other column both depend on neighbours being adjacent, and neither the
795
+ # staged files nor compaction's output are in any particular order.
796
+ table = table.sort_by(dggs_col)
769
797
  merged = partition_dir / f"part.0-{uuid4().hex}.parquet"
770
- pq.write_table(table, merged, compression=compression)
798
+ pq.write_table(
799
+ table,
800
+ merged,
801
+ compression=compression,
802
+ **_cell_column_encoding(table.schema, dggs_col),
803
+ )
771
804
  for f in files:
772
805
  f.unlink()
773
806
  return dropped, _ids_in(table, id_fields)
File without changes