-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
Fail to decode polygons with overlapping areas #33
Comments
+1 here |
Hitting an issue like rgeo/rgeo-geojson#33 where we are getting "LinearRing failed ring test (RGeo::Error::InvalidGeometry)" for a valid polygon. Added rescue from RGeo::Error::InvalidGeometry
+1 Version 2.1.1 problem still exists |
I could indeed reproduce this issue by forcing the geojson = '{"type":"Polygon","coordinates":[[[40.1605224609375,50.48547354578499],[41.890869140625,49.75642885858046],[41.8963623046875,50.447011182312195],[40.1495361328125,50.025387620270244],[40.1605224609375,50.48547354578499]]]}'
polygon = RGeo::GeoJSON.decode(geojson, geo_factory: RGeo::Cartesian.simple_factory) With that said, it looks like a geojson accepts complex polygons (https://tools.ietf.org/html/rfc7946#section-3.1.6). Hence we may considere setting uses_lenient_assertions for the coder geo_factory. This would make the polygon not compliant with OGC as mentioned in rgeo. However, I don't know yet enough about RGeo's codebase to make that decision globally. @keithdoggett what is your opinion on that one ? Locally, a quick fix is: geojson = <<~JSON
{
"type":"Polygon",
"coordinates": [[
[40.1605224609375,50.48547354578499],
[41.890869140625,49.75642885858046],
[41.8963623046875,50.447011182312195],
[40.1495361328125,50.025387620270244],
[40.1605224609375,50.48547354578499]
]]
}
JSON
polygon = RGeo::GeoJSON.decode(geojson, geo_factory: RGeo::Cartesian.simple_factory(uses_lenient_assertions: true))
puts polygon And for convenience: # in some init file
GEOJSON_CODER = RGeo::GeoJSON.coder(geo_factory: RGeo::Cartesian.simple_factory(uses_lenient_assertions: true))
# later
geojson = <<~JSON
{
"type":"Polygon",
"coordinates": [[
[40.1605224609375,50.48547354578499],
[41.890869140625,49.75642885858046],
[41.8963623046875,50.447011182312195],
[40.1495361328125,50.025387620270244],
[40.1605224609375,50.48547354578499]
]]
}
JSON
GEOJSON_CODER.decode(geojson) This might as well be a bit related with rgeo/rgeo#228, since it depends on the EDIT: sorry for the quick close/reopen, but I think we may be able to handle this issue here |
I've noticed a problem when trying to decode areas with "bowtie" like shapes:
And, as you can see here, this is a valid Geo JSON Polygon.
Debugging the code, we could check that
lib/rgeo/geo_json/coder.rb @ line 246
callsWhich actually raises an
RGeo::Error::InvalidGeometry: LinearRing failed ring test
and returnsnil
.Version tested: 0.4.3
The text was updated successfully, but these errors were encountered: