I try to find the nearest point in geoida database for every point stored in second database.
Here’s may approach, which is extremely slow. geoida.db stores +55000 coordinates
import sqlite3
from kdtree import KDTree
database = sqlite3.connect('geoida.db')
cursor = database.cursor()
cursor.execute("select lat, lon from coords")
geoid = cursor.fetchall()
database = sqlite3.connect('F.tsj')
cursor = database.cursor()
cursor.execute("select C1, C2 from tblSoPoints")
results = cursor.fetchall()
for line in results:
tree = KDTree.construct_from_data(geoid)
nearest = tree.query(query_point=line, t=2)
print nearest[0]
both databases contain latitudes and longitudes
Simply create the tree outside the loop: