New answers tagged

0

Couldnt find a solution for QGIS 2 using only expressions, I guess a custom function to get the current map extent is needed for this version (similar to item_variables('Map 1')['map_extent'] in QGIS 3). However, just in case someone is looking for a solution in QGIS 3, here is an expression: if( intersects( -- check if atlas layer and map extent intersect ...


2

I just found out, I could use the vertex tool of the editing toolbar: acitivate the editing mode. activate the vertex-editing-mode right-click on the point insert the new coordinates


6

QGIS 3.x: You can use the feature filter in layer properties -> source -> query builder: E.g. use $id < 51 as expression to only show the first 50 features. Or use "population" > x to display only vilages with a population greater than x. QGIS 2.x: In QGIS 2.18 you can find the same menu in layer properties -> general -> query ...


2

What you seem to mean is how often does each line cross the boundary (outline) of each polygon. When a line crosses a polygon, the number of intersection points is infinite as the intersection has the form of a line and this consists of an infinite number of points. To count the number of crossing points with the boundary, first convert your polygons to ...


11

I'm not an expression expert. My solution uses a custom function. Function definition: from qgis.core import * from qgis.gui import * import random @qgsfunction(args=-1, group='Custom') def randstr(in_list, feature, parent): return random.choice(in_list) Usage: randstr('A', 'B', 'C')


13

You can build the array, build a random index and extract its value array('a','b','c')[rand(0,2)]


8

You can try an expression like this: with_variable('stringlist',array('string_a','string_b','string_c'), array_get(@stringlist,rand(0,array_length(@stringlist)-1))) Explanation: First set up an array as variable, so you only have to build your lookup-array once. Next we pickup a random position from this array using array_get() combined with rand(). The ...


6

This solution relies on two relatively new functions of QGIS expressions: array_sum(), avalilable since QGIS 3.18 and overlay_nearest(), available since QGIS 3.16. Calculate the total length of the roads per province. Calculate the length of the percentage you want to get. In my example, the total length is 1090566 m, 10% thus is 109056.6 m Remark: see ...


0

Try (1.8 * ("NIR"-"Green") -3.75 * ("Red"-"Green")) / (SquareRoot(Square(2 * "NIR" + 1)-(6 * "NIR" - 5 * sqrt("Red")) - 0.5)) based on Bagheri, Ahmadi, Alavipanah & Omid 2013.


4

Not sure I understood well (if you want to count occurrence from column field3 or if it's the column you want to fill with a count from another column). I have considered you want to update the field3 using count from field1. In this case, you need to try the following expression to update field3 with count of occurrences from field1 using QGIS field ...


4

right(@project_basename,3) could be an option


8

Use this expression: substr( @project_basename, strpos( @project_basename, '_PR' ) + 3 ) I assume string _PR exists in the project name.


6

You can use a one-step expression using count() function: count("ID","CLASS") / count("ID") * 100 This will return the percentage of the current class of the total feature count. Where "ID" is a unique field and "CLASS" an identifier for your class, so not unique. If you need an overview-table, you can run ...


5

The solution is to use the function aggregate(). I did it in a two-step process: Tool Aggregate with count as aggregation, and subsequently tool Field Calculator with the following expression (where count is the attribute respectively column created with the Aggregate tool): "count" / aggregate(layer:=@layer, aggregate:='sum', expression:="...


8

Use this: ("ALTURA_SOB" >=500 AND "ALTURA_SOB" <= 1200) OR ("ALTURA_SOB" >=2000 AND "ALTURA_SOB" <= 2500)


6

The problem is that you expect that make_ellipse returns an ellipse in EPSG:26913 coordinates. Yes, it returns EPSG:26913 coordinates (big numbers like 500000 which are projected coordinates), but QGIS considers those are in source layer's CRS, EPSG:4269 (lat, long). If you check the CRS of ellipses_out, you will see its CRS is EPSG:4269. For a solution, use ...


3

The idea You can create a pseudo-random value that remains constant, based on the inherent properties of each feature with some mathematical operations. Inherent properties can be the x-/y-coordinate values (as proposed already) or $id of each feature. As you mentioned, $x and $y values are too close to each other to work as a kind of "random" ...


0

I have two solutions that could work : if your cell height don't vary too much. if your label need to appear only in one atlaspage, or in all atlaspage but not on two atlaspages. You still use the table but make multiple "cadre" (sorry I don't know the English name, it is just above position and size). This is normally used when you have a table ...


1

When filtering, the where keyword must not be written and the query should not be ending with ; Try with: CNTRY_NAME LIKE 'd%n%'


2

You can use filter in the aggregate expression IF your symbol_label is a value that can be obtained from your attribute.There is an easy way to do this, but it iss in PR limbo. Such as sum($area,filter:="attribute"=@symbol_label) Also be caution if you want to multiply this value and concat the string. The concat operator has precedence over math ...


1

You can use this QGIS expression: replace the number 1 at the second last line with any number from 1 to 26 to get the corresponding letter - if you set it to 5, it will return E: map_get( hstore_to_map( array_to_string ( array_foreach ( generate_series (1,26), to_string ( @element |...


Top 50 recent answers are included