从OSM中提取矢量和光栅数据。

osmxtract的Python项目详细描述


OSMXtract

说明

osmxtract是一个简单的python包,它使用Overpass API来获取OpenStreetMap特性并将它们导出到geojson文件中。

安装

使用pip

pip install osmxtract

命令行界面

使用量

osmxtract可以根据三个不同的选项猜测查询的范围:

  • --fromfile:使用输入矢量或光栅文件的边界;
  • --latlon--buffer:使用给定点周围缓冲区的边界;
  • --address--buffer:使用地理编码地址周围的缓冲区边界。
Usage: osmxtract [OPTIONS] OUTPUT

  Extract GeoJSON features from OSM with the Overpass API.

Options:
  --fromfile PATH                 Bounding box from input file.
  --latlon FLOAT...               Space-separated lat/lon coordinates.
  --address TEXT                  Address to geocode.
  --buffer INTEGER                Buffer size in meters around lat/lon or
                                  address.
  --tag TEXT                      OSM tag of interest (ex: "highway").
  --values TEXT                   Comma-separated list of possible values (ex:
                                  "tertiary,primary").
  --case-insensitive              Make the first character of each value case
                                  insensitive.
  --geom [point|linestring|polygon|multipolygon]
                                  Output geometry type.
  --help                          Show this message and exit.

示例

# buildings around the "Université Libre de Bruxelles" as polygons# save features in the file `buildings.geojson`. since no values# are provided, all non-null values are accepted for the tag# "highway" are accepted.
osmxtract --address "Université Libre de Bruxelles" --buffer 5000\
          --tag building --geom polygon buildings.geojson

# primary, secondary and tertiary roads based on the extent# of an existing raster. save the result as linestrings in the# `major_roads.geojson` file. we use the `--case-insensitive`# flag to get roads tagged as "primary" as well as "Primary".
osmxtract --fromfile map.tif --tag highway \
          --values "primary,secondary,tertiary"\
          --case-insensitive --geom linestring \
          major_roads.geojson

# cafes and bars near "Atomium, Brussels" 
osmxtract --address "atomium, brussels" --buffer 1000\
          --tag amenity --values "cafe,bar" --geom point \
          cafes_and_bars.geojson

API

importjsonfromosmxtractimportoverpass,locationimportgeopandasasgpd# Get bounding box coordinates from a 2km buffer# around the Atomium in Brusselslat,lon=location.geocode('Atomium, Brussels')bounds=location.from_buffer(lat,lon,buffer_size=2000)# Build an overpass QL query and get the JSON responsequery=overpass.ql_query(bounds,tag='amenity',values=['cafe','bar'])response=overpass.request(query)# Process response manually...foreleminresponse['elements']:print(elem['tags'].get('name'))# Output:# Au Bon Coin# Aux 4 Coins du Monde# Excelsior# Welcome II# Heymbos# Games Café# Stadium# Le Beau Rivage# The Corner# None# Expo# Koning# Centrum# St. Amands# Bij Manu# ...or parse them as GeoJSONfeature_collection=overpass.as_geojson(response,'point')# Write as GeoJSONwithopen('cafes_and_bars.geojson','w')asf:json.dump(feature_collection,f)# To GeoPandas GeoDataFrame:geodataframe=gpd.GeoDataFrame.from_features(feature_collection)

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java无法在spring boot应用程序中启用本机内存跟踪   jakarta ee在Java Web项目上的多窗口   日期将Java时间戳转换为MySQL时间戳,反之亦然   java如何实现异步任务连接到服务器并解析JSON   java为什么我得到索引越界异常?   我们如何在java中以大写字母和小写字母存储同名文件   jni/java:有效不可变本机对象的线程安全发布/共享   Java将文本写入远程文件   int最小硬币算法   java如何设置/获取我在类Vehicle的主方法中创建的类Car的“ford”实例的名称?   java使用计时器在队列已满时重新调度使用者   java从字符串的末尾提取一个子字符串,直到遇到第一个空格为止?   java在SimpleApplication之外正确初始化物理状态