Using QGIS Python API, I want to avoid updating geometry with an UPDATE sql command.

Why? I'm using a QSqlRelationalTableModel (see model-view programming if curious) and there are built-in editing strategy I want to benefit.

My issue is that for geometry, I should update the model content with a Spatialite geometry blob (specs).

I didn't found any blob functions in Spatialite for geometry, so I could do function_transform_geometry_to_spatialite_blob(MakePoint(0, 0, 4326)) and it returns a blob with geometry embedded as a text I can use to update my Geometry field within the model. Are there any I missed?

Maybe, it's not the right approach. You may have another suggestions/opinions.

PS: I know about http://blog.vitu.ch/10112013-1201/qgis-relations and I've seen this discussion but it does not seem as flexible as QSqlRelationalTableModel combined with QDataWidgetMapper (but I could be wrong)

  • 1
    You could make calls to the underlying spatialite functions (in C++, rather than SQL). I'd caution that if you do that, you are working around QGIS which may cause other issues later. Perhaps making this less abstract would help - show a small, executable example and say what you want to do instead.
    – BradHards
    Nov 21, 2015 at 0:31

1 Answer 1


It was obvious and I didn't read well the RTFM. See this discussion on the Spatialite mailing list.

The answer is:

SELECT ST_GeomFromText('POINT(1 2)', 4326);


SELECT MakePoint(1, 2, 4326);

To make result as a text, do:

SELECT hex(MakePoint(1, 2, 4326));

Your Answer

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

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