0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Automating GIS Processes 2024 写経 Lesson 6 Network analysis in Python(3)

Posted at

前回の続きです。

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型)を含みます。ファイルへ保存する前に、その型は文字列へ変換されるべきです。(代わりの方法は、無効な列を落とすです。)

image.png

列をフィルタし、文字列型にします。

# 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 object that quite often (such as ours here) refers to a string type of data.

ほとんどの属性がobject型であることを確認できます。object型はしばしば(今回のように)文字列型のデータを指します。

edges.columns
route_geom.columns

image.png

Save the data:

では、"OSM_Kamppi.gpkg"ファイルに、edgesroutenodesbuildingsそれぞれを、レイヤー毎に保存しましょう。なお、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()

image.png

geopandas.read_file(output_gpkg, layer="route").head()

image.png

geopandas.read_file(output_gpkg, layer="nodes").head()

image.png

geopandas.read_file(output_gpkg, layer="buildings").head()

image.png

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はそのような分析の入力データを準備するために使うことができます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?