Hi Sean, I've been finding more problems having to do with newer versions of Shapely with older versions of GEOS. Please look at the following:
In[23]: from shapely.wkt import dumps In[24]: from shapely.geometry import Point In[25]: dumps(Point(0,0)) Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2883, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-25-6b5b1cef3aeb>", line 1, in <module> dumps(Point(0,0)) File "/usr/local/lib/python2.7/dist-packages/shapely/wkt.py", line 22, in dumps return geos.WKTWriter(geos.lgeos, trim=trim, **kw).write(ob) File "/usr/local/lib/python2.7/dist-packages/shapely/geos.py", line 309, in __init__ setattr(self, name, applied_settings[name]) File "/usr/local/lib/python2.7/dist-packages/shapely/geos.py", line 317, in __setattr__ (self.__class__.__name__, name)) AttributeError: 'WKTWriter' object has no attribute 'trim' My environment is: Shapely 1.5.1 GEOS (3, 2, 2) I understand that my version of GEOS is quite old, but the problem is that upgrading Shapely and keeping GEOS is breaking things. Can you confirm? This is quite problematic when trying to install software which requires Shapely. For example on Ubuntu, if I install the latest available Shapely and the latest available GEOS I run into this situation, which didn't happen with older versions of Shapely. Perhaps the way to go about this is to establish which is the minimum version of GEOS required in a given version of Shapely and have Shapely completely fail as early as possible (ideally on installation or on import maybe?). Thanks, JP On Mon, Dec 15, 2014 at 3:10 PM, Juan Pablo Caram <jpca...@gmail.com> wrote: > > 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