Geographic Information Systems Asked on April 10, 2021
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)
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])
Answered by snowman2 on April 10, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP