Discussion:
[Community] Creating collections
Juan Pablo Caram
2014-01-20 22:54:59 UTC
Permalink
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gispython.org/pipermail/community/attachments/20140120/20ac31c3/attachment.htm>
Sean Gillies
2014-01-28 23:46:32 UTC
Permalink
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
... groups = zip(*[list(o.bounds) for o in geoms])
... return min(groups[0]), min(groups[1]), max(groups[2]),
max(groups[3])
...
Post by Juan Pablo Caram
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?
Post by Juan Pablo Caram
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
b = cascaded_union(something).bounds
b = something.bounds
etc...
And I'm having to do something like this for almost every operation.
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 at lists.gispython.org
http://lists.gispython.org/mailman/listinfo/community
--
Sean Gillies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gispython.org/pipermail/community/attachments/20140128/91bdc2a4/attachment.htm>
Juan Pablo Caram
2014-01-31 02:15:18 UTC
Permalink
Hi Sean,

Thanks for your response. Actually, finding the bounds of a list of
geometry object was just an example. I also need to plot them, serialize
them, etc. In fact, there seem to be quite a number of operations for
geometry collections! And I'm needing to handle lists of Shapely geometry
objects different from GeometryCollection's.

Serialising is probably going to be a nightmare as I will have to come up
with some custom representation for a list of WKT representations. It would
be so much nicer to have this supported by the GeometryCollection class.

Do you think I could sub-class it in some way that it would allow me to
group objects together? I understand that many operations would fail, but
maybe that wouldn't be such a bad thing, as they already do with invalid
Polygon's.

Thanks a lot,

JP
Post by Sean Gillies
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
... groups = zip(*[list(o.bounds) for o in geoms])
... return min(groups[0]), min(groups[1]), max(groups[2]),
max(groups[3])
...
Post by Juan Pablo Caram
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?
Post by Juan Pablo Caram
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
b = cascaded_union(something).bounds
b = something.bounds
etc...
And I'm having to do something like this for almost every operation.
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 at lists.gispython.org
http://lists.gispython.org/mailman/listinfo/community
--
Sean Gillies
_______________________________________________
Community mailing list
Community at lists.gispython.org
http://lists.gispython.org/mailman/listinfo/community
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gispython.org/pipermail/community/attachments/20140130/fb1e03c7/attachment.htm>
Loading...