What I'm trying to achieve is to create a geometry column of a point based on the latitude and longitude of that particular row in the already created table.

Given the following code:

from pysqlite2 import dbapi2 as sqlite3

conn = sqlite3.connect('adde.sqlite')
conn.execute("SELECT load_extension('libspatialite-2.dll');")
conn.execute("SELECT InitSpatialMetadata();")
conn.execute("SELECT AddGeometryColumn('coords','geom_column', 4326, 'Point', 2);")
conn.execute("UPDATE coords SET geom_column = GEOMETRYFROMTEXT('POINT('||longitude||' '||latitude||')', 4326);")

I receive the error:

AddGeometryColumn() error: "insert on table 'geometry_columns' violates constraint: 'spatial_ref_sys.srid'"

I've been able to create the column in the Spatialite GUI no problem, but I'd like to do all of this programmatically using Python. I've searched for a while now and I'm coming up a bit short. Any guidance as to why I'm receiving this particular error would be greatly appreciated.

I'm using Python 2.6 and pysqlite2 on Windows 7 64-bit


I solved it by inserting the definition for the required SRS into the database before adding the geometry column:

conn.execute("INSERT INTO spatial_ref_sys (srid, auth_name, auth_srid, ref_sys_name, proj4text) VALUES (4326, 'epsg', 4326, 'WGS 84', '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs')")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.