Discussion:
[Community] cascaded_union vs unary_union
Pascal Leroux
2012-05-28 07:35:38 UTC
Permalink
Hi all,

Using a list containing polygons AND multipolygons, I have made the Python
interpreter crash (bus error on MacOSX, segmentation fault on
Linux/Ubuntu). Shapely.ops.cascaded_union only accepts a Polygon instance
list or a MultiPpolygon instance as a parameter.

In addition to that, GEOSCascadedUnion is deprecated from version 3.3.0 and
GEOSUnaryUnion must be used instead.

Why not to define in shapely.ops a function "unary_union" that would call
(wrap) GEOSUnaryUnion function ?

I've modified ctypes_declarations.py and ops.py to use GEOSUnaryUnion and
it seems to work :

plx at sony:~$ python
Python 2.7.3 (default, Apr 20 2012, 22:44:07)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
from shapely.wkt import loads
mp=loads('MULTIPOLYGON (((0 0,0 1,1 1,1 0, 0 0)), ((2 2, 2 3, 3 3, 3 2,
2 2)))')
p=loads('POLYGON ((2 0, 2 1, 3 1, 3 0, 2 0))')
from shapely.ops import unary_union as u2
u2((mp,p))
<shapely.geometry.multipolygon.MultiPolygon object at 0xb6c9f9ac>
u2((mp,p)).wkt
'MULTIPOLYGON (((0.0000000000000000 0.0000000000000000, 0.0000000000000000
1.0000000000000000, 1.0000000000000000 1.0000000000000000,
1.0000000000000000 0.0000000000000000, 0.0000000000000000
0.0000000000000000)), ((2.0000000000000000 0.0000000000000000,
2.0000000000000000 1.0000000000000000, 3.0000000000000000
1.0000000000000000, 3.0000000000000000 0.0000000000000000,
2.0000000000000000 0.0000000000000000)), ((2.0000000000000000
2.0000000000000000, 2.0000000000000000 3.0000000000000000,
3.0000000000000000 3.0000000000000000, 3.0000000000000000
2.0000000000000000, 2.0000000000000000 2.0000000000000000)))'
multi=loads('MULTIPOLYGON (((0 0, 0 1, 1 1, 1 0, 0 0)), ((1 1, 2 1, 2
0, 1 0, 1 1)))')
u2(multi).wkt
'POLYGON ((0.0000000000000000 0.0000000000000000, 0.0000000000000000
1.0000000000000000, 1.0000000000000000 1.0000000000000000,
2.0000000000000000 1.0000000000000000, 2.0000000000000000
0.0000000000000000, 1.0000000000000000 0.0000000000000000,
0.0000000000000000 0.0000000000000000))'
from shapely.ops import cascaded_union as cu
u2(multi).equals(cu(multi))
True
...
cu((mp,p))
Erreur de segmentation (core dumped)
plx at sony:~$


Cascaded_union might be kept for compatibility reasons but it could call
GEOSUnarayUnion too ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gispython.org/pipermail/community/attachments/20120528/bff9f36f/attachment.htm>
Sean Gillies
2012-06-02 02:41:25 UTC
Permalink
Hi Pascal,

I don't see why we can't try to use UnaryUnion when it's available.
Can you add this to https://github.com/Toblerity/Shapely/issues so I
don't lose track while I'm workshopping and traveling this weekend?
Post by Pascal Leroux
Hi all,
Using a list containing polygons AND multipolygons, I have made the Python
interpreter crash (bus error on MacOSX, segmentation fault on Linux/Ubuntu).
Shapely.ops.cascaded_union only accepts a Polygon instance list or a
MultiPpolygon instance as a parameter.
In addition to that, GEOSCascadedUnion is deprecated from version 3.3.0 and
GEOSUnaryUnion must be used instead.
Why not to define in shapely.ops a function "unary_union" that would call
(wrap) GEOSUnaryUnion function ?
I've modified ctypes_declarations.py and ops.py to use GEOSUnaryUnion and it
plx at sony:~$ python
Python 2.7.3 (default, Apr 20 2012, 22:44:07)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
from shapely.wkt import loads
mp=loads('MULTIPOLYGON (((0 0,0 1,1 1,1 0, 0 0)), ((2 2, 2 3, 3 3, 3 2,
2 2)))')
p=loads('POLYGON ((2 0, 2 1, 3 1, 3 0, 2 0))')
from shapely.ops import unary_union as u2
u2((mp,p))
<shapely.geometry.multipolygon.MultiPolygon object at 0xb6c9f9ac>
u2((mp,p)).wkt
'MULTIPOLYGON (((0.0000000000000000 0.0000000000000000, 0.0000000000000000
1.0000000000000000, 1.0000000000000000 1.0000000000000000,
1.0000000000000000 0.0000000000000000, 0.0000000000000000
0.0000000000000000)), ((2.0000000000000000 0.0000000000000000,
2.0000000000000000 1.0000000000000000, 3.0000000000000000
1.0000000000000000, 3.0000000000000000 0.0000000000000000,
2.0000000000000000 0.0000000000000000)), ((2.0000000000000000
2.0000000000000000, 2.0000000000000000 3.0000000000000000,
3.0000000000000000 3.0000000000000000, 3.0000000000000000
2.0000000000000000, 2.0000000000000000 2.0000000000000000)))'
multi=loads('MULTIPOLYGON (((0 0, 0 1, 1 1, 1 0, 0 0)), ((1 1, 2 1, 2 0,
1 0, 1 1)))')
u2(multi).wkt
'POLYGON ((0.0000000000000000 0.0000000000000000, 0.0000000000000000
1.0000000000000000, 1.0000000000000000 1.0000000000000000,
2.0000000000000000 1.0000000000000000, 2.0000000000000000
0.0000000000000000, 1.0000000000000000 0.0000000000000000,
0.0000000000000000 0.0000000000000000))'
from shapely.ops import cascaded_union as cu
u2(multi).equals(cu(multi))
True
...
cu((mp,p))
Erreur de segmentation (core dumped)
plx at sony:~$
Cascaded_union might be kept for compatibility reasons but it could call
GEOSUnarayUnion too ?
_______________________________________________
Community mailing list
Community at lists.gispython.org
http://lists.gispython.org/mailman/listinfo/community
--
Sean Gillies
Loading...