wkt convert osmosis .poly ( PolygonFilter input )

MULTIPOLYGON WKT 数据地址 21523.txt

Osmosis/Polygon Filter File Format

wkt 转 poly

import sys
import numpy as np

for ipath in sys.argv[1:]:
    if not ipath.endswith('.txt'):
        print(f'skip {ipath}')
    opath = f'{ipath}.poly'
    print(opath)
    with open(ipath) as f:
        text = f.read()
    with open(opath, 'w') as f:
        f.write('geofence\n')
        cols = text.split('(')
        for idx, col in enumerate(cols):
            if len(col) < 100:
                continue
            f.write(f'area{idx}\n')
            coords = np.array([[float(x) for x in lla.split()] for lla in col[:-6].split(',')])
            for c in coords:
                f.write(f'    {c[0]} {c[1]}\n')
            f.write('END\n')
            # print(coords)
        f.write('END\n')
    print(f'wrote to {opath}')

输出 21523.txt.poly

开始过滤数据

 osmosis 
 --read-xml file="msd.osm"
 --bounding-polygon file="21523.txt.poly" completeWays="yes" clipIncompleteEntities="true" 
 --write-xml file="21523.osm"

从 msd.osm 中以 21523.txt.poly 为 boundary 过滤出了高亮部分的 osm 数据
在这里插入图片描述

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 游动-白 设计师:白松林 返回首页