Spatialite function to generate a blob from a geometry

Spatialite function to generate a blob from a geometry

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

Why? I'm using aQSqlRelationalTableModel(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 dofunction_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 and I've seen this discussion but it does not seem as flexible asQSqlRelationalTableModelcombined with QDataWidgetMapper (but I could be wrong)

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));

Watch the video: Postgresql: Create Postgis database and import shapefiles.