I have a shapefile with polygons and want to add an attribute field with the WKT in QGIS 3.4.
geom_to_wkt in the Field Calculator isn't working and I don't know how to do it. Any ideas?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
Tested on QGIS 2.18 and QGIS 3.4
I can suggest using a
"Virtual Layer" through
Layer > Add Layer > Add/Edit Virtual Layer...
Let's assume there is a polygon layer
"districts" with its attribute table accordingly, see image below.
With the following Query by means of QGIS native geometry function
geom_to_wkt, it is possible to achieve the result
SELECT *, geom_to_wkt(geometry) AS wkt FROM "districts"
The output Virtual Layer will maintain original geometry and all initial attributes including a new, namely 'wkt'.
The alternative query will contain
It returns the Well-Known Text representation of the geometry/geography. Optional argument may be used to reduce the maximum number of decimal digits after floating-point used in the output (defaults to 15).
SELECT *, ST_AsText(geometry) AS wkt FROM "districts"