From: Eric Hodel Date: 2009-06-24T15:42:27+09:00 Subject: Re: How to connect to SpatiaLite, a spatial enabled sqlite3 db? On Jun 23, 2009, at 23:18, Jan Martin wrote: > I am a beginner making a decision on what programing language I spent > more time to learn it. > In principle I really really like ruby. > > However for a GIS project of mine I like to use spatialite, a sqlite > database with spatial extension: > http://www.gaia-gis.it/spatialite/ > > And it seems there is no way to interface it from ruby? From your python code below, it seems to be plain old SQL. > def index(req): > data = util.FieldStorage(req) > lat= data['lat']; > lon= data['lon']; > > DB = sqlite.connect('exif.sqlite'); > DB.enable_load_extension(True); > DB.execute('SELECT load_extension("libspatialite.so")'); Looks like the ruby equivalent method to this DB.execute would be SQLite3::Database#execute, which should handle the same SQL syntax. > DBCursor = DB.cursor() > > strSQL = "SELECT FromPath > FROM ExifPhoto > WHERE Distance(GpsGeometry, > GeomFromText(\"POINT("+lat+" "+lon+")\", 4326)) = > ( > SELECT Min(Distance(GpsGeometry, > GeomFromText(\"POINT("+lat+" "+lon+")\", 4326))) > FROM ExifPhoto > );" > > DBCursor.execute( strSQL ); Ditto.