geo.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:cv4ag 作者: worldbank 项目源码 文件源码
def get_ways_data(elements, coords):
    ways_data = {}
    for element in elements:
        # Only process ways
        if element.get('type') != 'way':
            continue
        # Only process ways with 3 or more nodes, otherwise
        # Shapely will complain.
        nodes = element.get('nodes')
        if len(nodes) < 3:
            continue
        exterior = [(coords[node].get('lat'), coords[node].get('lon')) \
            for node in nodes]
        # Build the polygon and compute its bbox and centroid
        way_polygon = Polygon(exterior)
        ways_data[element.get('id')] = {
            'bounds': way_polygon.bounds,
            'lat': way_polygon.centroid.x,
            'lon': way_polygon.centroid.y}

    # Done
    return ways_data
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号