|
| 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. |
0 commit comments