Skip to main content
added 201 characters in body
Source Link
Babel
  • 74.9k
  • 15
  • 87
  • 227

You can create a point geometry at the bottom left of the current map canvas that dynamically changes by first creating a virtual field with the coordinates of this point in any of your vector layers. Then you can access these coordinates a virtual layer query to create the point.

  1. Inside field calculator (to create coordinates), the variable @map_extent from QGIS expressions is not available. So you have to create a custom function for the task to create the map canvas extent, see here how: https://gis.stackexchange.com/a/411313/88814 (thanks @katagena for the hint in the comment to this post).

    Then create two fields canvx for the x-coordinate with x_min(currentExtent()) and do the same for canvy with y_min(currentExtent()).

  2. New create a virtual layer with this query and replace my_layer with the name of the layer that contains the attributes canvx and canvy:

     SELECT MakePoint (p.canvxx , p.canvyy) FROM my_layercolor as p;p where p.id=1;
    

    The where p.id=1 part is optional, but is to avoid creating one and the same point at the bottom left separately for each feature in your layer. Change the id=1 part so that it fits your data.

You can create a point geometry at the bottom left of the current map canvas that dynamically changes by first creating a virtual field with the coordinates of this point in any of your vector layers. Then you can access these coordinates a virtual layer query to create the point.

  1. Inside field calculator (to create coordinates), the variable @map_extent from QGIS expressions is not available. So you have to create a custom function for the task to create the map canvas extent, see here how: https://gis.stackexchange.com/a/411313/88814 (thanks @katagena for the hint in the comment to this post).

    Then create two fields canvx for the x-coordinate with x_min(currentExtent()) and do the same for canvy with y_min(currentExtent()).

  2. New create a virtual layer with this query and replace my_layer with the name of the layer that contains the attributes canvx and canvy:

     SELECT MakePoint (p.canvx , p.canvy) FROM my_layer as p;
    

You can create a point geometry at the bottom left of the current map canvas that dynamically changes by first creating a virtual field with the coordinates of this point in any of your vector layers. Then you can access these coordinates a virtual layer query to create the point.

  1. Inside field calculator (to create coordinates), the variable @map_extent from QGIS expressions is not available. So you have to create a custom function for the task to create the map canvas extent, see here how: https://gis.stackexchange.com/a/411313/88814 (thanks @katagena for the hint in the comment to this post).

    Then create two fields canvx for the x-coordinate with x_min(currentExtent()) and do the same for canvy with y_min(currentExtent()).

  2. New create a virtual layer with this query and replace my_layer with the name of the layer that contains the attributes canvx and canvy:

     SELECT MakePoint (p.x , p.y) FROM color as p where p.id=1;
    

    The where p.id=1 part is optional, but is to avoid creating one and the same point at the bottom left separately for each feature in your layer. Change the id=1 part so that it fits your data.

deleted 914 characters in body
Source Link
Babel
  • 74.9k
  • 15
  • 87
  • 227

Virtual layer

For a dynamic solution (createYou can create a point geometry at the lowerbottom left corner of the current map canvas that changes when the canvasdynamically changes), create by first creating a Virtual layer with this query and replace polyvirtual field with the namecoordinates of a polygon layer:

SELECT MakePoint (MbrMinX ( Extent (p.geometry)), MbrMinY (Extent (p.geometry))) FROM poly as p;

Limitation: get map canvas extent

The difficulty is to get the map canvas extent in a similar way as with the variable @map_extentthis point in QGIS expressions. In SpatialLite's SQL functions reference list, I don't see any function to get the map canvas extent (I posted a new question for this: Get extent of the current map canvas in a virtual layer query in QGIS). Virtualof your vector layers are based on SpatialLite: The underlying engine uses SQLite and SpatiaLite to operate.

That sayed, Then you first must have a polygon (canvas bounding box) for the query.

Unfortunatley, getting the coordinate values of the point you're looking for with x(point_n(@map_extent, 1)) works fine e.g. in the label dialog, but does return only NULL in the attribute table/field calculator. Somehow this makes sense as the layer has it's own extent, but has no connection to the (current) map canvas extent at all (canvas can change, but layer remains unchanged). So you can't useaccess these coordinates a virtual fieldlayer query to create coordinate values you can access in the SQL query.

Geometry by expression

What you can do - but then it's not a dynamic solution any more:

You can use the same expression as with geometry generator, but use Menu Processing > Toolbox > Geometry by expression. It creates the point as an actual geometry, not just symbology.

You must do this based on any input vector layer (point, line or polygon). The point will be generator on a new layer.

See also here for similarities and differences between Geometry generator and geometry by expression.

  1. Inside field calculator (to create coordinates), the variable @map_extent from QGIS expressions is not available. So you have to create a custom function for the task to create the map canvas extent, see here how: https://gis.stackexchange.com/a/411313/88814 (thanks @katagena for the hint in the comment to this post).

    Then create two fields canvx for the x-coordinate with x_min(currentExtent()) and do the same for canvy with y_min(currentExtent()).

  2. New create a virtual layer with this query and replace my_layer with the name of the layer that contains the attributes canvx and canvy:

     SELECT MakePoint (p.canvx , p.canvy) FROM my_layer as p;
    

Virtual layer

For a dynamic solution (create a point at the lower left corner of the map canvas that changes when the canvas changes), create a Virtual layer with this query and replace poly with the name of a polygon layer:

SELECT MakePoint (MbrMinX ( Extent (p.geometry)), MbrMinY (Extent (p.geometry))) FROM poly as p;

Limitation: get map canvas extent

The difficulty is to get the map canvas extent in a similar way as with the variable @map_extent in QGIS expressions. In SpatialLite's SQL functions reference list, I don't see any function to get the map canvas extent (I posted a new question for this: Get extent of the current map canvas in a virtual layer query in QGIS). Virtual layers are based on SpatialLite: The underlying engine uses SQLite and SpatiaLite to operate.

That sayed, you first must have a polygon (canvas bounding box) for the query.

Unfortunatley, getting the coordinate values of the point you're looking for with x(point_n(@map_extent, 1)) works fine e.g. in the label dialog, but does return only NULL in the attribute table/field calculator. Somehow this makes sense as the layer has it's own extent, but has no connection to the (current) map canvas extent at all (canvas can change, but layer remains unchanged). So you can't use a virtual field to create coordinate values you can access in the SQL query.

Geometry by expression

What you can do - but then it's not a dynamic solution any more:

You can use the same expression as with geometry generator, but use Menu Processing > Toolbox > Geometry by expression. It creates the point as an actual geometry, not just symbology.

You must do this based on any input vector layer (point, line or polygon). The point will be generator on a new layer.

See also here for similarities and differences between Geometry generator and geometry by expression.

You can create a point geometry at the bottom left of the current map canvas that dynamically changes by first creating a virtual field with the coordinates of this point in any of your vector layers. Then you can access these coordinates a virtual layer query to create the point.

  1. Inside field calculator (to create coordinates), the variable @map_extent from QGIS expressions is not available. So you have to create a custom function for the task to create the map canvas extent, see here how: https://gis.stackexchange.com/a/411313/88814 (thanks @katagena for the hint in the comment to this post).

    Then create two fields canvx for the x-coordinate with x_min(currentExtent()) and do the same for canvy with y_min(currentExtent()).

  2. New create a virtual layer with this query and replace my_layer with the name of the layer that contains the attributes canvx and canvy:

     SELECT MakePoint (p.canvx , p.canvy) FROM my_layer as p;
    
added 227 characters in body
Source Link
Babel
  • 74.9k
  • 15
  • 87
  • 227

Virtual layer

For a dynamic solution (create a point at the lower left corner of the map canvas that changes when the canvas changes), create a Virtual layer with this query and replace poly with the name of a polygon layer:

SELECT MakePoint (MbrMinX ( Extent (p.geometry)), MbrMinY (Extent (p.geometry))) FROM poly as p;

Limitation: get map canvas extent

The difficulty is to get the map canvas extent in a similar way as with the variable @map_extent in QGIS expressions. In SpatialLite's SQL functions reference list, I don't see any function to get the map canvas extent (I posted a new question for this: Get extent of the current map canvas in a virtual layer query in QGIS). Virtual layers are based on SpatialLite: The underlying engine uses SQLite and SpatiaLite to operate.

That sayed, you first must have a polygon (canvas bounding box) for the query.

Unfortunatley, getting the coordinate values of the point you're looking for with x(point_n(@map_extent, 1)) works fine e.g. in the label dialog, but does return only NULL in the attribute table/field calculator. Somehow this makes sense as the layer has it's own extent, but has no connection to the (current) map canvas extent at all (canvas can change, but layer remains unchanged). So you can't use a virtual field to create coordinate values you can access in the SQL query.

Geometry by expression

What you can do - but then it's not a dynamic solution any more:

You can use the same expression as with geometry generator, but use Menu Processing > Toolbox > Geometry by expression. It creates the point as an actual geometry, not just symbology.

You must do this based on any input vector layer (point, line or polygon). The point will be generator on a new layer.

See also here for similarities and differences between Geometry generator and geometry by expression.

Virtual layer

For a dynamic solution (create a point at the lower left corner of the map canvas that changes when the canvas changes), create a Virtual layer with this query and replace poly with the name of a polygon layer:

SELECT MakePoint (MbrMinX ( Extent (p.geometry)), MbrMinY (Extent (p.geometry))) FROM poly as p;

Limitation: get map canvas extent

The difficulty is to get the map canvas extent in a similar way as with the variable @map_extent in QGIS expressions. In SpatialLite's SQL functions reference list, I don't see any function to get the map canvas extent (I posted a new question for this: Get extent of the current map canvas in a virtual layer query in QGIS).

That sayed, you first must have a polygon (canvas bounding box) for the query.

Unfortunatley, getting the coordinate values of the point you're looking for with x(point_n(@map_extent, 1)) works fine e.g. in the label dialog, but does return only NULL in the attribute table/field calculator. Somehow this makes sense as the layer has it's own extent, but has no connection to the (current) map canvas extent at all (canvas can change, but layer remains unchanged). So you can't use a virtual field to create coordinate values you can access in the SQL query.

Geometry by expression

What you can do - but then it's not a dynamic solution any more:

You can use the same expression as with geometry generator, but use Menu Processing > Toolbox > Geometry by expression. It creates the point as an actual geometry, not just symbology.

You must do this based on any input vector layer (point, line or polygon). The point will be generator on a new layer.

See also here for similarities and differences between Geometry generator and geometry by expression.

Virtual layer

For a dynamic solution (create a point at the lower left corner of the map canvas that changes when the canvas changes), create a Virtual layer with this query and replace poly with the name of a polygon layer:

SELECT MakePoint (MbrMinX ( Extent (p.geometry)), MbrMinY (Extent (p.geometry))) FROM poly as p;

Limitation: get map canvas extent

The difficulty is to get the map canvas extent in a similar way as with the variable @map_extent in QGIS expressions. In SpatialLite's SQL functions reference list, I don't see any function to get the map canvas extent (I posted a new question for this: Get extent of the current map canvas in a virtual layer query in QGIS). Virtual layers are based on SpatialLite: The underlying engine uses SQLite and SpatiaLite to operate.

That sayed, you first must have a polygon (canvas bounding box) for the query.

Unfortunatley, getting the coordinate values of the point you're looking for with x(point_n(@map_extent, 1)) works fine e.g. in the label dialog, but does return only NULL in the attribute table/field calculator. Somehow this makes sense as the layer has it's own extent, but has no connection to the (current) map canvas extent at all (canvas can change, but layer remains unchanged). So you can't use a virtual field to create coordinate values you can access in the SQL query.

Geometry by expression

What you can do - but then it's not a dynamic solution any more:

You can use the same expression as with geometry generator, but use Menu Processing > Toolbox > Geometry by expression. It creates the point as an actual geometry, not just symbology.

You must do this based on any input vector layer (point, line or polygon). The point will be generator on a new layer.

See also here for similarities and differences between Geometry generator and geometry by expression.

added 86 characters in body
Source Link
Babel
  • 74.9k
  • 15
  • 87
  • 227
Loading
added 1416 characters in body
Source Link
Babel
  • 74.9k
  • 15
  • 87
  • 227
Loading
Source Link
Babel
  • 74.9k
  • 15
  • 87
  • 227
Loading