Tag Info

New answers tagged

2

Writing my comment as an answer: It looks to me like there was an issue with the geometry of the shapefile, so running Repair Geometry should (and did) solve this problem.


0

if you redid the calculation as well, the numbers for the first two records are right-justified but just differ in the number of decimal places shown


4

You are using the syntax from the question, not the answer. Also, the pre-logic code for Python can't reference field names. You also might want to check out .rpartition(). You shouldn't have to use pre-logic at all: Sector = !FolderPath!.rsplit("/")[0] But if you did want to use pre-logic, here's how to do it: def sect(field): return ...


0

If you have hidden fields in the attribute table, then they will not show up in Field Calculator. In the attribute table, go to Table Options, and then Turn all Fields On. The key to note here is "in other dialogs". If you hide them here, they will be invisible to most other tools, identify, export, etc.


1

How about something like this: import arcpy mainTbl = r"C:\test.gdb\main" lutTbl = r"C:\test.gdb\lut" #Note the order of the fields in the search cursor has to coincide with field order in the update cursor #Also assumes the matching fields are of compatibale types (exanple: can't insert string into integer) lutDict = {r[0]:[i for i in r[1:]] for r in ...


1

The Field Calculator would crash on me whenever I would run the Field Calculator to update about 2,300 records on a point dataset that was generated as a checkout file geodatabase. This turned out to be a known ESRI bug where ArcMap would crash if the Field Calculator was used on more than 100 records at a time in a checkout file GDB, and was addressed in ...


6

You should be able to do a simple 'select by expression' where DATECOLUMN like "% 12%" This is assuming your date is a string column. Essentially; the query is using the 'pattern' that is formed, and saying "Find me every record where there's a space, followed by 12, follow by a colon. Since your data is in 24h format, the only records criteria that ...


1

Your question is a bit unclear. I try to explain to you what this script does: You have a column A and a column B. Depending on the values in column A we populate the empty fields in Column B. change(!A!) #write that into Expression of your Field Calculator, with the "!" you tell ArcMap in Python that this is a column def change (A): #everything from ...


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

I came up with a solution. It sounds complicated but we are looking at six tools and an iteration here! I copy my Shapefile A, use the dissolve Tool to dissolve shapefile A by Name. Then I use this created Shapefile as a in the Split Tool as the Split feature for Shapefile A. I insert into my model Iterate Feature and chose my Split output as a Workspace ...


0

I think simply this will do with VBScript, using your example of 10 fields to choose from by index (0-9): int(10*rnd) ...and with a Python codeblock using numpy: import numpy.random as R def getRandom(numFlds): return int(R.random()*numFlds) The above Python block would be called by (again using a 10 field example): getRandom(10) Extending ...


0

It seems that: Use Summary Statistics on "Shapefile A" with Statistics Field Size and Case Field Name to generate a table with Name frequency and sum_size. This table can be reused as an input in your iteration if you have multiple "Shapefile B"s. Use Join Field to join the summary statistics output table to "Shapefile B" based on Name, adding only the ...


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


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


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


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


0

Going off of your latest edit and ew_GIS try this: Expression: change(!OldFor_Com!, !Area_Ha!) Code Block: def change(OldFor_Com, area): if OldFor_Com == "OTHH": return area / 40 elif OldFor_Com == "OHWH": return area / 30 elif OldFor_Com in ("OOFH", "OSFH", "OOFH"): return area / 375 elif OldFor_Com == "PINE": return area / 10 ...


0

Besides the syntax errors with the ! marks, your first "if" statement is indented incorrectly


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


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


0

Can't try this since I am not near Arc* Try conditional expressions... Make field Q2 active use the python parser and try 1 if !Q1! == 0 else 0 If it doesn't work...never mind


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


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


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

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.



Top 50 recent answers are included