OSM-OpenStreetMap XML和PBF

司机简称

OSM

生成依赖项

libsqlite3(和libexpat for OSM XML)

这个驱动程序以.osm(基于XML)和.pbf(优化二进制)格式读取OpenStreetMap文件。

如果GDAL是使用SQLite支持构建的,并且对于.osm XML文件是使用Expat支持构建的,那么驱动程序是可用的。

文件名必须以.osm或.pbf扩展名结尾。

驱动程序将功能分为5层:

  • :“节点”功能,附加了重要的标记。

  • 线 :被识别为非区域的“方式”功能。

  • 多行线 :“关系”功能,形成多行(类型=“多行”或类型=“路由”)。

  • 多角形 :形成多多边形的“关系”特征(类型为“多多边形”或类型为“边界”)和被识别为区域的“方式”特征。

  • other_relations :不属于上述两层的“关系”特征。

驱动程序功能

Supports Georeferencing

This driver supports georeferencing

Supports VirtualIO

This driver supports virtual I/O operations (/vsimem/, etc.)

配置

In the data folder of the GDAL distribution, you can find a osmconf.ini file that can be customized to fit your needs. You can also define an alternate path with the OSM_CONFIG_FILE configuration option.

定制本质上是将OSM属性和键转换为OGR层字段。

字段可以使用SQL表达式(由SQLite引擎计算)从其他字段/标记计算。例如,计算zèorder属性。

“其他标记”字段

如果在 osmconf.ini 文件中,键/值对附加在“其他标记”字段中,语法与PostgreSQL HSTORE类型兼容。见 COLUMN_TYPES 的图层创建选项 PG driver .

例如:

ogr2ogr -f PostgreSQL "PG:dbname=osm" test.pbf -lco COLUMN_TYPES=other_tags=hstore

“所有标记”字段

类似于“other_tags”,只是它包含两个被明确标识为专用字段的键,以及其他键。

默认情况下,“所有标记”被禁用,启用时,它与“其他标记”互斥。

内部工作和性能调整

驱动程序将使用内部SQLite数据库来解析几何图形。如果该数据库保持在100MB以下,它将驻留在RAM中。如果它增长到上面,它将被写入磁盘上的临时文件中。默认情况下,除非您定义 CPL_TMPDIR 配置选项。可以使用 OSM_MAX_TMPFILE_SIZE 配置选项(值以MB为单位)。

对于节点的索引化,默认情况下使用不依赖于SQLite的自定义机制(解决关系的方法的索引化仍然依赖于SQLite)。它可以大大加快操作速度。但是,在某些情况下(不增加节点ID或节点ID不在预期范围内),它可能无法工作,并且驱动程序将输出一条错误消息,建议通过定义 OSM_USE_CUSTOM_INDEXING 配置选项为否。

When custom indexing is used (default case), the OSM_COMPRESS_NODES configuration option can be set to YES (the default is NO). This option might be turned on to improve performances when I/O access is the limiting factor (typically the case of rotational disk), and will be mostly efficient for country-sized OSM extracts where compression rate can go up to a factor of 3 or 4, and help keep the node DB to a size that fit in the OS I/O caches. For whole planet file, the effect of this option will be less efficient. This option consumes additional 60 MB of RAM.

交错阅读

由于OSM文件的性质和驱动程序在内部的工作方式,每层工作的默认读取模式可能无法正常工作,因为在用户应用程序使用之前,层中会积累太多的功能。

Starting with GDAL 2.2, applications should use the GDALDataset::GetNextFeature() API to iterate over features in the order they are produced.

For earlier versions, for large files, applications should set the OGR_INTERLEAVED_READING =YES configuration option to turn on a special reading mode where the following reading pattern must be used:

bool bHasLayersNonEmpty;
do
{
    bHasLayersNonEmpty = false;

    for( int iLayer = 0; iLayer < poDS->GetLayerCount(); iLayer++ )
    {
        OGRLayer *poLayer = poDS->GetLayer(iLayer);

        OGRFeature* poFeature;
        while( (poFeature = poLayer->GetNextFeature()) != NULL )
        {
            bHasLayersNonEmpty = true;
            OGRFeature::DestroyFeature(poFeature);
        }
    }
}
while( bHasLayersNonEmpty );

Note : the ogr2ogr application has been modified to use that OGR_INTERLEAVED_READING mode without any particular user action.

空间滤波

由于.osm或.pbf文件的结构和文件解析的方式,出于效率的原因,应用于点层的空间过滤器也会影响其他层。这可能会导致缺少顶点的直线或多边形。

为了改善这一点,一种可能是使用一个更大的空间滤波器和一些缓冲点层,然后后处理输出应用所需的滤波器。但是,如果多边形的顶点离感兴趣区域很远,则此操作将不起作用。在这种情况下,需要将文件完全转换为另一种格式,并过滤生成的直线或多边形层。

正在读取.osm.bz2文件和/或联机文件

.osm.bz2不是本机识别的,但是您可以使用以下命令(在Unix上)对其进行处理:

bzcat my.osm.bz2 | ogr2ogr -f SQLite my.sqlite /vsistdin/

无需下载即可转换.osm或.pbf文件:

wget -O - http://www.example.com/some.pbf | ogr2ogr -f SQLite my.sqlite /vsistdin/

or

ogr2ogr -f SQLite my.sqlite /vsicurl_streaming/http://www.example.com/some.pbf -progress

并结合上述步骤:

wget -O - http://www.example.com/some.osm.bz2 | bzcat | ogr2ogr -f SQLite my.sqlite /vsistdin/

打开选项

  • CONFIG_FILE=filename :配置文件名。默认为{GDALu DATA}/osmconf.ini文件.

  • USE_CUSTOM_INDEXING=YES/NO :是否启用自定义索引。默认为“是”。

  • COMPRESS_NODES=YES/NO :是否压缩临时数据库中的节点。默认为“否”。

  • MAX_TMPFILE_SIZE=int_val :内存中临时文件的最大大小(MB)。如果超过该值,它将进入磁盘。默认为100。

  • INTERLEAVED_READING=YES/NO :是否启用交错读取。默认为“否”。

也见