Hi JP,

Right, there aren't enough possible operations on geometry collections to
justify implementing the class.

Here's a bit of code that can get the bounds of any multipart geometry or
Python sequence of geometries:

>>> def bounds(geoms):
...     groups = zip(*[list(o.bounds) for o in geoms])
...     return min(groups[0]), min(groups[1]), max(groups[2]),
max(groups[3])
...
>>> from shapely.geometry import MultiPoint
>>> r = MultiPoint([(0, 0), (4,4)]).buffer(1.0)
>>> bounds(r)
(-1.0, -1.0, 5.0, 5.0)

It zips up the bounds of component geometries into 4 groups (minxs, minys,
maxxs, maxys) and then finds the mins and maxs of these. It doesn't even
need to switch on the types of things as long as every o in geoms is a
Shapely geometry object. Does that look helpful?


On Mon, Jan 20, 2014 at 3:54 PM, Juan Pablo Caram <jpca...@gmail.com> wrote:

> Hello,
>
> Is there a way to combine several shapely geometry objects into a
> collection without applying some operation like cascaded_union? I'm working
> on a CAD/CAM program and I'm repeatedly running into the problem of having
> to handle lists of geometry objects and collections differently. For
> example, to find the bound I'm doing:
>
> if type(something) == list:
>     b = cascaded_union(something).bounds
> elif type(something) == GeometryCollection:
>     b = something.bounds
> etc...
>
> And I'm having to do something like this for almost every operation.
>
> I this previous post:
> http://lists.gispython.org/pipermail/community/2012-November/003155.html
> it's mentioned that a constructor for GeometryCollection was omitted on
> purpose because there "isn't much point to the class", but it seems to be
> making application development somewhat complicated (at least for me). What
> would be the right approach to handling something like this?
>
> 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

Reply via email to