Hot answers tagged

7

The value that is written into the attribute table depends on what field calculator returns. In your case: CASE WHEN "Z" = 0 THEN "Z" = rand(1,100) END means that it compares Z and 0, and if that's true, it compares Z and a random value from 1 to 100, which has to be false because Z is 0. That's why it writes 0 (=False) into the fields which were 0. And ...


6

In the field calculator, show Codeblock. In the pre-logic script code box: import random def randnum(): return random.random() In the expression box: randnum() Result in a new float field:


5

You can do this directly within the CalculateField tool; use the following code block: prevval = None def calcowner(ownerval): global prevval val = prevval if ownerval is None else ownerval prevval = val return val And the expression: calcowner(!Owner!) Note that this probably won't work in ArcGIS 10.0 due to a bug that was fixed in 10....


3

Try to change your code to def calc(Wert1, Wert2, Wert3): if (Wert1 == None): return Wert2/Wert3 else: return Wert1


3

You need to use the Field Calculator or Calculate Field tool to calculate your new field equal to your old field. Make sure that your new field is defined the same as the old field. Otherwise it cannot be considered to be a copy.


3

In your if line you need to change your or to an and in the last part. if f4 == f5 and (f1 == f2 or f1 == f3) and (f6 != f7 and f6 != f8): This is because with f6 != f7 (6 != 5) it returns 1, even though f6 != f8 fails (6 = 6) in the second part. With the OR there it returns true if one of them is true. With an AND it would return true only if both are ...


2

In the FieldPyculator, you will need to: Insert your function as a Global expression and remove the AP parameter as you can choose from the GUI which field you want updated. Slightly change your Field expression by specifying fields using <Mag> instead of !Mag!. This is the global expression I used (not sure what Vector_Mag was so changed these ...


2

You can do it using the following formula in the Field Calculator: regexp_substr("Field_Name",'(\\d+|\\d+.+)') It will give you the following results: 25 2 26A 125 147A Even if you have text with a name 'Text 123456789ABCDEF', the output will be: 123456789ABCDEF


2

I would use regexp_substr instead of strpos so in your example something like: regexp_substr("FolderPath",'.*/') The first item ("FolderPath") is your column name (enclosed in "), the second is a standard python regular expression. There is a regexp howto available to help you out.


2

I think you need to add from qgis.utils import qgsfunction into your code. You can also remove the other imports as they're not necessary. So something like this should work: from qgis.utils import qgsfunction @qgsfunction(args="auto", group='Custom') def sp_split(value1, feature, parent): return value1.split(",")[2]


2

Use an if to check the value of each field, and skip that value if it's one of your "no data" values. You can add other "no data" values to the no_data list to skip those as well. Expression: skip_nodata(!FOR_FISH!, !MINING!, !FARM_EMP!) Code Block: def skip_nodata(val1, val2, val3): no_data = [-98, -99] x = 0 if val1 not in no_data: ...


1

This can be done with a custom python parser function like: Here we evaluate if value is NULL or not, if not write value to text file, if NULL pull value from text file: def update(val): if val: f = open('C:/Temp/temp.txt','w') f.write(val) f.close() return val else: f = open('C:/Temp/temp.txt','r') for v in f: return ...


1

This works for me: def setindex(height): dIndexInterval = 50 dCont = height i = dCont / dIndexInterval if ( dCont / dIndexInterval) - i == 0: return 1 else: return 0 And then setindex( !ELEV! ) in the bottom window where ELEV is the name of your elevation field. Edit The code given in the link looks buggy, as far as I can tell it will always ...


1

It looks like you put the defined function into the returned field. The message says if you have multi-line you have to cut the code and activate the Show codeblock and paste the code into the "Pre-Logic" Script Code space. The last line should be used to return the defined function exist in the "Pre-Logic" Script Code. Check "Using code blocks" in the ...


1

In field calculator: right("column", strpos("column" ,' ')) Should do the job.


1

You can vary parameter in expression below, depending on what distribution is required: def aRand(): return arcgis.rand("Normal 2 2") --------------------------------------- aRand()



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