pyQGIS use non-spatial data in a spatialite database

Just incase you want to build and use non spatial database tables from inside python you can use the following commands.
You can also do as you would to add spatial columns too but I needed code to be able spcifically to get at non spatial tables/data
from pyspatialite import dbapi2 as db
conn = db.connect(spatialitedb)
cur = conn.cursor()
cur.execute('DROP TABLE IF EXISTS LINZ_mapsets')
cur.execute('CREATE TABLE LINZ_mapsets (id integer, Name integer, EPSG integer, Title text)')
cur.execute("INSERT INTO LINZ_mapsets VALUES (1,1197,5479,'NZ Ross Dependency')")
cur.execute("INSERT INTO LINZ_mapsets VALUES (2,89,3793,'NZ Chatham Is')")
rs = cur.execute('SELECT * from LINZ_mapsets')
for row in rs:
print row

Leave a Reply

Your email address will not be published. Required fields are marked *

8 × = twenty four