Ejemplo n.º 1
0
def densify(targetNodes, factor):
    for i, curr in enumerate(targetNodes):
        if (i == len(targetNodes) - 1): break
        next = targetNodes[i + 1]
        parent = curr.getparent()
        # Obtain data from both current and next nodes
        nodes = {'curr': curr, 'next': next}
        for key, node in nodes.items():
            nodes[key] = {
                # 'time': DateTime.strptime(node[0].text, '%Y-%m-%dT%H:%M:%SZ'),
                'lat': float(node.attrib['lat']),
                'lon': float(node.attrib['lon']),
                'node': node,
            }
        # using the geodata, create a virtual line to get information.
        line = Geo([nodes['curr']['lat'], nodes['curr']['lon']],
                   [nodes['next']['lat'], nodes['next']['lon']])
        # subdivide the line into corresponding chunks and add the to the tree after curr
        for j in range(factor):
            pointC = line.point(line.distance * (1 / (j + 1)))
            node = DeepCopy(curr)
            node.attrib['lat'] = '%.7f' % round(pointC[0], 7)
            node.attrib['lon'] = '%.7f' % round(pointC[1], 7)
            curr.addnext(node)