4

All geoprocessing tools honour selections. So simply select the rows where column 1 has the NULL values then run a field calculate and select the field you want the values to come from. As you have a selection only those rows will be updated. Absolutely no code required.


4

Using Python in the field calculator, you could try the following expression: 1 if !myField! > 0.0 else 0 Or if you want it based on the polygon area, try: 1 if !shape.area! > 0.0 else 0 Since booleans are automatically cast to integers (1 or 0), you can do the same thing more simply as: !myField! > 0 or !shape.area! > 0 If there is a ...


4

If you don't find a solution using Field Calculator try python window with collections.Counter and two da.UpdateCursors: import arcpy from collections import Counter fc = 'C:\data.gdb\my_riks' #Change values = 'KKOD' #Change dupinst = 'dupinst' #Change totcount = 'totcount' #Change cnt = Counter() with arcpy.da.UpdateCursor(fc, [values, dupinst]) as ...


4

EDIT: or to your changed request it should be: array_length( array_agg( "RoadMntnc", "RoadMntnc")) You can use the following expression to count the segments of a line or polygon: num_geometries(segments_to_lines($geometry))


3

Field Calculator only iterates once over the table so you cannot generate a frequency list and apply it with one pass. If this is a task you need to repeat I'd recommend using a python script outside Field Calculator or creating a model in ModelBuilder.


2

Because you used regexp_matches() instead of regexp_match() it will return an array (notice the square brackets in Output preview at the bottom of your field calc screenshot) as opposed to a string. You need to convert the array to a string by wrapping your expression in array_to_string(). You also need to escape any backslashes so \1 needs to be \\1. It ...


2

What the !field1! if !field1! else '' expression does is evaluate if the corresponding value of !field1! exists or not. If there is a value, then it keeps that value and adds it to 'Comment'. However, if there is no value (it evaluates to None) it will keep and empty string (''). Here is an illustrative example: Suppose the value of field1 is 'ABC001' for ...


2

With python parser try: Code block: def updateValue(field1, field2): if field1 is None: return field2 else: return '0' Call with: realfieldname1= updateValue(!realfieldname1!,!realfieldname2!) When you call the function you must use the real fieldname enclosed in !!


1

I finally figured out the problem. Was my index position. So this type of code works as well. permit_fix = replace(!permit_num!) Code Block import re def replace(val): if (val[0:2] == "07"): return re.sub ('07','39', val) elif (val[0:2] == "10"): return re.sub ('10','39', val) elif (val[0:2] == "11"): return re....


1

You can use a list comprehension to index and replace the first characters for each item in a list. For example: test = ["3901","1420","2270","3985"] def replace(val): new = ["39" + i[2:] if i[:2] != "39" else i for i in test] print (new) replace(test)


1

This should work: length(make_line(make_point(25.906543, -80.546800),$geometry)) you create a line (make_line), starting at the point with your fixed coordinates (created with the command make_point(25.906543, -80.546800)) and ending at the second point, defined with $geometry as the current point of your layer. You then measure the length with the ...


1

You want the length to be displayed along your line and auto-update as you draw or edit the line? In this case, simply label your line with the expression length($geometry) For the attribute table, use Creating a Virtual Field - when you create a new field with the field-calculator, select virtual field and set the expression you like - e.g. length($...


1

Instead of using regex_match you can define a new function and use that custom function to extract the unique text without using regular expression. You can use the following function to do the job: from qgis.core import * from qgis.gui import * @qgsfunction(args='auto', group='Custom') def unique_text(text_field, feature, parent): split_text = ...


1

Use the normal Field Calculator and in the Formula option, select Pre-calculated Value. Then use the expression: '(' || @a || ' + ' || @b || ') / 2' where the parameters @a and @b are the fields you assign when running the model. This is read by the field calculator as a string version of: (A + B) / 2


1

You can try regexp_substr('iuyluf45567kjyyr347fklj', '(\\d+)[^\\d]*$') It will look for one or more digit that does not contain another digit between it and the end of the string


1

We found a way to do this in Excel: https://exceljet.net/formula/count-specific-words-in-a-cell


1

An update for QGIS 3 of the crystal clear answer by @Steven Kay You can get around this by creating a short python script in the function editor tab of the expression editor. Go into the function editor tab in the expression editor Create a new function ("New file" button) paste the following into the code window. You may get indentation errors, so ...


Only top voted, non community-wiki answers of a minimum length are eligible