New answers tagged

4

That weird string is not a memory address, but the layer's id. You can use the following expression to construct INPUTLAYERNAME_clipped string. And no need string_to_array(@INPUT,'_')[0]. layer_property( @INPUT, 'name' ) + '_clipped' layer_property(@INPUT, 'name') returns the layer name. If you need the layer source file name, use this: base_file_name( ...


1

string_to_array("text",';')[1]


1

You can always mask every character, including single or double quotes, by using their ascii-code: char(39) returns a single quote: ' char(34) returns a double quote: " To find the ascii code, simply look for it with ascii(): ascii('a') returns 97. To find the ascii code for single quotes, enter ascii('''') - this returns 39. Thus you can also use: ...


3

Great answer by @Babel! Another option would be: regexp_replace(replace("Field B", string_to_array("Field A"), ''), ',,', ',') The core part of the expression is replace("Field B", string_to_array("Field A"), ''), but it will produce 1,,3,,5 so regexp_replace(~~~, ',,', ',') was added to remove doubled commas.


3

Use this expression: array_to_string ( array_remove_all( array_foreach ( string_to_array(field_B), if ( array_contains (string_to_array(field_A),@element), '', @element ) ), '' ) )


4

If you want to use python, this is one (complicated) way: #Change the following three lines: layername = 'New scratch layer' fieldwithdups = 'values' fieldwithout = 'values2' lyr = QgsProject.instance().mapLayersByName(layername)[0] #Create a layer object by name attrmap = {} #A dictionary to store and to set new values fieldindex = lyr.fields()....


3

Use this expression with field calculator to create a new field with duplicates deleted (only distinct values remain). "text" is the fieldname where the initial string is: array_to_string (array_distinct(string_to_array("text")))


4

Since you mention SQL, here's a PostgreSQL approach to this issue: WITH yourvalues AS ( SELECT '37.3,37.8,44.A2,37.3,37.31' AS attributefield ) SELECT DISTINCT UNNEST(STRING_TO_ARRAY(attributefield,',')) AS unique_attributes FROM yourvalues Result: unique_attributes 37.31 44.A2 37.8 37.3 Result without using DISTINCT: attributes 37.3 37.8 44.A2 37.3 37....


Top 50 recent answers are included