Sean,
I seems that it's all about a version of GEOS that it's too old. I will try
upgrading to the latest and try again.
Thanks a lot!
JP

On Mon, Dec 15, 2014 at 1:51 PM, Sean Gillies <sean.gill...@gmail.com>
wrote:
>
> JP,
>
> Actually, you can call unary_union with an empty list in the latest
> Shapely.
>
> >>> import shapely
> >>> shapely.__version__
> '1.5.1'
> >>> import shapely.geos
> >>> shapely.geos.geos_version
> (3, 4, 2)
> >>> from shapely.ops import unary_union
> >>> unary_union([])
> <shapely.geometry.collection.GeometryCollection object at 0x10c3b6050>
>
> In your case, the KeyError gets raised first (I believe because your GEOS
> library is too old). Because cascaded_union has been aliased to unary_union
> (in Shapely 1.4+), it's the same story there.
>
> On Mon, Dec 15, 2014 at 11:33 AM, Juan Pablo Caram <jpca...@gmail.com>
> wrote:
>>
>> Hi Sean,
>>
>> Thanks for your response. What really concerns me here is that in case 1
>> (Newer GEOS and shapely) I cannot call cascaded_union (or unary_union) with
>> an empty list. I could on earlier versions.
>>
>> Thanks,
>>
>> JP
>>
>> On Mon, Dec 15, 2014 at 12:15 PM, Sean Gillies <sean.gill...@gmail.com>
>> wrote:
>>>
>>> Hi JP,
>>>
>>> As far as I can tell, the main difference between your cases is that in
>>> case 2, the included GEOS lib has a version >= 3.3. GEOS 3.2.2 (which is
>>> 4.5 years old, by the way) does not support unary union.
>>>
>>> See
>>> https://github.com/Toblerity/Shapely/blob/master/shapely/geos.py#L721
>>> <https://github.com/Toblerity/Shapely/blob/master/shapely/geos.py#L72>
>>>
>>> I admit that the KeyError is not the most helpful of errors.
>>> NotSupported might be bettter. I'll create a new issue in the tracker.
>>>
>>> On Sat, Dec 13, 2014 at 3:18 PM, Juan Pablo Caram <jpca...@gmail.com>
>>> wrote:
>>>
>>>> Hi,
>>>>
>>>> Could someone give me some light into this: I'm getting very different
>>>> behavior between versions/platforms for cascaded_union and unary_union. I
>>>> would like to know what it the expected/latest/correct behavior. These are
>>>> the two cases:
>>>>
>>>> CASE 1
>>>> ======
>>>>
>>>> Os: Ubuntu 12.04
>>>> libgeos-c1: 3.2.2-3ubuntu1
>>>> shapely: 1.5.1
>>>> python: 2.7.3
>>>>
>>>> >>> cascaded_union([])
>>>>
>>>> ---------------------------------------------------------------------------
>>>> ValueError                                Traceback (most recent call
>>>> last)
>>>> /home/jpcaram/flatcam/<ipython-input-4-0c768f786c71> in <module>()
>>>> ----> 1 cascaded_union([])
>>>>
>>>> /usr/local/lib/python2.7/dist-packages/shapely/ops.pyc in
>>>> cascaded_union(self, geoms)
>>>>     128             subs[i] = g._geom
>>>>     129         collection = lgeos.GEOSGeom_createCollection(6, subs, L)
>>>> --> 130         return
>>>> geom_factory(lgeos.methods['cascaded_union'](collection))
>>>>     131
>>>>     132     def unary_union(self, geoms):
>>>>
>>>> /usr/local/lib/python2.7/dist-packages/shapely/geometry/base.pyc in
>>>> geom_factory(g, parent)
>>>>      53     # Abstract geometry factory for use with topological
>>>> methods below
>>>>
>>>>      54     if not g:
>>>> ---> 55         raise ValueError("No Shapely geometry can be created
>>>> from null value")
>>>>      56     ob = BaseGeometry()
>>>>      57     geom_type = geometry_type_name(g)
>>>>
>>>> ValueError: No Shapely geometry can be created from null value
>>>>
>>>> >>> unary_union([])
>>>>
>>>> ---------------------------------------------------------------------------
>>>> KeyError                                  Traceback (most recent call
>>>> last)
>>>> /home/jpcaram/flatcam/<ipython-input-6-9089513baa4e> in <module>()
>>>> ----> 1 unary_union([])
>>>>
>>>> /usr/local/lib/python2.7/dist-packages/shapely/ops.pyc in
>>>> unary_union(self, geoms)
>>>>     146             subs[i] = g._geom
>>>>     147         collection = lgeos.GEOSGeom_createCollection(6, subs, L)
>>>> --> 148         return
>>>> geom_factory(lgeos.methods['unary_union'](collection))
>>>>     149
>>>>     150 operator = CollectionOperator()
>>>>
>>>> KeyError: 'unary_union'
>>>>
>>>> >>> cascaded_union([Point(0,0)])
>>>> <shapely.geometry.point.Point at 0x201d510>
>>>>
>>>> >>> unary_union([Point(0,0)])
>>>>
>>>> ---------------------------------------------------------------------------
>>>> KeyError                                  Traceback (most recent call
>>>> last)
>>>> /home/jpcaram/flatcam/<ipython-input-9-858a4018548e> in <module>()
>>>> ----> 1 unary_union([Point(0,0)])
>>>>
>>>> /usr/local/lib/python2.7/dist-packages/shapely/ops.pyc in
>>>> unary_union(self, geoms)
>>>>     146             subs[i] = g._geom
>>>>     147         collection = lgeos.GEOSGeom_createCollection(6, subs, L)
>>>> --> 148         return
>>>> geom_factory(lgeos.methods['unary_union'](collection))
>>>>     149
>>>>     150 operator = CollectionOperator()
>>>>
>>>> KeyError: 'unary_union'
>>>>
>>>>
>>>> CASE 2:
>>>> =======
>>>>
>>>> Os: Windows 7
>>>> python: 2.7.6
>>>> shapely: 1.3.0 (Installer came with geos)
>>>>
>>>> >>> cascaded_union([])
>>>> <shapely.geometry.collection.GeometryCollection at 0x7708830>
>>>>
>>>> >>> unary_union([])
>>>> <shapely.geometry.collection.GeometryCollection at 0x7708ab0>
>>>>
>>>>
>>>>
>>>> In CASE 1, everything is newer except for the python version. Has the
>>>> behavior of shapely/geos changed?
>>>>
>>>> Thank You,
>>>>
>>>> JP
>>>>
>>>>
>>>> _______________________________________________
>>>> Community mailing list
>>>> Community@lists.gispython.org
>>>> http://lists.gispython.org/mailman/listinfo/community
>>>>
>>>>
>>>
>>>
>>> --
>>> Sean Gillies
>>>
>>> _______________________________________________
>>> Community mailing list
>>> Community@lists.gispython.org
>>> http://lists.gispython.org/mailman/listinfo/community
>>>
>>>
>> _______________________________________________
>> Community mailing list
>> Community@lists.gispython.org
>> http://lists.gispython.org/mailman/listinfo/community
>>
>>
>
> --
> Sean Gillies
>
> _______________________________________________
> Community mailing list
> Community@lists.gispython.org
> http://lists.gispython.org/mailman/listinfo/community
>
>
_______________________________________________
Community mailing list
Community@lists.gispython.org
http://lists.gispython.org/mailman/listinfo/community

Reply via email to