前回の続きです。
Prepare data for saving to file
The data contain certain data types (such as
list) that should be converted into character strings prior to saving the data to file (an alternative would be to drop invalid columns).
データは型(例えばlist型)を含みます。ファイルへ保存する前に、その型は文字列へ変換されるべきです。(代わりの方法は、無効な列を落とすです。)
列をフィルタし、文字列型にします。
# Columns with invalid values
problematic_columns = [
"osmid",
"lanes",
"name",
"highway",
"width",
"maxspeed",
"reversed",
"junction",
"bridge",
"tunnel",
"access",
"service",
]
# convert selected columns to string format
edges[problematic_columns] = edges[problematic_columns].astype(str)
Now we can see that most of the attributes are of type
objectthat quite often (such as ours here) refers to a string type of data.
ほとんどの属性がobject型であることを確認できます。object型はしばしば(今回のように)文字列型のデータを指します。
edges.columns
route_geom.columns
Save the data:
では、"OSM_Kamppi.gpkg"ファイルに、edges、route、nodes、buildingsそれぞれを、レイヤー毎に保存しましょう。なお、buildingsは列フィルターをしてから保存しています。
import pathlib
NOTEBOOK_PATH = pathlib.Path().resolve()
DATA_DIRECTORY = NOTEBOOK_PATH / "data"
# Save one layer after another
output_gpkg = DATA_DIRECTORY / "OSM_Kamppi.gpkg"
edges.to_file(output_gpkg, layer="edges")
route_geom.to_file(output_gpkg, layer="route")
nodes.to_file(output_gpkg, layer="nodes")
buildings[['geometry', 'name', 'addr:street']].to_file(output_gpkg, layer="buildings")
保存したレイヤーを読み込んでみましょう。
geopandas.read_file(output_gpkg, layer="edges").head()
geopandas.read_file(output_gpkg, layer="route").head()
geopandas.read_file(output_gpkg, layer="nodes").head()
geopandas.read_file(output_gpkg, layer="buildings").head()
Great, now we have saved all the data that was used to produce the maps into a geopackage.
素晴らしい。マップを構成する全部のデータを1つのgeopackageに保存しました。
Advanced reading
Here we learned how to solve a simple routing task between origin and destination points. What about if we have hundreads or thousands of origins? This is the case if you want to explore the travel distances to a spesific location across the whole city, for example, when analyzing the accessibility of jobs and services (like in the Travel Time Matrix dataset used in previous sections).
Check out pyrosm documentation on working with graphs for more advanced examples of network analysis in python. For example, pandana is a fast and efficient python library for creating aggretated network analysis in no time across large networks, and pyrosm can be used for preparing the input data for such analysis.
このレッスンで私たちは、始点と終点の単純なルーティングのタスクを解決する方法を学びました。
もし私たちが数百や数千の始点をもっていたらどうしましょうか。
あなたが、街中全体を使った特定の場所への移動距離、例えば、職場やサービスへのアクセスのしやすさ(前のセクションで使った移動時間のマトリックスのような)の分析、を深掘りしたいとします。
Pythonでのネットワーク分析のもっと先進的な例については、Pyrosmのドキュメントにあるworking with graphs をチェックしてください。
例えば、pandanaは、大規模なネットワークでも、ノータイムで、集約したネットワーク分析を作成する、早く、効率的な、Pythonのライブラリです。pyrosmはそのような分析の入力データを準備するために使うことができます。





