Spatialite on Android / no such function: GeometryConstraints (code 1): , while compiling:

37 views
Skip to first unread message

Jan

unread,
Feb 27, 2018, 9:57:47 AM2/27/18
to SpatiaLite Users
Hello,

I’m developing an app with spatialite (package jsqlite) tileview AND dynamic dialogs from GIS Server.
I created Spatialite on Android from a Sqlite-Database with WKT.

On short:
dbsqlite.prepare("SELECT InitSpatialMetaData();").step();
dbsqlite.prepare("BEGIN ;").step();

for (String name : lst_tables) {
dbsqlite.prepare("SELECT AddGeometryColumn('" + name + "','GEOMETRY'," + code + ",'GEOMETRY', 'XY',0)").step();
dbsqlite.prepare("UPDATE " + name + " SET GEOMETRY=(GeomFromText(WKT," + code + "))").step();
}
dbsqlite.prepare("COMMIT ;").step();

works fine.

BUT now my problem:
I want to insert data to sqlite/spatialite with SQLiteOpenHelper

For a simple, I'll create a simple record where I set only the most necessary values.
ID, INSERT_DATE, INSERT_USER
After that I want update for record with all other columns.

But now an essential problem.
While inserting new a record with or without geometry I get an exception:
no such function: GeometryConstraints (code 1): , while compiling:
INSERT INTO MYTABLE (FID, INSERTDAT,INSERTUSER,ANDROID) VALUES ('-1','2018-02-27','Username,'2');
INSERT INTO MYTABLE (FID, INSERTDAT,INSERTUSER,ANDROID, GEOMETRY) VALUES ('-1','2018-02-27','
Username','2',ST_POINT(-1,-1));
INSERT INTO MYTABLE (FID, INSERTDAT,INSERTUSER,ANDROID, GEOMETRY) VALUES ('-1','2018-02-27','
Username','2',MakePoint(-1,-1,25832));

I created:
SELECT AddGeometryColumn('TABLENAME','GEOMETRY',25832,'GEOMETRY', 'XY',0)
SELECT AddGeometryColumn('test_geom', ‚GEOM‘,  4326, 'POINT', 'XY', 0);

https://www.gaia-gis.it/gaia-sins/spatialite-cookbook/html/new-geom.html

Now I tested all 3 ways (nothing, 0, 1)
Everytime same result.

I’ve seen, trigger working on every update and not only while updating GEOMETRY-column.
Is this a good idea?
It didn't work.

DROP TRIGGER ggi_MYTABLE_GEOMETRY;
CREATE TRIGGER ggi_MYTABLE_GEOMETRY BEFORE INSERT ON MYTABLE
FOR EACH ROW BEGIN
SELECT RAISE(ROLLBACK, 'MYTABLE.GEOMETRY violates Geometry constraint [geom-type or SRID not allowed]')
WHERE NEW.GEOMETRY notnull AND  (SELECT geometry_type FROM geometry_columns
WHERE Lower(f_table_name) = Lower('WA_VALVE') AND Lower(f_geometry_column) = Lower('GEOMETRY')
AND GeometryConstraints(NEW.GEOMETRY, geometry_type, srid) = 1) IS NULL;
END;


Or do you have an other idea for me?

Thanks

Regards,

Jan

br...@frogmouth.net

unread,
Feb 27, 2018, 4:58:29 PM2/27/18
to spatiali...@googlegroups.com

I’m not familiar with doing this in Android / Java (especially the SQLiteOpenHelper part), but a missing function could be because you’re using a different connection to the database (where you didn’t load the spatialite extension). There just isn’t enough code to say – you could try producing a minimal, compilable, self-contained example. Looking at the SQLiteOpenHelper code, you would probably want to do the extension loading in the onOpen() callback.

 

If you can’t get that to work, a hack would be to drop the triggers. That isn’t a good idea though.

 

Brad

--
You received this message because you are subscribed to the Google Groups "SpatiaLite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spatialite-use...@googlegroups.com.
To post to this group, send email to spatiali...@googlegroups.com.
Visit this group at https://groups.google.com/group/spatialite-users.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages