Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for geography columns #1627

Merged
merged 1 commit into from
Dec 22, 2024

Conversation

rshk
Copy link
Contributor

@rshk rshk commented Dec 20, 2024

This addresses #1503

Tests seem to pass, at least as far as detecting the table is concerned.
I feel like this could use some more tests to test the actual tile generation, I could probably use some pointers on the best way to go about that.
I'm fairly new to Rust (and this project), so please be kind 😛

It seems to be doing a good job creating tiles for a few NOAA layers imported in a postgis database and rendered in maplibre:

Screenshot from 2024-12-19 20-16-12

Screenshot from 2024-12-19 20-19-30

@rshk
Copy link
Contributor Author

rshk commented Dec 20, 2024

As a side note, I'm getting this error when running git push:

% just clippy
cargo clippy --workspace --all-targets -- -D warnings
    Checking martin v0.15.0 (/home/samu/Projects/martin/martin)
error: unknown lint: `clippy::ref_option`
  --> martin/src/pg/utils.rs:16:10
   |
16 | #[expect(clippy::ref_option)]
   |          ^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::ref_option_ref`
   |
   = note: `-D unknown-lints` implied by `-D warnings`
   = help: to override `-D warnings` add `#[allow(unknown_lints)]`

error: could not compile `martin` (lib test) due to 1 previous error
error: Recipe `clippy` failed on line 319 with exit code 101
Exit status: 101                                                                           

@rshk rshk force-pushed the support-geography-columns branch from 9da770e to 36dcbc2 Compare December 20, 2024 01:15
@CommanderStorm
Copy link
Collaborator

CommanderStorm commented Dec 20, 2024

I'm getting this error

This is because your rust version is a bit too old for this lint.
Consider updating with rustup update

We had to allow said lint because otherwise CI failed..

@rshk
Copy link
Contributor Author

rshk commented Dec 20, 2024

Nice, that did the trick, thanks.

@nyurik
Copy link
Member

nyurik commented Dec 20, 2024

btw, we may want to disable pre commit hooks - it seems it is more of a nuisance than help

@nyurik
Copy link
Member

nyurik commented Dec 20, 2024

also, we could improve the just clippy target - if it fails, it can also print "make sure you have the latest clippy installed"

Copy link
Member

@nyurik nyurik left a comment

Choose a reason for hiding this comment

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

Nice! One possible issue - while this approach works, and does not affect existing cases, I am not sure this is the right path for the geography types -- essentially you are converting all geographies to geometries, loosing some information. This may result in bugs reported by the geography-using people of incorrect visualizations... We may need some tests that are "geography-specific" (like polygons that cross the anti-meridian, or something else similarly non-trivial?).

@@ -38,6 +39,7 @@ WITH
f_geometry_column AS geom,
srid,
type,
-- 'geometry' AS column_type
Copy link
Member

Choose a reason for hiding this comment

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

need?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's how we could distinguish between tables using a geometry vs geography column.
I initially thought we might need it, but the approach of simply casting everything to ::geometry seems to be working well, so this can be removed unless we want to expose this information to the code for some other reason.

@@ -50,6 +52,33 @@ WITH
geometry_columns.f_table_name = sic.table_name AND
geometry_columns.f_geometry_column = sic.column_name
GROUP BY 1, 2, 3, 4, 5, 6),
--
Copy link
Member

Choose a reason for hiding this comment

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

is geography metadata here substantially different from geometry to require a separate section? not a biggie, and not a blocker, but if possible - we should have just one consolidated sub-table here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are a few substantials differences here: geography columns are defined in the geography_columns table, and the name of the column containing the name of the spatial column is f_geography_column. I agree that the duplication here is not ideal, but I couldn't think of a better alternative to cover both use cases.

Perhaps one thing we could do is move the JOINs to the UNION'd table, at the cost of adding yet another "with query" block? Not sure which of the two would be more preferable.

DROP TABLE IF EXISTS table_source_geog;
CREATE TABLE table_source_geog(gid serial PRIMARY KEY, geog geography(GEOMETRY, 4326));

INSERT INTO table_source_geog(geog) values ('SRID=4326;POINT(0 0)'::geography);
Copy link
Member

Choose a reason for hiding this comment

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

we usually prefer to have the same type of elements in a table - if you mix points and linestrings, what would be the type of the MVT data? Not a blocker, but for a test we may want a few more tables like this .... although perhaps one mixed table is also good to test the results

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied this from the table_source test case, which is doing the same for geometries.
I agree that we can probably use a few more tests for the geography columns.
Any recommendations on the best approach for this? I could just copy/paste all the tests we have for geometries to run them on geographies as well, but that feels like a lot of duplication, so I was wondering if there could be a more clever way?

@rshk
Copy link
Contributor Author

rshk commented Dec 21, 2024

Nice! One possible issue - while this approach works, and does not affect existing cases, I am not sure this is the right path for the geography types -- essentially you are converting all geographies to geometries, loosing some information. This may result in bugs reported by the geography-using people of incorrect visualizations... We may need some tests that are "geography-specific" (like polygons that cross the anti-meridian, or something else similarly non-trivial?).

I don't think converting geographies to geometries would cause any issue: the main difference between geometry and geography column is how the two are treated internally by postgis, but from a user perspective the data returned in both cases should be equivalent. It's also going to be converted to carthesian (EPSG:3857) coordinates anyways, so it can be encoded in a vector tile.

I haven't tested geometries crossing the anti-meridian yet (going to do it now) but I assume they should work as well as their geometry counterparts. AFAIK it's the map renderer (maplibre) that needs to know how to draw the "shortest path" between two points; the vector tile only contains a list of points, but no other information about the path between them.

Not sure if there's a convenient way to write an automated test for that, or they can only be verified visually?
Maybe we can add a few geography objects to the demo, that can be used for verifying that.

The only place I think casting to geometry on the fly can negatively affect performance is the calc_bounds() function, since st_extent() is unlikely going to be able to use the index; #1220 seems to provide a good solution for that though, so this shouldn't be an issue once that is merged.

@nyurik
Copy link
Member

nyurik commented Dec 22, 2024

i think this is ok to merge. I would still like a few more test cases, but that could be done separately

@nyurik nyurik enabled auto-merge (squash) December 22, 2024 03:23
@nyurik nyurik merged commit be642b4 into maplibre:main Dec 22, 2024
18 checks passed
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.

3 participants