【问题标题】:Import only point features with osm2pgsql using style file使用样式文件使用 osm2pgsql 仅导入点特征
【发布时间】:2021-12-31 09:52:00
【问题描述】:

我是新人osm2pqsgl。我已经为整个欧洲下载了一个osm.pbf 文件,我想将此数据添加到我的Postgres 数据库中。但是,我只对points 感兴趣,没有linestrings 也没有polygon,在points 内我只对这些标签及其信息感兴趣(例如denominationname

我已将 style 文件从 osm2pgsql 编辑到此

node,way   historic     text         polygon
node,way   natural      text         polygon 
node,way   religion     text         linear
node,way   tourism      text         polygon
  1. 如何从带有osm2pgsqlosm.pbf 文件中仅导入Point 特征?
  2. 如何仅导入具有特定 tagPoint 功能,例如从具有 osm2pgsqlosm.pbf 文件中的 tourism

【问题讨论】:

    标签: postgresql postgis openstreetmap osm2pgsql


    【解决方案1】:

    我最终使用了osm2pgsql 中的flex output 选项并创建了一个.lua 文件。这里是tag religion

    local tables = {}
        
    -- this creates the table for point and its columns
    tables.religion = osm2pgsql.define_node_table('religion_point', {
        { column = 'osm_type',     type = 'text', not_null = true },
        { column = 'name',     type = 'text', not_null = true},
        { column = 'geom',     type = 'point' },
    }, { schema = 'public' })
    
    -- tags we don't need
    local function clean_tags(tags)
        tags.odbl = nil
        tags.created_by = nil
        tags.source = nil
        tags['source:ref'] = nil
    
        return next(tags) == nil
    end
    
    function osm2pgsql.process_node(object)
        -- We are only interested in religion details
        -- replace here with the tag you want to import i.e. natural, historic, ...
        if not object.tags.religion then
            return
        end
    
        clean_tags(object.tags)
    
        -- Using grab_tag() removes from remaining key/value saved to Pg
        local osm_type = object:grab_tag('religion')
        local name = object:grab_tag('name')
        tables.religion:add_row({
            osm_type = osm_type,
            tags = json.encode(object.tags),
            name = name,
            geom = { create = 'point' }
        })
    end
    

    然后运行它

    $ osm2pgsql -c -d <DATABASENAME> -U postgres -H localhost -O flex -S ./<NAME>.lua ./<FILENAME>.osm.pbf
    

    脚本来源

    【讨论】:

      【解决方案2】:

      不确定osm2pgsql 是否可以即时执行此操作,但是您可以使用osmosis 过滤输入文件。另一种选择是osmium

      另一方面,我不确定先验丢弃多边形是否是一个正确的假设。你可以在建筑物(或其他多边形)上找到很多tourismreligion 等标签。我建议为它们计算质心并union 一起计算。

      【讨论】:

      • 感谢您的回复。我如何只导入带有标签tourismreligionPointPolygon 功能。我将如何修改style file
      • 修改样式无济于事。我建议只过滤带有osmosis 请求标签的点和多边形。有一个example usagedetailed one
      • 我会调查一下,谢谢!
      猜你喜欢
      • 2018-07-04
      • 1970-01-01
      • 2020-09-15
      • 2022-12-07
      • 1970-01-01
      • 2015-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多