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

DatatypeMismatch with db queries using multipolygons #30

Open
Siggs2000 opened this issue Jan 29, 2017 · 2 comments
Open

DatatypeMismatch with db queries using multipolygons #30

Siggs2000 opened this issue Jan 29, 2017 · 2 comments
Labels
documentation Issues that could be solved by adding documentation

Comments

@Siggs2000
Copy link

I'm fairly certain that I'm doing something wrong here but when using a the active-record rgeo gem and encoding a single polygon, I'm able to make a db query like this:

This works:
MyModel.where("latlon && ?", poly) where the latlon column is a point type and the poly represents a regular polygon that I generated from a linestring of coordinates using this factory: factory = RGeo::Geographic.spherical_factory(:srid => 4326)

This doesn't:
Using this gem, I encode a geojson multipolygon successfully using: poly = RGeo::GeoJSON.decode(mp.to_json, :json_parser => :json) Then I extract the geometry using:
poly = poly.geometry and that also seems to be successful. Now I try to run that same query from above:
MyModel.where("latlon && ?", poly) but this time it fails with this error:

PG::DatatypeMismatch at /api/v1/listings/polygon_search.json
============================================================

> ERROR:  argument of WHERE must be type boolean, not type record
LINE 1: SELECT "my_models".* FROM "my_model" WHERE (latlon && '002000...
            
@Siggs2000
Copy link
Author

I think I've figured this out. I suppose I just have to iterate through each of the polygons in the multi_polygon and check results for each one. Unless anyone knows of a better way?

The exception was being raised because the multi_polygon is actually multiple polygon types.... Obvious in hindsight!

@BuonOmo BuonOmo added the documentation Issues that could be solved by adding documentation label Nov 9, 2020
@BuonOmo
Copy link
Member

BuonOmo commented Nov 9, 2020

I think I've figured this out. I suppose I just have to iterate through each of the polygons in the multi_polygon and check results for each one. Unless anyone knows of a better way?

That's the way indeed!

Here's a snippet I use to do so.

Since it is from 2017 and you found a solution anyway, I'm closing this issue :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Issues that could be solved by adding documentation
Projects
None yet
Development

No branches or pull requests

2 participants