1

我从http://download.geofabrik.de/europe/great-britain.html获得了 wales-latest.osm.pbf 。这是威尔士的 OSM 文件。如果我将http://www.openstreetmap.org/#map=19/51.50387/-3.08467导出为 XML,我会得到键:值对border_type:city。

当我使用以下代码解析 wales-latest.osm.pbf 文件时,它找不到任何border_type:city 对:

@Override
    protected void parseWays(List<Way> ways) {
        for (Way w : ways) {
            StringBuilder sb = new StringBuilder();
            sb.append("  Nodes: ");
            long lastRef = 0;
            for (Long ref : w.getRefsList()) {
                lastRef+= ref;
                sb.append(lastRef).append(" ");
            }
            sb.append("\n  Key=value pairs: ");
            boolean isCity=false;
            for (int i=0 ; i<w.getKeysCount() ; i++) {
                isCity=isCity||(getStringById(w.getKeys(i)).equals("border_type")&&(getStringById(w.getVals(i)).equals("city")));
                sb.append(getStringById(w.getKeys(i))).append("=")
                        .append(getStringById(w.getVals(i))).append(" ");
            }

            if (!isCity){
                continue;
            }

            System.out.println(sb.toString());
        }
    }

如果我替换"city""territorial"then 它可以找到匹配项。

pbfs 中不存在border_type:city 吗?这仅与 geofabrik.de pbfs 有关吗?我也尝试过 Scotland osm.pbf 文件,但也没有用。

4

1 回答 1

0

一个问题是你只看方法,而不是关系。以Cardiff为例。它位于威尔士,标记为border_type=city,但因为您只是在检查代码找不到它的方式。

您想要解析方式和关系。

于 2013-10-05T01:13:40.400 回答