Darin
Darin

Reputation: 11

Python + Spatialite + Virualknn

So, I'm playing around with the Spatialite Virtualknn to try my hand at some routing using open street maps data and Python.

After downloading the Australian osm data, I've extracted a roads layer and created a separate Spatialite database.

spatialite_osm_net.exe -o australia-latest.osm.pbf -d aus_road.sqlite -T roads

I then ran this query from Spatialite_gui

select ST_AsText(ref_geometry)   
from knn where f_table_name = 'roads'  
and ref_geometry = ST_POINT(145.61249, -38.333801)

And got these 3 results

POINT(145.61249 -38.333801)  
POINT(145.61249 -38.333801)  
POINT(145.61249 -38.333801)  

So I then created this quick and nasty Python script (Python 3.9.0 but I have tried other versions)

import spatialite  
file = "./aus_road.sqlite"  
db = spatialite.connect(file)  
allme = db.execute("select ST_AsText(ref_geometry) from knn where f_table_name = 'roads' and ref_geometry = ST_POINT(145.61249, -38.333801)")  
allme.fetchall()  

And all I get back is

[]

Anybody have any idea why Virtualknn wont work in Python?

Upvotes: 1

Views: 140

Answers (0)

Related Questions