Skip to content

Commit 308ad4a

Browse files
committed
feat: Add example 18 for geo predicates with WKT points and polygons, update workflows and documentation
1 parent 5339bf2 commit 308ad4a

6 files changed

Lines changed: 568 additions & 10 deletions

File tree

.github/workflows/test-python-examples.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,12 @@ jobs:
402402
timeout_duration=900
403403
example_jvm_args=""
404404
;;
405+
"18_geo_predicates_wkt.py")
406+
example_args=""
407+
example_name="$example (geo predicates with WKT points and polygons)"
408+
timeout_duration=900
409+
example_jvm_args=""
410+
;;
405411
"19_hash_index_exact_match.py")
406412
example_args=""
407413
example_name="$example (hash index exact-match workflow)"
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# 18 - Geo Predicates With WKT Points And Polygons
2+
3+
[View source code]({{ config.repo_url }}/blob/{{ config.extra.version_tag }}/bindings/python/examples/18_geo_predicates_wkt.py){ .md-button }
4+
5+
This example demonstrates the current SQL-first geospatial surface in the Python
6+
bindings. It deliberately uses WKT stored in `STRING` properties and exercises the same
7+
`geo.*` predicates already covered by the Java engine tests:
8+
9+
- creating a `GEOSPATIAL` index on point coordinates
10+
- storing depots as WKT `POINT` values
11+
- storing service areas as WKT `POLYGON` values
12+
- running direct `geo.within(...)` and `geo.intersects(...)` sanity checks
13+
- querying indexed point records with polygon filters
14+
- querying stored polygon records for overlap
15+
- reopening the database to verify persisted geospatial index metadata
16+
- dropping the index and rerunning the same filter to show full-scan fallback
17+
18+
## Run
19+
20+
From `bindings/python/examples`:
21+
22+
```bash
23+
python3 18_geo_predicates_wkt.py
24+
```
25+
26+
With a custom database path:
27+
28+
```bash
29+
python3 18_geo_predicates_wkt.py --db-path ./my_test_databases/geo_demo
30+
```
31+
32+
## Notes
33+
34+
- The example stays SQL-first on purpose. There is no separate Python geometry object
35+
API.
36+
- Geospatial values are stored as WKT strings and interpreted in queries via `geo.*`.
37+
- `GEOSPATIAL` indexes are for spatial predicates, not uniqueness constraints.
38+
- The example includes both the indexed path and the post-`DROP INDEX` fallback path so
39+
the script shows that the index changes performance characteristics, not result
40+
correctness.
41+
- If the packaged runtime does not include geospatial SQL functions or `GEOSPATIAL`
42+
index support, the script prints a short explanation and exits.
43+
44+
## Why This Example Exists
45+
46+
The Java engine already has focused geospatial coverage for:
47+
48+
- `CREATE INDEX ... GEOSPATIAL`
49+
- indexed `geo.within(...)` queries over stored WKT points
50+
- indexed `geo.intersects(...)` queries
51+
- fallback evaluation when the index is absent
52+
- persistence across reopen
53+
54+
This Python example mirrors those behaviors with the public bindings API so the examples
55+
set includes a dedicated geospatial workflow without introducing a new Python-side DSL.

bindings/python/docs/examples/index.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ Four-way graph-ingest comparison. Repository guidance from these experiments is
6464
**[17 - Time Series End-to-End](17_timeseries_end_to_end.md)**
6565
SQL-first time-series workflow covering type creation, tagged inserts, range queries, and hourly bucket aggregation.
6666

67+
**[18 - Geo Predicates With WKT Points And Polygons](18_geo_predicates_wkt.md)**
68+
SQL-first geospatial workflow covering WKT storage, GEOSPATIAL indexes, indexed `within` / `intersects`, polygon overlap queries, and fallback after dropping the index.
69+
6770
**[19 - Hash Index Exact-Match Lookup Workflow](19_hash_index_exact_match.md)**
6871
SQL-first HASH index workflow covering unique and non-unique exact-match lookups, schema inspection, and duplicate-key rejection.
6972

@@ -90,7 +93,8 @@ python 01_simple_document_store.py
9093
10. **Hybrid Queries** (13) - Combined SQL, graph, and vector workflow
9194
11. **Lifecycle And Ingest Benchmarks** (14/15/16) - Embedded lifecycle timing and ingest comparisons
9295
12. **Time Series SQL Workflow** (17) - Tagged samples, range queries, and bucket aggregation from Python
93-
13. **Hash Index Workflow** (19) - Exact-match HASH indexes, missing-key behavior, and duplicate protection
96+
13. **Geo Predicate Workflow** (18) - WKT points and polygons, indexed spatial filters, and fallback semantics
97+
14. **Hash Index Workflow** (19) - Exact-match HASH indexes, missing-key behavior, and duplicate protection
9498

9599
---
96100

0 commit comments

Comments
 (0)