New answers tagged

2

If you want to define an input as a variable, first create an input, than use this input with Set project variable, give it a name and use the value of the input with Using model input (see screenshot). You can than use this variable with it's name in select by expression: Running the model with input character a: all features with attribute name starting ...


2

On the line layer, create a new field with field calclulator and the following expression for the start-point. The expression creates a buffer around the start-point of the line, then looks for the two closest points to the line and checks which one lies inside the buffer. From this point, it takes the value of the field name. Adapt the expression as follows ...


2

You dont mention what field type you have. But I have a string field called kkod with integers in it. This model is working if I use the for loop output as input to a string variable, then use the string as input to an SQL expression variable:


0

The ModelBuilder does have a for loop implementation which sounds more appropriate than while in your use case. This being said, iteration capabilities within ModelBuilder for ArcMap (which it seems you're using) are relatively limited. You can't batch custom models, and I think you are only allowed one iteration per model. To get around these, you can ...


1

Use the label class to write an expression that uses the modulo function %. The modulo function returns the remainder of division. If you use [OBJECTID]%2 all the even OBJECTIDs will return 0. Here I am displaying postal codes for every even objectid record. You can easily reduce the labels if the density is too big for you map. Here you would only ...


3

Hide (toggle visibility) your point layer. On the line layer, add an additional symbol layer, set it to Geometry generator / Point to symbolize all points here, on the line layer. Use this expression: collect_geometries( overlay_contains ('points', $geometry)) Layer Points is invisible, points are created with an additional symbol layer on the line layer - ...


2

You can modify the expression by using: line_locate_point (to get the distance from the start-point of the line to the point where the line intersects with the polygon (white dot on the screenshot below: the point point where the line intersects the polygon for the second time, = step 5 in the original solution) line_substring to get the substring (blue on ...


3

It is not a solution using the expression, it may seem a bit lamer. Let's assume there are two layers: a point 'random_points_test' and a polygon 'poly_test' respectively, see image below. Step 1. Use the "Join attributes by location" to get "id"s from polygons Step 2. Proceed with the "Add autoincremental field" geoalgorithm ...


2

Use this expression (explanation see below): to_int( array_find ( array_sort ( array_agg( x( geometry ( get_feature_by_id ( @layer, $id ))), group_by:= array_first ( ...


7

You can define a custom function to get crs extent. from qgis.core import * from qgis.gui import * @qgsfunction(args='auto', group='Custom') def crs_extent(layer_name, feature, parent): layers = QgsProject.instance().mapLayersByName(layer_name) if layers: bounds = layers[0].crs().bounds() else: raise ValueError(f"Layer {...


2

Use None not NULL. Python doesn't understand "NULL" Your if else is not valid python syntax, you need if: and else: with indented lines below each You don't need to add literal strings to literal strings "<UND><BOL>" not "<UND>"+"<BOL>" String formatting is faster than concatenating (adding) ...


5

You need geometries for your input of intersects(), not layers. Get the current features geometry by using $geometry and the collected MultiLineString-Geometry of the top-layer by using aggregate() function. Like: if(intersects($geometry, aggregate('top layer', 'collect', $geometry)), 'BL', 'OL') or since QGIS 3.16 using the overlay_intersects() function ...


8

You have to add regex word boundaries (\b) to extract your numbers: regexp_substr("address", '\\b\\d+\\b')


4

Use this expression: regexp_substr( replace( "address", regexp_substr("address",'\\d\\s\\d') , '' ), '(\\d+)' )


5

You can use array_filter() combined with in operator, like: array_filter(array(1,2,3,4,5,6), @element not in (4,5,6))


1

To get the value of one of two attributes, where one of them always is empty (Null or 0), you can use this expression - be aware that array_sum is available since QGIS 3.18: array_sum (array (building_height, block_height)) For older QGIS-version, you can use this expression: if ( (building_height is NULL) or (building_height =0), block_height, ...


Top 50 recent answers are included