You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Overpass QL的if语句中结合正则表达式筛选OSM节点?

巴黎住宅类节点筛选:修正后的Overpass QL代码

这个需求完全可以实现,Overpass QL的if:条件语句支持结合正则表达式完成这类“存在则校验,不存在则放行”的逻辑。

原代码的问题

原代码里的if语句存在语法错误,且未覆盖“无building标签则直接纳入结果”的场景,导致筛选逻辑不完整。

修正后的完整代码

[out:json][timeout:50];

// 定位巴黎区域(admin_level=8对应巴黎市)
area["name"="Paris"][admin_level=8]->.searchArea;

// 筛选符合条件的节点
node(area.searchArea)
  ["addr:housenumber"]["addr:postcode"]  // 必须包含门牌号和邮编标签
  [!"contact:email"]
  [!"contact:phone"]
  [!"phone"]
  [!"email"]
  [!"ref:FR:SIRET"]
  [!"landuse"]
  [!"amenity"]
  [!"leisure"]
  [!"website"]
  [!"shop"]
  [!"brand"]
  [!"office"]
  [!"tourism"]
  [!"operator"]
  // 核心逻辑:无building标签 或 building标签匹配指定正则
  (if: !t["building"] || t["building"] ~ "dormitory|apartments|yes|residential|house");

// 输出结果
out body;

关键逻辑说明

(if: !t["building"] || t["building"] ~ "dormitory|apartments|yes|residential|house") 是实现需求的核心:

  • !t["building"]:匹配没有building标签的节点,直接纳入结果
  • t["building"] ~ "...":匹配有building标签且值符合正则的节点,正则包含了你指定的住宅类建筑类型

另外,原代码里多余的嵌套查询结构已简化,直接筛选后输出即可。

内容的提问来源于stack exchange,提问作者Arcélone

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 14:55:01