Discussion:
[Community] How to create a GeometryCollection with shapely
Christian Ledermann
2012-11-13 09:37:57 UTC
Permalink
I want to parse a kml like :

<kml:MultiGeometry xmlns:kml="http://www.opengis.net/kml/2.2">
<kml:Polygon>
<kml:outerBoundaryIs>
<kml:LinearRing>
<kml:coordinates>3.000000,0.000000 4.000000,0.000000
4.000000,1.000000 3.000000,0.000000</kml:coordinates>
</kml:LinearRing>
</kml:outerBoundaryIs>
</kml:Polygon>
<kml:Point>
<kml:coordinates>0.000000,1.000000</kml:coordinates>
</kml:Point>
<kml:LineString>
<kml:coordinates>0.000000,0.000000 1.000000,1.000000</kml:coordinates>
</kml:LineString>
</kml:MultiGeometry>


into a shapely geometry


I tried

po = Polygon([(3,0), (4,0), (4,1), (3,0)])
l = LineString([(0,0), (1,1)])
p = Point(0,1)
g = GeometryCollection([po,p,l])

which fails with:
TypeError: __init__() takes exactly 1 argument (2 given)
and
geo_if = {'type': 'GeometryCollection', 'geometries': [
po.__geo_interface__, l.__geo_interface__,
p.__geo_interface__ ]}
g = asShape(geo_if)

which fails with:
ValueError: Unknown geometry type: geometrycollection


How can I create a GeometryCollection?
--
Best Regards,

Christian Ledermann

Nairobi - Kenya
Mobile : +254 702978914

<*)))>{

If you save the living environment, the biodiversity that we have left,
you will also automatically save the physical environment, too. But If
you only save the physical environment, you will ultimately lose both.

1) Don?t drive species to extinction

2) Don?t destroy a habitat that species rely on.

3) Don?t change the climate in ways that will result in the above.

}<(((*>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gispython.org/pipermail/community/attachments/20121113/903e1391/attachment.htm>
Christian Ledermann
2012-11-13 14:05:14 UTC
Permalink
Post by Christian Ledermann
shapely.wkt.loads('GEOMETRYCOLLECTION (POINT (0.0 1.0), LINESTRING (0.0
0.0, 1.0 1.0), POLYGON((3.0 0.0, 4.0 0.0, 4.0 1.0, 3.0 0.0)))')
<shapely.geometry.collection.GeometryCollection object at 0xb74aa48c>


but this seems terribly awkward




On Tue, Nov 13, 2012 at 12:37 PM, Christian Ledermann <
Post by Christian Ledermann
<kml:MultiGeometry xmlns:kml="http://www.opengis.net/kml/2.2">
<kml:Polygon>
<kml:outerBoundaryIs>
<kml:LinearRing>
<kml:coordinates>3.000000,0.000000 4.000000,0.000000
4.000000,1.000000 3.000000,0.000000</kml:coordinates>
</kml:LinearRing>
</kml:outerBoundaryIs>
</kml:Polygon>
<kml:Point>
<kml:coordinates>0.000000,1.000000</kml:coordinates>
</kml:Point>
<kml:LineString>
<kml:coordinates>0.000000,0.000000 1.000000,1.000000</kml:coordinates>
</kml:LineString>
</kml:MultiGeometry>
into a shapely geometry
I tried
po = Polygon([(3,0), (4,0), (4,1), (3,0)])
l = LineString([(0,0), (1,1)])
p = Point(0,1)
g = GeometryCollection([po,p,l])
TypeError: __init__() takes exactly 1 argument (2 given)
and
geo_if = {'type': 'GeometryCollection', 'geometries': [
po.__geo_interface__, l.__geo_interface__,
p.__geo_interface__ ]}
g = asShape(geo_if)
ValueError: Unknown geometry type: geometrycollection
How can I create a GeometryCollection?
--
Best Regards,
Christian Ledermann
Nairobi - Kenya
Mobile : +254 702978914
<*)))>{
If you save the living environment, the biodiversity that we have left,
you will also automatically save the physical environment, too. But If
you only save the physical environment, you will ultimately lose both.
1) Don?t drive species to extinction
2) Don?t destroy a habitat that species rely on.
3) Don?t change the climate in ways that will result in the above.
}<(((*>
--
Best Regards,

Christian Ledermann

Nairobi - Kenya
Mobile : +254 702978914

<*)))>{

If you save the living environment, the biodiversity that we have left,
you will also automatically save the physical environment, too. But If
you only save the physical environment, you will ultimately lose both.

1) Don?t drive species to extinction

2) Don?t destroy a habitat that species rely on.

3) Don?t change the climate in ways that will result in the above.

}<(((*>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gispython.org/pipermail/community/attachments/20121113/026dfa9e/attachment.htm>
Sean Gillies
2012-11-13 14:52:45 UTC
Permalink
Hi Christian,

I deliberately omitted a geometry collection constructor because there was
almost no support in GEOS for operations on them. You couldn't buffer a
collection, for example, or find its difference to another geometry. I've
seen some signs of this changing in GEOS, but until it does I don't think
there's any point to the class. It wouldn't be much more than a list of
geometries.
Post by Christian Ledermann
<kml:MultiGeometry xmlns:kml="http://www.opengis.net/kml/2.2">
<kml:Polygon>
<kml:outerBoundaryIs>
<kml:LinearRing>
<kml:coordinates>3.000000,0.000000 4.000000,0.000000
4.000000,1.000000 3.000000,0.000000</kml:coordinates>
</kml:LinearRing>
</kml:outerBoundaryIs>
</kml:Polygon>
<kml:Point>
<kml:coordinates>0.000000,1.000000</kml:coordinates>
</kml:Point>
<kml:LineString>
<kml:coordinates>0.000000,0.000000 1.000000,1.000000</kml:coordinates>
</kml:LineString>
</kml:MultiGeometry>
into a shapely geometry
I tried
po = Polygon([(3,0), (4,0), (4,1), (3,0)])
l = LineString([(0,0), (1,1)])
p = Point(0,1)
g = GeometryCollection([po,p,l])
TypeError: __init__() takes exactly 1 argument (2 given)
and
geo_if = {'type': 'GeometryCollection', 'geometries': [
po.__geo_interface__, l.__geo_interface__,
p.__geo_interface__ ]}
g = asShape(geo_if)
ValueError: Unknown geometry type: geometrycollection
How can I create a GeometryCollection?
--
Best Regards,
Christian Ledermann
Nairobi - Kenya
Mobile : +254 702978914
<*)))>{
If you save the living environment, the biodiversity that we have left,
you will also automatically save the physical environment, too. But If
you only save the physical environment, you will ultimately lose both.
1) Don?t drive species to extinction
2) Don?t destroy a habitat that species rely on.
3) Don?t change the climate in ways that will result in the above.
}<(((*>
--
Sean Gillies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gispython.org/pipermail/community/attachments/20121113/6defd955/attachment.htm>
Loading...