Dear list,
I have created an External method in plone that reads a shapefile containing
linestring geometries. I want to convert those to polygons. I use WorldMill
0.1 and Shapely-1.0.5.
When I use the object_hook like this:
c = w['shapefile']
c.object_hook = shapely_feature
for f in c:
try:
if f.properties['ID']!='':
# look up the object through the catalog
for brain in catalog(portal_type='Thing',
Title='"'+f.properties['ID']+'"'):
d=brain.getObject()
LOG('Bisk2008', INFO, brain.Title)
if d !=None:
geo=IGeoreferenced(d)
coords=[]
l=f.geometry.coordsf):
for i in range(len(l)):)
coords.append(l[i])
# reverse back to point 0 to create a polygon
for i in range(len(l)-2, -1, -1):
coords.append(l[i])
poly_coords=[]
poly_coords.append(tuple(coords))
geo.setGeoInterface('Polygon', poly_coords)
except:
LOG('project', INFO, "Error with %s" % brain.Title)
The following error is raised:
2008-08-28T10:04:02 ERROR Zope.SiteErrorLog
Traceback (innermost last):
Module ZPublisher.Publish, line 119, in publish
Module ZPublisher.mapply, line 88, in mapply
Module ZPublisher.Publish, line 42, in call_object
Module Products.ExternalMethod.ExternalMethod, line 231, in __call__
- __traceback_info__: ((<PloneSite at /project>,), {}, None)
Module /home/plone/project/parts/zope2/Extensions/egeo.py, line 38, in
importDempingGeometry
Module mill.collection, line 105, in mill.collection.Iterator.__next__
(src/mill/collection.c:%u)
Module mill.collection, line 149, in
mill.collection.Iterator._marshal_feature (src/mill/collectio
n.c:%u)
Module /home/plone/project/parts/zope2/Extensions/egeo.py, line 13, in
shapely_feature
Module shapely.wkb, line 17, in loads
ReadingError: Could not create geometry because of errors while reading
input.
But the loop had handled 4299 features successfully before this happened.
If I redo the code using some of shapely's more basic functions, without
hooking it into the shapely_feature:
c = w['shapefile']
# c.object_hook = shapely_feature
for f in c:
if f.properties['ID']!='':
# look up the object through the catalog
for brain in catalog(portal_type='Thing',
Title='"'+f.properties['ID']+'"'):
d=brain.getObject()
LOG('project', INFO, brain.Title)
if d !=None:
geo=IGeoreferenced(d)
geom = lgeos.GEOSGeomFromWKB_buf(c_char_p(f.geometry),
c_size_t(len(f.geometry)))
if geom:
shapely_geom = geom_factory(geom)
coords=[]
l=shapely_geom.coords
for i in range(len(l)):
coords.append(l[i])
# reverse back to point 0 to create a polygon
for i in range(len(l)-2, -1, -1):
coords.append(l[i])
poly_coords=[]
poly_coords.append(tuple(coords))
geo.setGeoInterface('Polygon', poly_coords)
Then the whole shape file (4368 features) is processed without errors.
--
Jan H. van der Ven
_______________________________________________
Community mailing list
[email protected]
http://lists.gispython.org/mailman/listinfo/community