Tag Info

Hot answers tagged

5

Using cursors is a good way to inspect how datetime fields can be accessed and written to. This is taken from a feature class, with a a date field: with arcpy.da.SearchCursor("poly_small", ("COL_DATE")) as cursor: for row in cursor: print row[0], type(row[0]) 2014-07-18 06:03:05 <type 'datetime.datetime'> 2014-07-17 00:00:00 <type ...


3

Since you tagged this with python, you can also accomplish this with an updatecursor. Using field calculator in python for multiline statements is sometimes more difficult than the same function in a cursor. with arcpy.da.UpdateCursor("Mange_Waste", ("Q1", "Q2")) as cursor: for row in cursor: if row[0] == "a": row[1] = 1 else: ...


3

you need to use a block or to write everything in a single line (respecting the indentations) block (with Python parser) def myfunction(a,b): if a == 'a': return 1 else: return 0 then you call the function defined in your block myfunction(!Q1!, !Q2!) note that this is a general solution, but in your specific case you could ...


3

First, you should note that field calculator applies only row by row (except if you use a static variable). So you will need to precompute the mean and the standard deviation of your Gaussian distribution. Then run the equation in Python def Gaussian(field, mean, std): return math.exp(-(field-mean)**2/(2*std**2))/(math.sqrt(math.pi()*2)*std) ...


2

I am unclear about your function's logic, but I would approach it like this... Expression: autoIncrement(!Munic!, !Point!) Expression Type: PYTHON_9.3 Code Block: rec = 0 def autoIncrement(munic, point) pStart=1 pInterval=1 if(rec==0): rec=pStart else: rec=rec+pInterval return '{0}' "-" '{1}' "-" '{2:03}'.format(munic, point, rec) ...


2

You need to send your area field into your calculation as a parameter. Expression: change(!OldFor_Com!, !shape.area@hectares!) Code Block: def change(OldFor_Com, area): if OldFor_Com == "OTHH": return area / 40 elif OldFor_Com == "OHWH": return area / 30


2

1 square metre is 10.7639104 square feet according to Google. Therefore if the cell size is 1 each cell is 1 square metre (1 x 1), the area covered by class is: Count x 10.7639104 if the cell size is 2 metres the area is 4 sq.m. (2 x 2) and the area covered by class is: 4 x Count x 10.7639104 If the cell size is irregular then multiply the width and ...


2

I actually just did something very similar to this in another script, so I'll drop this here if anyone finds it useful. It's 10 lines if you remove the comments. import collections #Summarizes the second number in a list of tuples by the occurrences in the first #e.g., [["a", 1], ["b", 2], ["a", 3], ["c", 7], ["d", 0], ["c", -1]] -> #{'a': 4, 'c': 6, ...


2

Esri is a little stuck with this because they want to preserve forward compatibility of old Python code people depend on. I really wish they would have changed the default by now though, as we get a lot of queries from users why their scripts fail in background processing -- because the default (VB) is not supported by arcpy 64 bit! Here's an example ...


1

Add a new field (text) In field calculator, round the original Percent value to no decimals, and append a percent sign: format(round(!Percent!)) + "%" or the shorter, more elegant "{}%".format(round(!Percent!)) (Thanks to Paul for the improved syntax!)


1

After your newest updates to the question, this should work: def change(OldFor_Com, Area_Ha): if OldFor_Com == "OTHH": return Area_Ha / 40.0 elif OldFor_Com == "OHWH": return Area_Ha / 30.0 elif OldFor_Com == "OOFH": return Area_Ha / 375.0 elif OldFor_Com == "OSFH": return Area_Ha / 375.0 elif OldFor_Com ...


1

Your exclamation marks need to be wrapped around the field name: def change(OldFor_Com): if OldFor_Com == "OTHH": return !shape.area@Hectares! / 40 elif OldFor_Com == "OHWH": return !shape.area@Hectares! / 30 Also, make sure Python is the defined Parser.


1

Your logic is correct. This help guide may help you out in the future for using python in the field calculator. There are already valid pythonic answers above I'll post another option, in VB (sometime's it is simplier than python). In field calculator choose "show codeblock" for "Q2" under "Pre-logic script code" write: In VB: if [Q1] = "a" then result ...


1

Have you checked and selected the correct target field = "property2" for "update selected field"? no need to set update field in syntax. try the below syntax. CASE WHEN "property1" = 'FOO' THEN 'BAR' END


1

Although this can be accomplished with one update cursor, I find it easier to separate the two. Here's the somewhat tested code to get you started with cursors. I created a mock feature class with 26 fields filled with random values and I picked two of them to compare with field calculator and it seemed to be correct. Feel free to ask for clarification. ...


1

Using an UpdateCursor lets you avoid the codeblock and directly work with the row data, instead of dealing with the Field Calculator. For example, in 10.1: depth_fields = # list of depth fields flow_fields = # list of flow fields zipped = zip(sorted(depth_fields), sorted(flow_fields)) for input in zipped: fields = (input[0], input[1], 'K_FC', ...


1

If you have two sources, first join them together, either by spatial or attribute criteria. Then you can use columns of both data sources in the Field calculator. Field calculation examples using code blocks and multiple parameters.


1

Run Summary Statistics on SIDETABLE using Name as case field and A as statistics field with MAX as the statistic. You can then update MAINTABLE with the resulting summary table - regular join on Name and field calculate, join field, field calculate directly if both tables in the same geodatabase, etc. For that matter, if the tables are in the same ...


1

From what I understood from your question, you can do this in too different approaches. Using Categories You can use the Expression builder to write conditional expressions that will create all your output different combinations: You start by pressing the Expression button and write the expression: CASE WHEN "Score_1"+"Score_2" > 6 THEN 'Bigger than ...


1

You may want to look at doing rule based styling if all you are trying to do is color code features based on attributes in your table. You can access this from the Properties window, then under Style. Within the Style section you can get to the rule based option from the Single Symbol drop down (choose Rule-based). Here you can add rules based on your ...



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