New answers tagged

3

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


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 ...


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.


0

This is copied verbatim from the ArcGIS Desktop help. The instructions are for Windows 7, so it's probably different for newer versions. You get the idea, though. Changing the way ArcMap displays short format dates in Windows 7 You can change the way ArcMap displays date formats by setting date format options within the Regional and Language ...


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: ...


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 ...


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.


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.


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 ...


0

I just tested this at ArcGIS Pro 1.3 and can confirm what you are saying. I think the reason that field calculations cannot be undone is that they are not being done within an edit session, but rather by the Calculate Field tool of the Geoprocessing pane. I think the only way to try and obtain the software behaviour that you seek is to submit an ArcGIS ...


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


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()


0

I've found similar issues when adding polygons and updating an area field with ($area/10000). It uses a different method than (area($geometry)) and often returns a different answer. I've concluded that editing, saving edits, turn editing off, open table/recalc field with (area($geometry)) works consistently. I don't mind discrepancies and errors, as I ...


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:


0

Buffering features in wgs84 does not work with distances calculated in meters. You first have to reproject each layer to a projected crs suitable for your area. In the modeler this is possible with


1

Field calculator for Python d={} def GroupOrder(groupID): if groupID in d: d[groupID]+=1 else: d[groupID]=1 return d[groupID] --------------------------- GroupOrder( !locality! ) Change !locality! to relevant field


1

Be sure to check "Code Block": def calc_X(A,B,C,D): if A == 0 and B == 0: return calculation_1(A,B,C,D) elif A == 0 and B != 0: return calculation_2(A,B,C,D) elif B == 0 and A != 0: return calculation_3(A,B,C,D) else: return calculation_4(A,B,C,D) Then: X = calc_X(!A!, !B!, !C!, !D!)


1

Since you are using the field calculator on that given field you can just use this with codeblock enabled. Tested with Volume field as a float and it works: if [Area_Ha]<=70 then result = 2.85 *([Area_Ha]^1.22) elseif [Area_Ha] >70 then result = 7.1* ([Area_Ha]+9.97) end if Then: Volume_De = result In python I think you're not allowed ...


0

Attached is the error message. Matte, The modified code didn't work


2

You donĀ“t need to bring your calculated field in the return part of the function: Try: if [Area_Ha] <=70 then [Area_Ha]^1.22 * 2.85 else ([Area_Ha]+9.97)*7.1 end if


3

This python function implements the logic you described in your question: def calculate_X(A,B,C,D): if A == 0 and B == 0: X = calculation_1(A,B,C,D) elif A == 0 and B != 0 and C != 0 and D != 0: X = calculation_2(A,B,C,D) elif B == 0 and A != 0 and C != 0 and D != 0: X = calculation_3(A,B,C,D) else: X = ...


1

Example of code in field calculator / calculate field: Field Name: X Expression: calc1(!A!,!B!,!C!,!D!) Expression type: PYTHON_9.3 Code Block(/Pre-Logic Script Code): def calc1(a,b,c,d): if a==0 and b==0: return a+b+c+d+1+2+3+4 elif a==0 and b<>0: return a-b-c-d else: return a+b-c+d


0

If you are intending to do analysis with this data consider setting up a RELATE, this will help you pass selections from one table to another, eg. you select the polygon on screen and then run the relate that passes the selection to the hospital admissions table. So one polygon selecting many admission rows. If you intend to summarize and display this ...



Top 50 recent answers are included