這很複雜,但長話短說:我已經使用了幾個類似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