I am using PyQGIS 3.
I pull in a line table from postgres database. and one of the attributes is a point geometry, when I open the attribute table that column shows data in this format:
SRID=4326;POINT(-101.82683089226423 31.232703471526868)
and printing out this attribute for each feature prints this out as a string. Printing out the type name and type I get this:
TypeName:geometry, Type:10
How do I deal with this in my python code?
Do I have to treat it like a string and split the text to get the "POINT(-101.82683089226423 31.232703471526868)
" or is there a way to treat this as a point geometry so that I can do QgsGeometry
things with it?
I tried this:
print(QgsGeometry.fromWkt(feature['label_location']))
and I got this:
<QgsGeometry: null>
How do I cast this to a QgsGeometry
?
This works:
QgsGeometry.fromWkt(feature['label_location'].split(';')[-1])
but seems kind of crude.
Is there a better way?
I tried to use the above method to update the attribute, but I could not update it in a way that maintains the format. I have another place in my code that expects this specific string format and in the postgres table it is wkb. I would like to avoid running a query to do this and would ideally find a way to use all QGIS functions but it may not be possible.