Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 2 down vote accepted

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')")

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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