Hi Ari, cascaded_union() expects the argument to be a sequence of geometries, either a multi-part geometry or a list of geometries. The problem with OGR's shapefile driver is that it can give you LineStrings and MultiLineStrings from a single file. Until I have a patch for Shapely or a new release, I'll have to ask you to test the input items and wrap them in a list if they are single-part geometries. Something like this:
for item in input: geom = shape(item['geometry']) if not geom.type.startswith('Multi'): geom = [geom] dissolve_feat = cascaded_union(geom) ... On Mon, Jun 9, 2014 at 4:55 PM, Ari Simmons <ari.ucb.f...@gmail.com> wrote: > This is my first time trying a cascaded_union, and I am getting the > following "..no len()..." error. I don't seem to have any 'NoneType' > geometry..so I'm not sure what it is picking up on...anybody else see it? > > >>Traceback (most recent call last): > >> File "<stdin>", line 1, in <module> > >> File "I:/It_25/116609_global_hwy_shields/dissolve/dissolve.py", line > 17, in >>dissolve > >> dissolve_feat = cascaded_union(geom) > >>File "C:\Python27\lib\site-packages\shapely\ops.py", line 112, in > >>cascaded_union > >> L = len(geoms) > >>TypeError: object of type 'LineString' has no len() > > import fiona > from shapely.geometry import shape > from shapely.ops import cascaded_union > > def dissolve(inFile, outFile): > with fiona.open(inFile, 'r', encoding='utf-8') as input: > input_driver = input.driver > input_crs = input.crs > input_schema = input.schema.copy() > with fiona.open(outFile, 'w', driver=input_driver, crs=input_crs, > schema=input_schema, encoding='utf-8') as output: > for item in input: > geom = shape(item['geometry']) > dissolve_feat = cascaded_union(geom) > output.write({'geometry':mapping(dissolve_feat), > 'properties': item['properties']}) > > > _______________________________________________ > 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