0

Following the top answer on a previous question about storing geometries in a spatialite database, I am trying to update a spatialite table using:

engine.execute("SELECT AddGeometryColumn('your_table', 'geog', 27700, 'polygon', 'XY');")
# add a Spatialite geometry column called 'geog' to the table, using ESPG 27700, data type POLYGON and 2 dimensions
    # (x, y)
engine.execute("UPDATE your_table SET geog = GeomFromWKB(geometry, 27700);")

The code worked fine when I was using point data. However, when I use vector data I keep getting the error your_table.geog violates Geometry constraint [geom-type or SRID not allowed] I know the SRID is ok, so from the error I assume it is the geom-type that is incorrect. I have checked the geom-type in a couple ways: 1. opening the layer in QGIS and checking the porperties; and 2. opening the database in spatialite-gui and 'check geometries'. I have also tried using polygon, multipolygon and multipolygonz as the 4th argument in the AddGeometryColumn selection, but I get the same error. So, what is the best way to check which geometry it should be?

3
  • 3
    That happens usually with shapefiles which contain a mixture of polygons and multipolygons. If you initialize the table for polygons the multipolygons are rejected and vice versa. You have two options 1) initialize the table as a generic "GEOMETRY" and it accepts any geometries, but some sofware will have problems with dealing such table or 2) initialize the table for multipolygons and insert geometries through the CastToMultiPolygon function gaia-gis.it/gaia-sins/spatialite-sql-latest.html.
    – user30184
    Jun 3, 2019 at 20:39
  • @user30184. Thank you for you answer. I used the second one and it worked
    – Perfalcon
    Jun 4, 2019 at 8:03
  • Please write as an answer what, and how did you do that.
    – user30184
    Jun 4, 2019 at 13:12

1 Answer 1

2

Using @user30184's comment, I initialized the table for multipolygons, using the CastToMultiPolygon function found here. The second part of my above code was changed to:

    # Spatialite geometry objects
    engine.execute("UPDATE your_table SET geom = CastToMultiPolygon(ST_GeomFromWKB(geometry, 27700));")```

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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