Skip to content

docs: crs tracking example#81

Merged
jiayuasu merged 10 commits intoapache:mainfrom
MrPowers:add-crs-example
Sep 22, 2025
Merged

docs: crs tracking example#81
jiayuasu merged 10 commits intoapache:mainfrom
MrPowers:add-crs-example

Conversation

@MrPowers
Copy link
Collaborator

I'm trying to demonstrate how SedonaDB tracks CRSs and doesn't allow for operations with mismatched CRSs.

Doesn't look like this code is properly setting the CRS:

cities = sd.sql("""
SELECT * FROM (VALUES
    ('New York', ST_SetSRID(ST_GeomFromText('POINT(-8238310.24 4969803.34)'), 3857)),
    ('Los Angeles', ST_SetSRID(ST_GeomFromText('POINT(-13153204.78 4037636.04)'), 3857)),
    ('Chicago', ST_SetSRID(ST_GeomFromText('POINT(-9757148.04 5138517.44)'), 3857)))
AS t(city, geometry)""")
cities.schema
SedonaSchema with 2 fields:
  city: Utf8
  geometry: Binary

Let me know if you have any suggestions on how to fix the code!

@paleolimbot
Copy link
Member

Let me know if you have any suggestions on how to fix the code!

I believe this is caused by a DataFusion bug (all extension information in a VALUES clause are dropped). You should be able to work around this by moving the function call to the SELECT (also shorter!).

cities = sd.sql("""
SELECT city, ST_SetSRID(ST_GeomFromText(wkt), 3857) AS geometry FROM (VALUES
    ('New York', 'POINT(-8238310.24 4969803.34)'),
    ('Los Angeles', 'POINT(-13153204.78 4037636.04)'),
    ('Chicago', POINT(-9757148.04 5138517.44)'))
AS t(city, wkt)""")

@MrPowers MrPowers marked this pull request as ready for review September 17, 2025 20:20
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR creates a Jupyter notebook demonstrating CRS (Coordinate Reference System) tracking in SedonaDB, specifically showing how mismatched CRSs prevent spatial operations and how to resolve them through transformation.

Key changes:

  • Creates comprehensive CRS tracking examples showing error handling for mismatched CRSs
  • Demonstrates proper CRS conversion using ST_Transform for successful spatial joins
  • Shows real-world scenarios with different data sources (Parquet files, inline SQL data)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

"source": [
"# CRS Examples\n",
"\n",
"This example demonstrates how one table with a EPSG 4326 CRS cannot be joined with another table that uses EPSG 3857."
Copy link

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing article before 'EPSG'. Should be 'an EPSG 4326 CRS' instead of 'a EPSG 4326 CRS'.

Suggested change
"This example demonstrates how one table with a EPSG 4326 CRS cannot be joined with another table that uses EPSG 3857."
"This example demonstrates how one table with an EPSG 4326 CRS cannot be joined with another table that uses EPSG 3857."

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

"id": "5279bebd-1d8d-4f33-bcd9-2c1e93ff7221",
"metadata": {},
"source": [
"## Example #2: Joining two tables with different CRSs"
Copy link

Copilot AI Sep 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section header mentions 'different CRSs' but both tables (vermont and buildings) actually have compatible CRSs (epsg:4326 and ogc:crs84). The example should clarify that these CRSs are compatible or demonstrate an actual CRS mismatch scenario.

Suggested change
"## Example #2: Joining two tables with different CRSs"
"## Example #2: Joining two tables with nominally different but compatible CRSs\n",
"\n",
"In this example, we join two tables where one uses EPSG:4326 and the other uses OGC:CRS84. Although these CRSs are named differently, they are functionally equivalent, so the join works as expected. This demonstrates that not all differently-named CRSs are incompatible."

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not relevant anymore, but smart observation

Copy link
Member

@paleolimbot paleolimbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

docs/crs-examples.md needs to be added to the navigation in mkdocs.yml somewhere or I don't think it will be accessible.

You can render with ci/scripts/build-docs.sh. We currently include both the .md and .ipynb files for the other guides (although strictly speaking we could gitignore them).

"id": "91910e50-a5ae-4d5a-a431-62ac5fbc11ca",
"metadata": {},
"source": [
"# CRS Examples\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This abbreviation should be defined once in the title and once in the regular text and before being used.

Suggested change
"# CRS Examples\n",
"# Coordinate Reference System (CRS) Examples\n",

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this, thanks

"source": [
"# CRS Examples\n",
"\n",
"This example demonstrates how one table with a EPSG 4326 CRS cannot be joined with another table that uses EPSG 3857."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"This example demonstrates how one table with a EPSG 4326 CRS cannot be joined with another table that uses EPSG 3857."
"This example demonstrates how one table with a EPSG 4326 Coordinate Reference System (CRS) cannot be joined with another table that uses EPSG 3857."

Copy link
Member

@paleolimbot paleolimbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, although CI will fail until #108 is merged.

CI will also fail when this is merged if you don't add crs-examples.md to the navigation in mkdocs.yml.

@kadolor
Copy link
Contributor

kadolor commented Sep 20, 2025

Looks good, although CI will fail until #108 is merged.

CI will also fail when this is merged if you don't add crs-examples.md to the navigation in mkdocs.yml.

Yes, please add this notebook to the mkdocs.yml @MrPowers

@jiayuasu jiayuasu merged commit 9bc6ffe into apache:main Sep 22, 2025
4 checks passed
jiayuasu pushed a commit that referenced this pull request Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants