这很复杂,但长话短说:我已经使用了几个类似OSMN的库来绘制城市的几个景点之间的路线。现在我将它转换为一个shp文件。Shapely:不带逗号的元组与LineString
该路由是一个充满节点ID的列表。然后这些id用于提取每个节点的纬度和经度。我做了元组与来连接各个节点对(一个开始,一个到达)的坐标循环,这样的:在循环结束
journey = []
# previous list will contain tuples with coordinates of each node
for node1, node2 in zip(route[:-1], route[1:]):
parcours.append(tuple((G.node[noeud1]['x'], G.node[noeud1]['y']))) # we create a tuple with coordinates of start's node
parcours.append(tuple((G.node[noeud2]['x'], G.node[noeud2]['y']))) # then we make the same for the arrival node
这里的打印(旅程)的结果:
[(6.15815, 48.6996136), (6.1629696, 48.7007431), (6.1629696, 48.7007431), [...], (6.1994411, 48.6768434), (6.1994411, 48.6768434), (6.1995322, 48.6767583)]
每个元组都显示正确。但是,当我想旅途转换成一个身材匀称的线段形式...而它返回:
import fiona
schema = {
'geometry': 'Polygon',
"properties": {'id': 123}
}
with fiona.open('test.shp', 'w', 'ESRI Shapefile', schema) as c:
c.write({
'geometry': mapping(trace)
})
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) in() 4 } 5 ----> 6 with fiona.open('test.shp', 'w', 'ESRI Shapefile', schema) as c: 7 c.write({ 8 'geometry': mapping(trace)
/usr/local/lib/python3.5/dist-packages/fiona/init.py in open(path, mode, driver, schema, crs, encoding, layer, vfs, enabled_drivers, crs_wkt) 173 c = Collection(path, mode, crs=crs, driver=driver, schema=this_schema, 174 encoding=encoding, layer=layer, vsi=vsi, archive=archive, --> 175 enabled_drivers=enabled_drivers, crs_wkt=crs_wkt) 176 else: 177 raise ValueError(
/usr/local/lib/python3.5/dist-packages/fiona/collection.py in init(self, path, mode, driver, schema, crs, encoding, layer, vsi, archive, enabled_drivers, crs_wkt, **kwargs) 154 elif self.mode in ('a', 'w'): 155 self.session = WritingSession() --> 156 self.session.start(self, **kwargs) 157 except IOError: 158 self.session = None
fiona/ogrext.pyx in fiona.ogrext.WritingSession.start (fiona/ogrext2.c:16207)()
TypeError: argument of type 'int' is not iterable
:
from shapely.geometry import LineString
final_journey = LineString(journey)
print(final_journey)
LINESTRING (6.15815 48.6996136, 6.1629696 48.7007431, 6.1629696 48.7007431, 6.1630717 48.7002871, [...], 6.1991794 48.677085, 6.1994411 48.6768434, 6.1994411 48.6768434, 6.1995322 48.6767583)
因此,我不能使用菲奥娜转换的轴马力我不明白为什么元组在经纬度之间没有逗号转换。此外,还有几个重复(第三行的第二个坐标是第四行的第一个坐标,等等),也许它可能是未来shp的错误来源。
在此先感谢!
什么,当你做你所看到的'print(final_journey)'是你的行的[Well Known Text](https://en.wikipedia.org/wiki/Well-known_text)表示。这没什么错(例如'没有逗号的元组'),它只是在解释器中几何地显示几何图形。 – mgc