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

Union of valid (multi)polygons produces geometry collection with a linestring #476

Closed
skat-kurt opened this issue Sep 19, 2019 · 5 comments

Comments

@skat-kurt
Copy link

I ran into something weird today. I have 2 valid polygons. After
invoking union on them the result is a GeometryCollection with a
LineString inside. I would not expect the union of Polygons to lead to
LineStrings? It is of course also possible that I oversee something.

geom1-wkt: "MULTIPOLYGON (((546132.889 6290404.306, 546132.268 6290443.796, 546139.126 6290438.224, 546128.599 6290446.777, 546109.556 6290423.732, 546132.889 6290404.306)))"

geom2-wkt: "MULTIPOLYGON (((546132.27 6290443.792, 546132.268 6290443.786, 546132.889 6290404.317, 546132.897 6290404.299, 546135.837 6290401.852, 546135.844 6290401.85, 546135.845 6290401.85, 546135.852 6290401.85, 546140.089 6290403.894, 546140.4 6290404.045, 546140.405 6290404.057, 546140.405 6290404.277, 546140.286 6290437.351, 546140.283 6290437.359, 546140.28 6290437.364, 546139.127 6290438.223, 546139.125 6290438.225, 546132.275 6290443.79, 546132.27 6290443.792)))""

resulting-union-wkt: "GEOMETRYCOLLECTION (LINESTRING (546139.1259999973 6290438.224000002, 546139.126 6290438.224), POLYGON ((546132.563714283 6290424.991238262, 546132.889 6290404.306, 546109.556 6290423.732, 546128.599 6290446.777, 546136.5712956785 6290440.299651759, 546139.125 6290438.225, 546139.1259999973 6290438.224000002, 546139.127 6290438.223, 546140.28 6290437.364, 546140.283 6290437.359, 546140.286 6290437.351, 546140.405 6290404.277, 546140.405 6290404.057, 546140.4 6290404.045, 546140.089 6290403.894, 546135.852 6290401.85, 546135.845 6290401.85, 546135.844 6290401.85, 546135.837 6290401.852, 546132.897 6290404.299, 546132.889 6290404.317, 546132.563714283 6290424.991238262), (546136.5567565103 6290440.311463506, 546132.268 6290443.796, 546132.2681501706 6290443.786450512, 546132.27 6290443.792, 546132.275 6290443.79, 546136.5567565103 6290440.311463506)))"

@dr-jts
Copy link
Contributor

dr-jts commented Sep 19, 2019

This is due to topology collapse happening because geometry A has a very narrow spike near POINT ( 546139.127 6290438.223 ) which falls outside geometry B. When the spike is noded with geometry B the outside portion collapses to a line segment.

JTS has always had the feature that overlay operations return ALL components of the result regardless of dimension. This was done to avoid losing information. A different semantic of returning only the highest-dimension resultants could have been chosen. Perhaps that should be provided as an option.

@dr-jts
Copy link
Contributor

dr-jts commented Sep 19, 2019

See also related question: shapely/shapely#771

@skat-kurt
Copy link
Author

Thanks @dr-jts. For now, when I get a geometry collection I use the PolygonExtracter to create a new MultiPolygon. Is this a recommended way of handling the situation?

@dr-jts
Copy link
Contributor

dr-jts commented Sep 20, 2019

Yes, that.s the best way currently of handling this.

@skat-kurt
Copy link
Author

Thanks, I'll close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants