1

I have a function to create buffers from everything in a shapefile, but I'm getting an error on some files: Record's geometry type does not match collection schema's geometry type: 'Polygon' != 'LineString'

Here's my function:

def buffer_file(src, dst, buffer):
  if not os.path.isfile(dst):
    with fiona.open(src) as input:
      input_meta = copy.deepcopy(input.meta)
      input_meta['schema']['properties'] = { 'id': 'int'}

      with fiona.open(dst, 'w', **input_meta) as output:
        for i, point in enumerate(input):
          output.write({
            'properties': { 'id': i },
            'geometry': mapping(shape(point['geometry']).buffer(buffer))
          })

What am I missing to make this work with all files? I works with most files I throw at it flawlessly. I just have some problem files.

  • 2
    Add some debug code into your script so that when the error happens you can see a) the input geometry and b) the buffered geometry. That will help with finding the right way to fix the problem. – user30184 Aug 3 '18 at 7:38
1

Try to change destination geometry type into "Polygon". I guess geometry type of your input shapefile is LineString. But buffers are polygons. Briefly, you are trying to add polygons to shapefile whose geometry type is LineString.

def buffer_file(src, dst, buffer):
  if not os.path.isfile(dst):
    with fiona.open(src) as input:
      input_meta = copy.deepcopy(input.meta)
      input_meta['schema']['properties'] = { 'id': 'int'}

      # ADD THIS LINE
      input_meta["schema"]["geometry"] = "Polygon"

      with fiona.open(dst, 'w', **input_meta) as output:
        for i, point in enumerate(input):
          output.write({
            'properties': { 'id': i },
            'geometry': mapping(shape(point['geometry']).buffer(buffer))
          })

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.