Linux【OSMCTools 01】OpenStreetMap数据处理工具OSMCTools下载安装使用举例(osmconvert osmfilter命令说明)如何获取区域边界说明

193 阅读7分钟

OpenStreetMap的下载地址:Geofabrik Download Server
OSMCTools的GitHub地址:github.com/ramunasd/os…

Windows操作系统,可以从http://m.m.i24.cc/osmconvert_latest.zip下载osmconvert最新版本的zip文件;也可以从官方网站http://wiki.openstreetmap.org/wiki/osmconvert下载一个适用于Windows的安装程序进行安装。但这两个地址都无法访问,原因不明。本次安装的是 Linux 系统的。

1.Tools

  • osmassignpoly
  • osmchange - updates an .osm file using one or more .osc files
  • osmconvert - reads and converts OSM data to the selected output file format
  • osmfilter - filters OSM data
  • osmgeobase
  • osmposition
  • osmrelpoly
  • osmupdate - cares about updating an .osm, .o5m or .pbf file
  • pbftoosm - converts .pbf file into .osm XML format

2.官网安装步骤

  git clone https://github.com/ramunasd/osmctools.git
  cd osmctools
  autoreconf --install
  ./configure
  make install

3.实际安装步骤

3.1 环境

[root@tcloud ~]# cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)

3.2 步骤

# 1.安装autoconf
yum install -y autoconf
# 否则会报错
-bash: autoreconf: command not found

# 2.安装 automake libtool
yum install -y automake libtool
# 否则报错
Can't exec "aclocal": No such file or directory at /usr/share/autoconf/Autom4te/FileUtils.pm line 326.
autoreconf: failed to run aclocal: No such file or directory

  1. 从GIT上下载源码
# 未安装git的先进行安装
yum install -y git

# 1.从GIT上下载源码
git clone https://github.com/ramunasd/osmctools.git

在这里插入图片描述
2. 生成 configure 脚本等文件

# 2.生成 configure 脚本等文件
[root@tcloud osmctools-master]# autoreconf --install 
configure.ac:3: installing './install-sh'
configure.ac:3: installing './missing'
src/Makefile.am: installing './depcomp'

在这里插入图片描述

  1. 构建环境并生成 Makefile 以及设置编译选项的脚本
# 3.构建环境并生成 Makefile 以及设置编译选项的脚本
[root@tcloud osmctools-master]# ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for style of include used by make... GNU
checking dependency style of gcc... gcc3
checking for gzopen in -lz... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating include/config.h
config.status: executing depfiles commands

# 4.安装
make install
[root@tcloud osmctools-master]# make install
Making install in src
make[1]: Entering directory `/opt/osmctools-master/src'
gcc -DHAVE\_CONFIG\_H -I. -I../include -march=native -O3 -MT osmconvert.o -MD -MP -M F .deps/osmconvert.Tpo -c -o osmconvert.o osmconvert.c
mv -f .deps/osmconvert.Tpo .deps/osmconvert.Po
gcc -march=native -O3 -o osmconvert osmconvert.o -lz
gcc -DHAVE\_CONFIG\_H -I. -I../include -march=native -O3 -MT osmfilter.o -MD -MP -MF .deps/osmfilter.Tpo -c -o osmfilter.o osmfilter.c
mv -f .deps/osmfilter.Tpo .deps/osmfilter.Po
gcc -march=native -O3 -o osmfilter osmfilter.o
gcc -DHAVE\_CONFIG\_H -I. -I../include -march=native -O3 -MT osmupdate.o -MD -MP -MF .deps/osmupdate.Tpo -c -o osmupdate.o osmupdate.c
mv -f .deps/osmupdate.Tpo .deps/osmupdate.Po
gcc -march=native -O3 -o osmupdate osmupdate.o
gcc -DHAVE\_CONFIG\_H -I. -I../include -march=native -O3 -MT osmchange.o -MD -MP -MF .deps/osmchange.Tpo -c -o osmchange.o osmchange.c
mv -f .deps/osmchange.Tpo .deps/osmchange.Po
gcc -march=native -O3 -o osmchange osmchange.o
gcc -DHAVE\_CONFIG\_H -I. -I../include -march=native -O3 -MT pbftoosm.o -MD -MP -MF .deps/pbftoosm.Tpo -c -o pbftoosm.o pbftoosm.c
mv -f .deps/pbftoosm.Tpo .deps/pbftoosm.Po
gcc -march=native -O3 -o pbftoosm pbftoosm.o -lz
gcc -DHAVE\_CONFIG\_H -I. -I../include -march=native -O3 -MT osmrelpoly.o -MD -MP -MF .deps/osmrelpoly.Tpo -c -o osmrelpoly.o osmrelpoly.c
mv -f .deps/osmrelpoly.Tpo .deps/osmrelpoly.Po
gcc -march=native -O3 -o osmrelpoly osmrelpoly.o
gcc -DHAVE\_CONFIG\_H -I. -I../include -march=native -O3 -MT osmassignpoly.o -MD -MP -MF .deps/osmassignpoly.Tpo -c -o osmassignpoly.o osmassignpoly.c
mv -f .deps/osmassignpoly.Tpo .deps/osmassignpoly.Po
gcc -march=native -O3 -o osmassignpoly osmassignpoly.o
gcc -DHAVE\_CONFIG\_H -I. -I../include -march=native -O3 -MT osmgeobase.o -MD -MP -MF .deps/osmgeobase.Tpo -c -o osmgeobase.o osmgeobase.c
mv -f .deps/osmgeobase.Tpo .deps/osmgeobase.Po
gcc -march=native -O3 -o osmgeobase osmgeobase.o
gcc -DHAVE\_CONFIG\_H -I. -I../include -march=native -O3 -MT osmposition.o -MD -MP -MF .deps/osmposition.Tpo -c -o osmposition.o osmposition.c
mv -f .deps/osmposition.Tpo .deps/osmposition.Po
gcc -march=native -O3 -o osmposition osmposition.o
make[2]: Entering directory `/opt/osmctools-master/src'
 /usr/bin/mkdir -p '/usr/local/bin'
 /usr/bin/install -c osmconvert osmfilter osmupdate osmchange pbftoosm osmrelpoly osmassignpoly osmgeobase osmposition '/usr/local/bin'
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/opt/osmctools-master/src'
make[1]: Leaving directory `/opt/osmctools-master/src'
make[1]: Entering directory `/opt/osmctools-master'
make[2]: Entering directory `/opt/osmctools-master'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/opt/osmctools-master'
make[1]: Leaving directory `/opt/osmctools-master'

安装成功后增加的bin文件跟介绍里的一样:

在这里插入图片描述

4.工具使用实例

4.1 osmconvert

它是一个用于处理OSM(OpenStreetMap)地图数据的命令行工具。可以将OSM地图文件从一种格式转换成另一种格式,比如OSM XML文件转换成PBF(Protocolbuffer Binary Format)、CSV(Comma Separated Values)等格式,并且可以对地图数据进行筛选、剪切、合并等操作。

# 可以直接输入 osmconvert 根据指引进行文件处理
[root@tcloud ~]# osmconvert

osmconvert 0.8.11

Converts .osm, .o5m, .pbf, .osc, .osh files, applies changes
of .osc, .o5c, .osh files and sets limiting borders.
Use command line option -h to get a parameter overview,
or --help to get detailed help.

If you are familiar with the command line, press <Return>.

If you do not know how to operate the command line, please
enter "a" (press key E and hit <Return>).

不同版本的 osmconvert 用法可能不同,常见的用法:

  1. 查看PBF文件的统计信息
osmconvert china-latest.osm.pbf --out-statistics
-----------------------------------------------------------------
timestamp min: 2007-02-27T00:40:13Z
timestamp max: 2023-05-16T19:28:11Z
lon min: 52.8472761
lon max: 135.6776013
lat min: 4.9997288
lat max: 54.0115689
nodes: 152714910
ways: 11459000
relations: 148001
node id min: 274901
node id max: 10903266309
way id min: 4181592
way id max: 1173486456
relation id min: 2664
relation id max: 15863565
keyval pairs max: 605
keyval pairs max object: relation 270056
noderefs max: 2000
noderefs max object: way 28779814
relrefs max: 8899
relrefs max object: relation 911618
-----------------------------------------------------------------
Finished! Calculation time: 31s.

  1. 将OSM XML文件转换成PBF格式:
osmconvert input.osm -o=output.pbf

  1. 将PBF格式的地图文件转换成OSM XML格式:
# pbf格式的文件无法直接查看转换后可直接看数据
osmconvert input.pbf -o=output.osm

最全的Linux教程,Linux从入门到精通

======================

  1. linux从入门到精通(第2版)

  2. Linux系统移植

  3. Linux驱动开发入门与实战

  4. LINUX 系统移植 第2版

  5. Linux开源网络全栈详解 从DPDK到OpenFlow

华为18级工程师呕心沥血撰写3000页Linux学习笔记教程

第一份《Linux从入门到精通》466页

====================

内容简介

====

本书是获得了很多读者好评的Linux经典畅销书**《Linux从入门到精通》的第2版**。本书第1版出版后曾经多次印刷,并被51CTO读书频道评为“最受读者喜爱的原创IT技术图书奖”。本书第﹖版以最新的Ubuntu 12.04为版本,循序渐进地向读者介绍了Linux 的基础应用、系统管理、网络应用、娱乐和办公、程序开发、服务器配置、系统安全等。本书附带1张光盘,内容为本书配套多媒体教学视频。另外,本书还为读者提供了大量的Linux学习资料和Ubuntu安装镜像文件,供读者免费下载。

华为18级工程师呕心沥血撰写3000页Linux学习笔记教程

本书适合广大Linux初中级用户、开源软件爱好者和大专院校的学生阅读,同时也非常适合准备从事Linux平台开发的各类人员。

需要《Linux入门到精通》、《linux系统移植》、《Linux驱动开发入门实战》、《Linux开源网络全栈》电子书籍及教程的工程师朋友们劳烦您转发+评论

详情docs.qq.com/doc/DSmdCdUNwcEJDTXFK