I am getting the following error on this function:
ValueError: Record's geometry type does not match collection schema's geometry type: 'Point' != 'MultiPoint'
The problem is that I have multipoints mixed with regular points. When I try to write the outputs at I get a schema confusion problem.
I've tried to draft the happy path, but I'm not getting why it still seems to be clobbering itself...the function 'move_point' will return a single shapely object (either Point or Multipoint) that I am attempting to write to out_file/output...I though the 'if' catches would navigate this, but apparently not..
def process_file(self, in_file, out_file, compare_file, dist):
# open input file and compare file
# loop over each
with fiona.open(in_file, 'r') as input:
with fiona.open(compare_file, 'r') as compare:
meta = input.meta
# The outFile has the same crs, schema as inFile
with fiona.open(out_file, 'w', **meta) as output:
# Read shapely geometries from file
# Loop through all shapely objects
# type(item) = 'dict'
for item in input:
my_shape = shape(item['geometry'])
# check if it is a multipoint or point
if isinstance(my_shape, MultiPoint):
# break Multipoints into points
# i.e. <class 'shapely.geometry.multipoint.MultiPoint'>
point_list = my_shape.geoms
for the_point in point_list:
print type(the_point)
my_shape = self.move_point(the_point, compare, dist)
elif isinstance(my_shape, Point):
# return of move_point is a shapely geom
# i.e. <class 'shapely.geometry.point.Point'>
my_shape = self.move_point(my_shape, compare, dist)
else:
raise ValueError('unhandled geometry type: ' + repr(my_shape.type))
# write to outfile
if my_shape is not None:
# how to pick up the new attributes
output.write({'geometry':mapping(my_shape), 'properties': item['properties']})
Aucun commentaire:
Enregistrer un commentaire