#--------------------------20200227更新----------------------------------------

德国人第二天邮件就反馈了。确实严谨,也学到了。

1 osm 全部坐标信息只在points里, 后面的way 和relation 只有点id的索引。

他给出的读取方法是:

l0 =osm.GetLayer(0)

f0=None

fcount=0while l0.GetNextFeature() is notNone:

fcount+= 1

必须顺次读取,先读完全部的points再读后面的

2 pbftoosm 不维护了。

Pbftoosm is not maintained any more. Please use Osmconvert, its direct

replacement, or Osmium instead.

osmium cat -o nk.osm north-korea-latest.osm.pbf

3 不兼容报错,主要是因为删除了上传者个人信息。 他们验证过的工具可以处理这个问题。

Our files follow the standard with the exception thatpersonal metadata

fields are set to 0 or empty strings to protect the privacy of

OpenStreetMap contributors. Our tests pointed out that this is not an

issue for established tools such as Osmium, Osmosis and Osmconvert.

4 处理是基于导入pg的

We do not plan to support pbftoosm in future because its development

stopped nine years ago. We do not use GDAL to read PBF files ourselves

because it is not performant. Instead, we import them into a PostgreSQL

database and run

毕竟咱是外行,还是学到很多啊

#----------------------------------------------------------------------------

项目需要分析过滤osm上的数据,  在

可以下载到按大洲,和国别 的 osm数据,    所有国家提供  .osm.pbf格式 和 raw osm压缩 .osm.bz2  格式,  数据少的国家 提供 . shp 格式的.

对shp的处理当然没问题. 但在数据大的国家动辄几G, pbf体积最小, 就下载了.但是读取可坑死我了.  前后折腾了N天.终于明白了.

一.症状

直接说结论:这个网站的pbf格式, 不是标准的pbf!  表现症状有2:

1.1 不被 gdal ogr 库支持

在py下

importgdal, ogr

gdal.SetConfigOption('OGR_INTERLEAVED_READING', 'YES')#gdal.SetConfigOption('OSM_MAX_TMPFILE_SIZE', '2000')

if __name__ == '__main__':

fname = './data/osm_pbf/north-korea-latest.osm.pbf'

osm =ogr.Open(fname)print(osm.GetLayerCount())

layer=osm.GetLayer(0)#layer = data.GetLayer('lines')

print(layer.GetFeatureCount())

feature=layer.GetNextFeature()

o1=feature.ExportToJson(as_object=True)print(o1)

1 所有的对 layer 0 也就是points  是可以运行的,但是 lines multipolygons 一个features都读不出来, 只返回None

layer.GetFeatureCount()

可以读出数量

在ubuntu下, 自己辛苦源码编译的gdal下,  全是-1

但是, gdal 测试里自带的pbf     GDAL/autotest/ogr/data/test.pbf

是没任何问题的  !

1.2 不被openstreetmap官网的pbf转换工具支持

官网提供了pbf2osm 直接一个可执行文件 比如x64 linux 直接下载一个pbftoosm64  放到bin 之类的路径下

对gdal自带的pbf是可以正常转型的 转成osm的 注意尖括号不能省略

pbftoosm64 test.osm

但是转他家下载的.osm.pbf就报错

➜ osm_pbf git:(master) ✗ pbftoosm64 nk.osm

pbftoosm Warning: header block element type unknown: 0x80 0x02.

pbftoosm Warning: header block element type unknown: 0xA6 0xC8.

pbftoosm: Format error: 0xA6.

pbftoosm: Number of bytes read: 24

这几天,为了编译gdal和他的依赖库, 兜了个大圈子,坑死我了.

2 解决

但是,这毕竟是个天天更新全球数据的网站, 德国人开的网站,总不至于发布完全无法读取的数据呀.

Commonly Used Formats

asia-latest.osm.pbf, suitable for Osmium, Osmosis, imposm, osm2pgsql, mkgmap, and others. This file was last modified 6 hours ago and contains all OSM data up to 2020-02-25T21:59:02Z. File size: 7.7 GB; MD5 sum:

sudo apt-get install build-essential cmake libboost-dev \

libexpat1-dev zlib1g-dev libbz2-dev

pip3.8 install osmium

写个新的py脚本read_osm_pbf.py

'''https://download.geofabrik.de/asia.html

asia-latest.osm.pbf, suitable for Osmium, Osmosis, imposm, osm2pgsql, mkgmap, and others.'''

importosmiumclassCounterHandler(osmium.SimpleHandler):def __init__(self):

osmium.SimpleHandler.__init__(self)

self.num_nodes=0defnode(self, n):

self.num_nodes+= 1

if __name__ == '__main__':

fname= './data/osm_pbf/north-korea-latest.osm.pbf'h=CounterHandler()

h.apply_file(fname)print("Number of nodes: %d" % h.num_nodes)

运行一下:

python3.8 read_osm_pbf.py

果然能读, 没报错

下面继续研究具体怎么读坐标,怎么关联shapely

有时间真想问问德佬, 你们这pbf和osm官网的pbf到底啥关系?!

java osm pbf_read format .osm.pbf from geofabrik相关推荐

  1. Objective-C 字符串拼接函数 多个不同类型的参数拼接到一个字符串 类似于Java中 String.format()方法的原生API

    总目录 iOS开发笔记目录 从一无所知到入门 文章目录 需求 Screenshot Code Output 需求 我有多个参数(类型也许不同),需要拼接到一个字符串中. 在Java中有String.f ...

  2. [Exception] java.util.MissingFormatArgumentException: Format specifier ‘%s‘

    java.util.MissingFormatArgumentException: Format specifier '%s'at java.util.Formatter.format(Formatt ...

  3. Java / Android String.format 的使用

    String类的format()方法用于创建格式化的字符串以及连接多个字符串对象. 自己使用的地方1 拼接字符串 2 ,多语言文字顺序不同问题,例如中文:距离到公司还有30分钟, 时间是接口获取的, ...

  4. Java的String.format可以静态导入

    JDK-8203630 ["为String :: format添加等效的实例方法"]假定"将String :: format实现为静态的参数似乎是可以静态导入 forma ...

  5. java 格式化 布尔型_这么久才知道Java中的format很强大!

    Java中允许我们对指定的对象进行某种格式化,从而得到我们想要的格式化样式. Format 首先介绍java.text包中的Format Foramt是一个抽象基类,其具体子类必须实现 format( ...

  6. java string.format_如果性能很重要,我应该使用Java的String.format()吗?

    我编写了一个小类进行测试,该类具有两者的更好性能,并且+领先于格式.以5到6的倍数进行尝试 import java.io.*; import java.util.Date; public class ...

  7. java 08d_Java String.Format() 方法及参数说明

    JDK1.5中,String类新增了一个很有用的静态方法String.format(): format(Locale l, String format, Object... args) 使用指定的语言 ...

  8. Java使用String.format()实现补零

    判断字符串长度,不够9位,在前面补0 String.format("%09d", Integer.valueOf("123")) 输出结果:000000123

  9. Java笔记-String.format的使用(可用于格式化字符串)

    如下代码: String tmp = "Hello, '%s', %s, %s, %s"; tmp = String.format(tmp, "one", &q ...

  10. list of Java class file format major version numbers?

    http://stackoverflow.com/questions/9170832/list-of-java-class-file-format-major-version-numbers http ...

最新文章

  1. 微软中国CTO:不思进取、放弃基本技能的程序员在34.9岁会被淘汰!
  2. 插入最快mysql8.0_MySQL8.0大表秒加字段,是真的吗?
  3. Java多线程安全问题解决的两种方式代码案例
  4. 01_基于应用拆分的技术架构
  5. cobbler自动化安装详解
  6. mysql查询缓存到redis_php查询mysql并缓存到redis
  7. python的ctypes模块详解数组_python ctypes结构数组
  8. linux sqluldr2命令,sqluldr2 linux64
  9. 【FFmpeg4.1.4】音视频分离器
  10. oracle建表语句 货币,Oracle建表语句是什么
  11. mysql 数据库后缀名,mysql 数据库文件扩展名
  12. java连接mysql数据库实现图书馆管理系统
  13. 联想启动Kind City项目:交互式全球合作鼓励同理心,共创建立于善意之上的未来
  14. 互联网舆情监测控免费及系统技术方法详解
  15. L13. hrtimer使用实例(高精度定时器)
  16. JS实现RGB,HSL,HSB相互转换
  17. STM32电路设计之最小系统
  18. 蓝桥杯 算法提高 9-2 文本加密(c语言版详细注释)
  19. 工业物联网数控机床设备远程控制整体解决方案
  20. Android字节码插桩

热门文章

  1. 解决es集群Yellow与Red的问题
  2. 特种部队2全面反击bt电影种子下载
  3. RAP2环境部署(nginx代理模式)及运维
  4. Rust use of undeclared crate or module和maybe a missing crate?
  5. 基于SMTP协议的E-MAIL电子邮件发送客户端软件C#实现
  6. 黑帆第一季/全集Black Sails迅雷下载
  7. 7天带你搞定一个图表框架echarts(七)
  8. Google Play Academy 组队 PK 赛,正式开赛!
  9. python调用打印机打印图片
  10. 遇上与你一样的她(他)| MixLab人工智能