1
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(Retrieving data from OpenStreetMap(3))

Last updated at Posted at 2025-10-28

前回 の続きです。

Points-of-interest

Point-of-interest (POI) is a generic concept that describes point locations that represent places of interest. As osmnx.features_from_place() can download any geometry data contained in the OpenStreetMap database, it can also be used to download any kind of POI data. [geometries is now deprecated]

In OpenStreetMap, many POIs are described using the amenity tag <https://wiki.openstreetmap.org/wiki/Key:amenity>__. We can, for example, retrieve all restaurant locations by querying amenity=restaurant.

興味のある地点(POI)は、興味のある場所を示す地点の場所を描写する一般的な概念です。
osmnx.features_from_place()関数がオープンストリートマップのデータベースに含まれるどのようなジオメトリのデータもダウンロードできるように、osmnx.features_from_place()関数は、様々な種類のPOIデータをダウンロードするためにも使われます。

オープンストリートマップでは、amenityタグを使って、多くのPOIが描写されます。

私たちは、例えば、amenity=restaurantと問い合わせすることで、全てのレストランの場所を取得できます。

restaurants = osmnx.features_from_place(
    PLACE_NAME,
    {
        "amenity": "restaurant"
    }
)
len(restaurants)

image.png

As we can see, there are quite many restaurants in the area.

Let’s explore what kind of attributes we have in our restaurants GeoDataFrame:

ご覧の通り、このエリアには、かなりたくさんのレストランがあります。
どのような属性のレストランがあるか、探ってみましょう。

# Available columns
restaurants.columns.values

image.png

As you can see, there is quite a lot of (potential) information related to the amenities. Let’s subset the columns and inspect the data further. Can we extract all restaurants’ names, address, and opening hours?

ご覧の通り、かなりたくさんの(潜在的な)アメニティ(日本語にするのが難しいですが、利便性でしょうか)に関する情報があります。
列を絞り込み、さらに深堀りしてみましょう。全部のレストランの名前と所在地と営業開始時間を抽出できるでしょうか?

# Select some useful cols and print
interesting_columns = [
    "name",
    "opening_hours",
    "addr:city",
    "addr:country",
    "addr:housenumber",
    "addr:postcode",
    "addr:street"
]

# Print only selected cols
restaurants[interesting_columns].head(10)

image.png

Tip:

If some of the information needs an update, head over to openstreetmap.org and edit the source data!

もしいくつかの情報の更新が必要ならば、openstreetmap.orgで、元データを更新してください!

Parks and green areas

Let’s try to fetch all public parks in the Kamppi area. In OpenStreetMap, parks hould be tagged as leisure = park. Smaller green areas (puistikot) are sometimes also tagged landuse = grass. We can combine multiple tags in one data query.

Kamppiエリアの公共の公園、すべてを取得しましょう。オープンストリートマップでは、公園はleisure = parkとタグ付けされるべきです。(houldはshouldの誤りと思われます。)
より小さい緑色のエリア(puistikot、緑地帯)については、しばしば、landuse = grassとタグ付けされます。複数のタグをひとつの問い合わせとすることができます。

parks = osmnx.features_from_place(
    PLACE_NAME,
    {
        "leisure": "park",
        "landuse": "grass",
    },
)
parks.head()

image.png

parks.plot(color="green")

image.png

leisure: parkだけでプロットしてみましょう。
image.png

landuse: grassだけでプロットしてみましょう。
image.png

重複している箇所もあるようですね。

Plotting the data

Let’s create a map out of the streets, buildings, restaurants, and the area polygon.

ストリート、建物、レストラン、そして、Kamppiエリアのポリゴンによる地図を作ってみましょう。

import matplotlib
figure, ax = matplotlib.pyplot.subplots(figsize=(12,8))

# Plot the footprint
area.plot(ax=ax, facecolor="black")

# Plot parks
parks.plot(ax=ax, facecolor="green")

# Plot street ‘edges’
edges.plot(ax=ax, linewidth=1, edgecolor="dimgray")

# Plot buildings
buildings.plot(ax=ax, facecolor="silver", alpha=0.7)

# Plot restaurants
restaurants.plot(ax=ax, color="yellow", alpha=0.7, markersize=10)

image.png

Cool! Now we have a map where we have plotted the restaurants, buildings, streets and the boundaries of the selected region of ‘Kamppi’ in Helsinki. And all of this required only a few lines of code. Pretty neat!

すばらしい! Kamppiエリアのレストラン、建物、ストリートとそのリンクをプロットした地図ができました。
そして、これらは、数行のコードで実現しています。すごくいいですね!

Check your understanding

Retrieve OpenStreetMap data from some other area! Download these elements using OSMnx functions from your area of interest:

  • Extent of the area using geocode_to_gdf()
  • Street network using graph_from_place(), and convert to geo-data frame using graph_to_gdfs()
  • Building footprints (and other geometries) using features_from_place() and appropriate tags.

Note: The larger the area you choose, the longer it takes to retrieve data from the API!

理解度をチェックします。

他のいくつかのエリアからオープンストリートマップのデータを取得する!OSMnxの関数を使って、あなたの興味のあるエリアからこれらの要素をダウンロードする。

  • そのエリアの広さ(geocode_to_gdf()を使って)
  • ストリートネットワーク(graph_from_place()を使って、 さらに、graph_to_gdfs()でGeoDataFrameに変換する)
  • 建物の足跡(と他のもの)(features_from_place()と適切なタグを使って)

(備忘録):より大きなエリアを選ぶほど、APIからデータを取得する時間が長くなります!

# Specify the name that is used to search for the data. Check that the place
# name is valid from https://nominatim.openstreetmap.org/ui/search.html
MY_PLACE = ""

# Get street network

# Get building footprints

# Plot the data

Advanced reading

To analyse OpenStreetMap data over large areas, it is often more efficient and meaningful to download the data all at once, instead of separate queries to the API. Such data dumps from OpenStreetMap are available in various file formats, OSM Protocolbuffer Binary Format (PBF) being one of them. Data extracts covering whole countries and continents are available, for instance, at download.geofabrik.de.

Pyrosm is a Python package for reading OpenStreetMap data from PBF files into geopandas.GeoDataFrames. Pyrosm makes it easy to extract road networks, buildings, Points of Interest (POI), landuse, natural elements, administrative boundaries and much more - similar to OSMnx, but taylored to analyses of large areas. While OSMnx reads the data from the Overpass API, pyrosm reads the data from a local PBF file.

Read more about fetching and using pbf files as a source for analysing OpenStreetMap data in Python from the pyrosm documentation.

大きなエリアのオープンストリートマップを分析するためには、APIへの問い合わせを分割するよりも、一度に全部のデータをダウンロードすることが、より効率的、かつ、大事な場合があります。
そのようなオープンストリートマップからのデータダンプは様々なファイルフォーマットで利用でき、OSM Protocolbuffer Binary Format (PBF)はそのうちのひとつです。
国全体や大陸全体をカバーするデータの抽出も可能です。例えば、download.geofabrik.de

Pyrosmは、オープンストリートマップのデータをPBFファイルからgeopandas.GeoDataFramesに読み込むPytnonのパッケージです。
Pyrosmは道路ネットワーク、建物、興味のある地点(POI)、土地利用、自然の要素、行政区画等の抽出を容易にし、OSMnxに似ています、が、大きなエリアを分析するために仕立てられています。
OSMnxはOverpass APIからデータを読み込みますが、PyrosmはローカルのPBFファイルからデータを読み込みます。

Pythonでのオープンストリートマップのデータの分析のため、データの源泉として、PBFファイルを使う方法については、Pyrosmのドキュメントをご覧ください.

1
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
1
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?