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

Update to use WKT vs WKB #54

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mkeller3
Copy link
Contributor

@mkeller3 mkeller3 commented Sep 8, 2022

Currently the geometry is converted to WKB, but this does not convert correctly when executing the sql statement. By using WKT, we no longer see this issue occur.

Example: INTERSECTS(geom, POINT(-89.004202 40.503501))

Converts to: ST_Intersects("geom",ST_GeomFromWKB(x'0101000000FB2477D8444056C06C4084B872404440'))

Running the following SQL:

SELECT ST_GeomFromWKB(x'0101000000FB2477D8444056C06C4084B872404440')

You receive the following error:

ERROR: function st_geomfromwkb(bit) does not exist LINE 1: SELECT ST_GeomFromWKB(x'0101000000FB2477D8444056C06C4084B872... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. SQL state: 42883 Character: 8

After converting to use ST_GeomFromText this issue no longer occurs.

Currently the geometry is converted to WKB, but this does not convert correctly when executing the sql statement. By using WKT, we no longer see this issue occur.
@constantinius
Copy link
Contributor

@mkeller3

Thanks for the contribution!

Which DB backend are you using? All major backends I checked support this method, so I'm a bit surprised.

One thing you could do is to subclass the SQLEvaluator and just override the geometry method with your custom solution.

@mkeller3
Copy link
Contributor Author

PostgreSQL

@constantinius
Copy link
Contributor

@mkeller3 I'm a bit confused: https://postgis.net/docs/ST_GeomFromWKB.html

@mkeller3
Copy link
Contributor Author

mkeller3 commented Sep 23, 2022

PostgreSQL does support that method, but the way shapely is converting the input to bytes is not compatible with PostgreSQL. I provided the example above to show what happens if you try to use the WKB method in PostgreSQL. It returns an error.

@mkeller3
Copy link
Contributor Author

image

@constantinius
Copy link
Contributor

Right, now I understand. I will look at how we can format the WKB to be loadable in Postgres

@mkeller3
Copy link
Contributor Author

mkeller3 commented Oct 4, 2022

Do you want to continue to try and use shapely, or would you be open to other options?

@EPajares
Copy link

Hi both, thanks for working on this. I was also just running in this issue. Another option could be changing the passed WKB-String to this.

SELECT ST_GeomFromWKB(E'\\x0101000000FB2477D8444056C06C4084B872404440')

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