I'd like to insert a row with a point geometry with pyspatialite. The sql looks like this:

insert into eqdata(origin_time, url, mag, lat, lon, depth, m_a, region, mt, the_geom)
                 values ('2013-11-10 07:39:59', 'http://geofon.gfz-potsdam.de/event.php?id=gfz2013walq', 4.300000, -19.840000, 70.050000, 45.000000, 'M', 
                 'Near Coast of Northern Chile', 'None', geomfromtext('POINT(-19.840000 70.050000)', 4326));

This does not work and produces this error:

spatialite.dbapi2.IntegrityError: eqdata.the_geom violates Geometry constraint [geom-type or SRID not allowed]

If I execute the same SQL in the same database with spatialite_gui it works without any problem.

How can I handle this problem with pyspatialite?

  • 1
    I don't believe this will solve your problem, but I see two issues with the Well Known Text expression for your Point feature. 1) You've got the point as Lat/Long, and it should be Long/Lat. And 2) in WGS84 coordinates, for Chile, both the Lat and the Long should be negative units (fyi Google does them as lat/long, ugh). So the correct WKT would be: POINT(-70.050000 -19.840000) But these are merely logical errors; they'd just result in your point appearing off the coast of Greenland. :/
    – elrobis
    Jan 7, 2014 at 15:45
  • ..j/c, but you might try your insert without the SRID in your WKT expression (i.e. remove ", 4326"). The db should insert the geometry, assuming the default SRID. If it works, at least then you know your SRID stuff is all tangled up.
    – elrobis
    Jan 7, 2014 at 16:19
  • for me what I needed to do was to do GeomFromText(wkt, srid) since my wkt didn't have the srid in it (as opposed to GeomFromText(wkt) without explicitly specifying the srid). I thought that since I specified the srid when I defined the geometry that it would use this as a default, but it seems like one needs to be explicit. May 18, 2016 at 11:12

1 Answer 1


The most likely cause of violating the geometry constraint is using the wrong geometry type (e.g. you used POINT but declared it as LINE or similar). However that doesn't appear to be the case here, based on your testing with spatialite_gui.

One difference that spatialite_gui (and the spatialite command line tool) have over libspatialite and anything that uses libspatialite directly (including pysqlite extension loading and pyspatialite) is that the spatial_ref_sys table doesn't get initialised automatically in normal libspatialite startup. So it is possible you didn't create the spatial_ref_sys table correctly, or selected an option that doesn't include SRID 4326.

You can check this by something like

SELECT * FROM spatial_ref_sys WHERE srid = 4326

If that doesn't return any rows, then this is definitely the problem. You can read more about how this works in the SpatiaLite Cookbook, however there are recent changes that make InitSpatialMetadata() more flexible (and a bit more complex), so please review the function reference (making sure that the version of the function reference matches the version you're using if not 4.1.0)

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.