-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Support geometric types for postgres #166
Comments
All typesOID sources: https://github.com/postgres/postgres/blob/2743d9ae4a490a7d96b5c19d50694bd101a87dc8/src/include/catalog/pg_type.dat Text encoding descriptions: https://www.postgresql.org/docs/current/datatype-geometric.html For text encoding, notice that several types share similar formats, so you may not need exactly one function per type. Binary encoding implementation in C: https://github.com/postgres/postgres/blob/2743d9ae4a490a7d96b5c19d50694bd101a87dc8/src/backend/utils/adt/geo_ops.c All values are big (network)-endian encoded.
|
|
I just left a comment on the I would frankly find it irritating to need two separate features for 2D and 3D points, but on the other hand I'm not sure if it can be avoided, since PostgreSQL itself implements a 2D point, while something like PostGIS implements others. So perhaps it's just a question of I'd be personally tempted to start with the |
In the geospatial world, geometries are almost exclusively used together with the PostGIS extension. So implementing the PostgreSQL geometric types has not very high priority. As mentioned, geozero supports encoding/decoding PostGIS geometries with SQLx (example). |
OK, so it sounds like my first task should be to extend Given that you need to enable the extension As for native PostgreSQL geometries, I can hopefully come back to this after I get a solid grasp on the |
@pka, IDK maybe I'm just missing something, but I cannot get the example to work in my application, and all the tests for |
@nixpulvis The PostGIS tests were broken indeed. Here are the setup instructions: https://github.com/georust/geozero/blob/master/geozero/tests/data/postgis.sql#L1. Please report any failures in the geozero repo. |
I'm not sure with this given example how to make sqlx and geozero play nicely with a struct, though? Having a field with |
@bbqsrc if you want to read a geometry as part of a struct, you have to use |
I'm not sure why this issue drifted to geospatial support when the OP clearly meant only geometric support? Also, did you note the pull request by @qtbeee for support of geometric types? In fact, @abonander actually mentioned that this was nothing to do with geospatial support in the conversation on that pull request. I'm aware that @pka said:
But note that he (correctly) mentioned that this was the case in what he calls the geospatial world. There are use cases (such as image and document analysis) which require geometric support that have nothing to do with GIS. I therefore respectfully disagree with the implementation of geometric types having a low priority simply because they're less important to geoinformatics. I suggest starting a new issue for geospatial support and making this ticket about Postgres Geometry types as the OP intended. |
I'm sorry for causing some drifting here. My main issue was that I needed 3D points, which unfortunately aren't supported without extensions. I wouldn't say that 3D points are fundamentally any more geospatial than geometrical, you just happen to need PostGIS to get 3D points. I wasn't sure if there was some desire to unify the types between "native" and PostGIS primitives. |
Are there any workarounds for just inserting a point into a new row? Should I just use unchecked? |
Given how often we've run into semver issues with using external crates for data modeling, I think I'd rather just provide bespoke structs for mapping these types. |
Just for reference, I could not get the I spent a lot of time trying to get the macro to work fruitlessly, while the function worked fine. Not complaining! Sqlx is great! Thank you so much! Just pointing out for others running into the same issue, since it wasn't explicitly pointed out here. |
Hi, I would very much like to contribute geometry type support (and postgis type support, if wanted) - but I am a bit confused about the current state of affairs? Is postgis support natively in sqlx wanted? (In my opinion it would be a good thing, it is a semi-popular standard and hidden behind a feature gate it wouldn't incure any cost for people not using postgis) This especially matters for me since as far as I see it, it is not possible to add third party types to sqlx which are checked at compile time So - if support for postgis is wanted I would be happy to contribute, but should we add custom types to sqlx itself or use a different rust library for that? Intuitivly I would choose a different, more established library, but @abonander argued against it and imo best suited library And should the WKB decoding be bespoke? There is https://docs.rs/wkb/latest/wkb/, but this would lock us into I would love feedback and I would also feel comfortable writing a draft PR for support, but only if this is actually a wanted feature, apology if I oversaw any prior discussion. |
What is the current consensus, do we use the As a compromise I would propose we add public traits to allow custom types for the deserialization. Throug New Types you could use these traits to add suport for Or we make traits with assoziate types, so you can create a ZST implementing these to simulate implementing them for external types. PS: if we roll our own type do we want a feature flag for them? |
same question here. What is still missing/required to proceed? And it seems also blocking the postgis support from the SeaORM side if my understanding is correct? |
There should be sufficient traits to implement decoding for any given type. You'd just have to request it using the type override syntax (see the docs), making the macros choose an external type by default is a different question entirely. The biggest issue with integrating an external crate is stability. Is it yet another crate we're going to have to upgrade with every minor ( |
Any updates? |
In addition to @Gearme , in the official documentation of PostGIS, they state that:
Which means that it is perfectly reasonable to use the simpler geometric type when
Edit 1: |
Wouldn’t mind having a crack at the types outlined in #166 (comment). |
https://docs.rs/geo
https://www.postgresql.org/docs/current/datatype-geometric.html
POINT
->geo::Coordinate<f64>
LINE
->geo::Line<f64>
LSEG
->geo::Line<f64>
BOX
->geo::Rect<f64>
PATH
->geo::LineString<f64>
POLYGON
->geo::Polygon<f64>
The text was updated successfully, but these errors were encountered: