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
Union of a multipolygon and a polygon outputs empty multipolygon #1277
Comments
Thanks for opening the issue. I can reproduce it with boost 1.71 but with current version (1.85) the problem seems to be fixed. I am getting the following output (also testing for validity of output)
The two results are slightly different probably due to information lost in serialization to the text. |
Thanks for the reply! I will try with a newer version of boost. |
Thanks. If the newer version resolves your problem please close this issue. |
Yes, I confirmed it works with 1.85. I will close this issue. |
Hi, I have a very weird problem regarding
boost::geometry::union_
.I'm using:
I'm trying to take a union of a multipolygon and a polygon. Let me call the multipolygon A and the polygon B.
Basically I want the
output
below.It should output a multipolygon, which has an area equal to or larger than A or B.
However, it ends up with empty multipolygon.
Both A and B are valid, spike-free geometry.
This is A:
and this is B (not the same scale):
and this is the expected output (B is attached to the top right of A):
See my notebook in gist for the full plot: https://gist.github.com/z-masahiro-sakuta/c7700df23c3d70596a82a1af0377c33e
However, the very weird thing is, once I serialize A and B into WKT formatted texts and load them back, it won't happen. I guess some information is lost in serialization to the text.
For this reason, it is very hard to make a reproduceable code, because the problem happens in one part of my large codebase. I had to serialize the geometry in a raw binary format that preserves full double precision floating point data, otherwise I cannot put a reproduceable code here.
Reproduction code
I attached a zip file to reproduce it. It contains 4 files:
geom_invalid.cpp
- the source file to build the reproduction code. It contains custom deserialization code to load fromA.bin
andB.bin
.CMakeLists.txt
- to build the applicationA.bin
- a binary serialized multipolygon for AB.bin
- a binary serialized polygon for Bgeom_invalid.zip
You can unzip and run like this:
The output in my environment is below.
The 5th line says
result wkt = "MULTIPOLYGON()"
but it should contain a union of the polygons.The last 2 lines show the correct result if the inputs are converted to WKT.
Workarounds
I could use WKT in the input shapes to fix it, but I don't know why it works, and unless I find the root cause, it may not fix other cases.
Also, I run the logic in a performance-critical code, so I don't want to convert back and force between WKT unnecessarily.
I also tried
boost::geometry::correct()
andboost::geometry::remove_spikes()
on the input, but neither worked.I use
boost::geometry::union_
a lot in my application, and this issue happens very rarely (maybe once in thousands of times). Most of the time, the union produces expected multipolygon. But once it happens, it persists with the same inputs and my users can't fix it.The text was updated successfully, but these errors were encountered: