0

I have two point shapefile representing towns within a state and I want find the distance between them. Since the points are in different shapefiles, should I merge them so they would be in the same shapefile before computing the linestring or is it possible to compute the linestring without merging both point shapefiles using shapely and Fiona function not GeoPandas.

ValueError: Record does not match collection schema:

 import shapely
 import fiona
 from shapely.geometry import MultiPoint, Point, shape



 POL = ".cache/merbin.shp"
 POI = ".cache/merert.shp"


 with fiona.open(POI) as src:
    for elem in src:
      if elem['id'] == '0':
         geom = shape(elem['geometry'])
         elem['geometry'] = mapping(geom.centroid)

 with fiona.open(POL) as salt:
 for tea in salt:
     if tea['id'] == '0':
         geom = shape(tea['geometry'])
         tea['geometry'] = mapping(geom.centroid)

        schema = {'geometry': 'Point',
            'properties': {} }
        with fiona.open('mew.shp', 'w', 'ESRI Shapefile', schema, crs=from_epsg(4326)) as output:
       prop = {}
       print(tea)
       output.write(tea)
       output.write(elem)
1
  • 1
    Your code indentation has to be corrected, and some elements are missing a definition. Could you please fix this? – s.k May 10 '20 at 20:32
0

Untested, but I think this should do it:

import fiona
from shapely.geometry import LineString, shape

POL = ".cache/merbin.shp"
POI = ".cache/merert.shp"

with fiona.open(POI) as src:
    for elem in src:
        if elem['id'] == '0':
            geom1 = shape(elem['geometry'])
            break
    else:
        raise RuntimeError("Not Found")

with fiona.open(POL) as salt:
    for tea in salt:
        if tea['id'] == '0':
            geom2 = shape(tea['geometry'])
            break
    else:
        raise RuntimeError("Not Found")

linestring = LineString([geom1, geom2])

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.