Пример #1
0
def write_neighbor_visualization_kml(known, k=6, verbose=False):
    """Write a KML file showing k nearest neighbors among known locations."""
    X = known.loc[:, XCOLS]
    neighbors = NearestNeighbors(n_neighbors=k).fit(X)
    _, indices = neighbors.kneighbors(X)
    colors = 'red,orange,yellow,green,cyan,purple'.split(',')
    with open('../Data/visualize_neighbors.kml', 'wb') as kml:
        kml.write('<?xml version="1.0" encoding="UTF-8"?>\n')
        kml.write('<kml xmlns="http://www.opengis.net/kml/2.2">\n')
        kml.write('<Document>\n')
        common.write_styles(kml)
        for i in range(len(known)):
            kml.write('  <Folder id="%s">\n' % (known.ix[i].ptol_id, ))
            kml.write('      <name>%s</name>\n' % (known.ix[i].ptol_id, ))
            ax = known.ix[i, XCOLS].values
            ay = known.ix[i, YCOLS].values
            alabel = known.ix[i].ptol_id
            common.write_point(kml, 'red', ax, alabel)
            common.write_point(kml, 'red', ay, alabel)
            if verbose: print known.ix[i].ptol_id, ax, ay
            points = [indices[i, j] for j in range(1, k)]
            for m in range(len(points)):
                j = points[m]
                bx = known.ix[j, XCOLS].values
                by = known.ix[j, YCOLS].values
                blabel = known.ix[j].ptol_id
                common.write_point(kml, 'yellow', bx, blabel)
                common.write_point(kml, 'yellow', by, blabel)
                common.write_line(kml, ax, bx, colors[m])
                common.write_line(kml, ay, by, colors[m])
                if verbose: print '  ', known.ix[j].ptol_id, bx, by
            kml.write('  </Folder>\n')
        kml.write('</Document>\n')
        kml.write('</kml>\n')
Пример #2
0
def write_triangle_visualization_kml(tri, known, unknown):
    """Compute unknown modern coordinates from known ones using the
    given triangulation."""
    colors = ['red', 'yellow', 'green']
    with open('../Data/visualize_triangles.kml', 'wb') as kml:
        kml.write('<?xml version="1.0" encoding="UTF-8"?>\n')
        kml.write('<kml xmlns="http://www.opengis.net/kml/2.2">\n')
        kml.write('<Document>\n')
        common.write_styles(kml)
        for simp in tri.simplices:
            print simp
            tri_name = 'Triangle_%s' % '_'.join(str(x) for x in simp)
            kml.write('  <Folder id="%s">\n' % (tri_name, ))
            kml.write('      <name>%s</name>\n' % (tri_name, ))
            write_triangle(kml, tri_name, colors, [(known.ix[x].ptol_lat, known.ix[x].ptol_lon) for x in simp])
            write_triangle(kml, tri_name, colors, [(known.ix[x].modern_lat, known.ix[x].modern_lon) for x in simp])
            kml.write('  </Folder>\n')
        kml.write('</Document>\n')
        kml.write('</kml>\n')
Пример #3
0
def write_triangle_visualization_kml(tri, known, unknown):
    """Compute unknown modern coordinates from known ones using the
    given triangulation."""
    colors = ['red', 'yellow', 'green']
    with open('../Data/visualize_triangles.kml', 'wb') as kml:
        kml.write('<?xml version="1.0" encoding="UTF-8"?>\n')
        kml.write('<kml xmlns="http://www.opengis.net/kml/2.2">\n')
        kml.write('<Document>\n')
        common.write_styles(kml)
        for simp in tri.simplices:
            print simp
            tri_name = 'Triangle_%s' % '_'.join(str(x) for x in simp)
            kml.write('  <Folder id="%s">\n' % (tri_name, ))
            kml.write('      <name>%s</name>\n' % (tri_name, ))
            write_triangle(kml, tri_name, colors,
                           [(known.ix[x].ptol_lat, known.ix[x].ptol_lon)
                            for x in simp])
            write_triangle(kml, tri_name, colors,
                           [(known.ix[x].modern_lat, known.ix[x].modern_lon)
                            for x in simp])
            kml.write('  </Folder>\n')
        kml.write('</Document>\n')
        kml.write('</kml>\n')
Пример #4
0
def write_neighbor_visualization_kml(known, k=6, verbose=False):
    """Write a KML file showing k nearest neighbors among known locations."""
    X = known.loc[:, XCOLS]
    neighbors = NearestNeighbors(n_neighbors=k).fit(X)
    _, indices = neighbors.kneighbors(X)
    colors = "red,orange,yellow,green,cyan,purple".split(",")
    with open("../Data/visualize_neighbors.kml", "wb") as kml:
        kml.write('<?xml version="1.0" encoding="UTF-8"?>\n')
        kml.write('<kml xmlns="http://www.opengis.net/kml/2.2">\n')
        kml.write("<Document>\n")
        common.write_styles(kml)
        for i in range(len(known)):
            kml.write('  <Folder id="%s">\n' % (known.ix[i].ptol_id,))
            kml.write("      <name>%s</name>\n" % (known.ix[i].ptol_id,))
            ax = known.ix[i, XCOLS].values
            ay = known.ix[i, YCOLS].values
            alabel = known.ix[i].ptol_id
            common.write_point(kml, "red", ax, alabel)
            common.write_point(kml, "red", ay, alabel)
            if verbose:
                print known.ix[i].ptol_id, ax, ay
            points = [indices[i, j] for j in range(1, k)]
            for m in range(len(points)):
                j = points[m]
                bx = known.ix[j, XCOLS].values
                by = known.ix[j, YCOLS].values
                blabel = known.ix[j].ptol_id
                common.write_point(kml, "yellow", bx, blabel)
                common.write_point(kml, "yellow", by, blabel)
                common.write_line(kml, ax, bx, colors[m])
                common.write_line(kml, ay, by, colors[m])
                if verbose:
                    print "  ", known.ix[j].ptol_id, bx, by
            kml.write("  </Folder>\n")
        kml.write("</Document>\n")
        kml.write("</kml>\n")