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
Some "valid" polygons are treated as invalid by rgeo #212
Comments
@Kdoggett887 Thank you for the detailed explanation. But I think there are more issues to this problem. While the points are dense in the given triangle, lines do not cross over one another. Indeed, MySQL 8.0(with spherical coordinates support) does validate this polygon. select st_isvalid(st_geomfromtext("POLYGON ((37.5816708669373 126.968027438107, 37.58168793850955 126.96804356077827, 37.5816870915542 126.96804348189114, 37.58168238826706 126.96804311029837, 37.581642824769546 126.96803990177084, 37.5816708669373 126.968027438107))", 4326)) => 1 I am not sure about the root cause of this bug. Since this issue is happening with densely located points, maybe some sort of rounding off error is being introduced in RGeo's algorithm? |
@daesan That's a good point. Thanks for bringing that up. I did some more research and got your polygon to be valid by changing the It maps the lat/lngs to a cartesian sphere but casts the (x,y,z) points to floats. Turns out around I would be happy to submit a PR to get this fix merged in if it makes sense. |
@Kdoggett887 That's really cool! Thank so much for digging into this. It would be great if you can submit a PR to fix this issue. 👍 |
I've been banging my head over the same issue! https://stackoverflow.com/questions/58996305/getting-invalidgeometry-linearring-failed-ring-test-after-upgrading-rgeo-gem |
The new validation system in version 3 allows for creating geometries that are invalid, so issues like this where reading from the database failed due to a validation error will no longer happen. This doesn't solve the second issue that the spherical math library is not robust to floating point errors at high precision, but I'm going to close this since there's an issue open for improvements to the spherical math library (#274) |
Some polygons that are valid with MySQL or QGIS are causing error in rgeo.
Steps to reproduce
The following code results in exception.
RGeo::Geographic.spherical_factory.parse_wkt("POLYGON ((126.968027438107 37.5816708669373, 126.96804356077827 37.58168793850955, 126.96804348189114 37.5816870915542, 126.96804311029837 37.58168238826706, 126.96803990177084 37.581642824769546, 126.968027438107 37.5816708669373))")
Expected behavior
It should be parsed without problem.
Actual behavior
It throws the following exception.
RGeo::Error::InvalidGeometry (LinearRing failed ring test)
System configuration
Ruby version: 2.5.0p0
OS: Mac OS X 10.14.6
The text was updated successfully, but these errors were encountered: