2

I see there are functions in QGIS that supposed to generate geometry, like geom_from_wkt. How do I actually display it?

When I create a new field (in a field calculator) with a formula, say

bounds(make_line(make_point($x-1,$y-1),make_point($x+1,$y+1)))

its value becomes NULL no matter what type I select.

And If I say Update existing field" and choose <geometry> in the dropdown -- nothing changes, I still do not see rectangles.

3

That expression returns an object of type geometry.
Therefore it is not possible to save its value (as written) in any columns of the attribute table.
However, the expression can be used:


About your expression:

It is assumed that you are applying that expression to a single-part point geometries layer.

If they are not points, it returns NULL. If they are multi-part points, it returns a square of 2 units side, only for the first part of the collection.

Although you cannot use it as it is in the attribute table, you could modify it a bit so that it returns a text string that describes the generated geometry, known as Well-Known Text (WKT):

geom_to_wkt( bounds( make_line( 
  make_point( $x-1, $y-1),
  make_point( $x+1, $y+1))))

Test it in a Text(String) with Output field length of 500.

2
  • So, the answer, it seems, is I cannot create or overwrite a geometry attribute with these expressions in the existing layer which already has a geometry attribute. Instead, I have to use the alternatives you listed. – user143266 Nov 13 '19 at 4:18
  • The expression takes the X and Y coordinates of a point, and with them it forms a polygon (after the transformation that the expression applies). You cannot easily save polygons in a points layer. However you can make the points "look like polygons", with that expression in the geometry generator of the styling. The other option is that you create a new polygon layer, be it a "real" layer with the Geometry by Expression tool or a virtual layer. – Gabriel De Luca Nov 13 '19 at 4:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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