OSM 提取 POI - OsmPoisPbf 工具

1. OsmPoisPbf 工具:提取 POI

1.1 简介

OsmPoisPbf 工具,从 OSM 文件(需为 .pbf 格式)提取 POI 数据,保存为 .csv 文件:github

  • 需要安装 jre,以及设置 jre 的路径

1.2 主要参数

主要参数

  • -of <file>:输出的 .csv 文件

  • -r:解析 relations

  • -ph:使输出的 .csv 文件首行为表头

  • -s <character>:列与列之间的分隔符,默认为 |
    注意:尽量不要使用英文逗号 , 作为分隔符,因为得到的 .csv 文件的最后一列(即 name 列)中的元素可能会存在 , 字符。

实例代码

java -jar osmpois.jar -r -ph singapore.osm.pbf
java -jar osmpois.jar -of "singapore_OSM_POI.csv" -s "," -r -ph "singapore.osm.pbf"

1.3 POI 种类

得到的 .csv 文件的第一列为 category,为 POI 的类别数字。数字具体的含义见这里

1.4 实用工具

实用工具: 对提取到的 POI 数据,进行匹配,获得具体分类,并保存为 .shp 格式

点击查看代码
import requests
import pandas as pd
import geopandas as gpd

def match_poi(poi_path, type_path, save_path):
    '''
    match the poi information by code and save file

    Parameters
    ----------
    poi_path (str); type_path (str); save_path
    '''
    # load POI type information
    type_df = pd.read_csv(type_path, on_bad_lines='skip')
    # drop NA row
    type_df = type_df.dropna(axis=0).reset_index(drop=True)
    # rename columns
    type_df = type_df.rename(columns={'POI TYPE': 'poi_type', 'CODE': 'code'})
    # add "category" and "detail" columns
    type_df['category'] = type_df['poi_type'].str.split('_').str.get(0)
    type_df['detail'] = type_df['poi_type'].str.split('_').str.get(1)
    # drop "poi_type" columns
    type_df = type_df.drop('poi_type', axis=1)
    # convert the data type of the "code" column
    type_df = type_df.astype({'code': 'int32'})
    
    # load POI data
    poi_df = pd.read_csv(poi_path, index_col=None, header=0)
    poi_df = poi_df.rename(columns={'category': 'code'})
    
    # merge two table
    poi_df = pd.merge(left=poi_df, right=type_df, how='left', on='code')
    
    # pd.DataFrame toe gpd.GeoDataFrame
    poi_gdf = gpd.GeoDataFrame(
        data = poi_df[['code', 'osm_id', 'name', 'category', 'detail']],
        geometry = gpd.points_from_xy(poi_df['lon'], poi_df['lat']),
        crs = 'EPSG:4326')      # CRS in OSM, WGS 48
    
    # save file 
    poi_gdf.to_file(save_path)
    return None
# ----------------------------------------------------------------------------

poi_path = 'singapore_OSM_POI.csv'
type_path = r'https://raw.githubusercontent.com/MorbZ/OsmPoisPbf/master/doc/poi_types.csv'
save_path = 'OSM-poi-2022-06-01.shp'
match_poi(poi_path, type_path, save_path)
posted @ 2023-04-10 08:27  veager  阅读(775)  评论(0)    收藏  举报