Tag Info

Hot answers tagged

6

Here's a go at it. Use Python as the parser and check show Codeblock. Enter this in the top Pre-Logic Script Code box: def getints(field): integers = [] for char in field: try: value = int(char) integers.append(str(value)) except ValueError: break return "".join(integers) And put ...


5

Note that "Town" refers to a column called Town, while 'Town' is the string that you actually want to assign. Therefore: (Updated to correct the then and else parts. Thanks fluidmotion for pointing out the issues.) CASE WHEN "COLUMN1" IS NOT NULL THEN 'Town' ELSE 0 END


5

the percent symbol is not a valid value in a numeric field. If you want to see the percent symbol, you can right click on your field name, go to properties -> number fomat and choose percentage. otherwise (not recommended) you need a text field,but then you need to convert your numeric values to string (assuming that T_Acres is numeric and using the ...


4

You can use Summary Statistics (Analysis) using the COUNT option on your field, then from that, you can see which repeat "more than 20 times" or however many times.


4

Put a u in front of the string so the interpreter knows it's Unicode. myCalc(!Epulettipus!, u"Lakóépület")


4

Apparently RefName never equals your comparison strings. All constant strings includes German characters ä or ü, but you don't use the "u" constant string prefix. Depending on the incoming string's format the comparison might not be what you expekt. You should write if RefName==u"Flächen für die Landwirdshaft" and make sure that RefName also is a correct ...


3

Here is a field calculator method that incorporates itertools.takewhile. While ian's solution writes the new values to a text field, this is suited for writing to a numeric field. import itertools def convert(x): try: return int("".join(itertools.takewhile(str.isdigit, str(x)))) except: pass convert(!OriginalString!)


3

Similar to @underdark, but in my installation, i had to use CASE WHEN "COLUMN1" IS NOT NULL THEN 'Town' ELSE 0 END and be sure the correct update field is checked, as you mentioned. when i attempted to set "COLUMN2" to some value with the CASE comparison, it will only evaluate true or false (0 or 1), rather than actually updating with ...


3

You don't 'Dim' variables in python, you just declare and assign them. That said, your basic route is to set the parser to python and check Show Codeblock. In the Pre-Logic Script Code box, enter your function like this: def DoThis(fld): val = 0 if fld <> 'a certain string': val = # do your calculation here return val In your ...


3

Based on your variable, you just need to make sure variables and strings are not confused field_1="!field_name1!" field_2="!field_name2!" arcpy.CalculateField_management("Layer", field_0, field_1 + " / " + field_2, "PYTHON_9.3") note that if you have the strings as variables without the "!", it is nicer to use format() field_1="field_name1" ...


3

The code should work, just add the colon after if statement and proper indentation: def RemoveNULLS(x, v): if x == '0': return v else: return x RemoveNULLS( !TESTFIELD!, !TESTFIELDBEREGNER!) Be careful with what data type used for the x (if it is an integer, you cannot use '0', should be 0).


3

From ESRI Support HowTo: Create sequential numbers in a field using Python in the Field Calculator


3

in the code block you'll define a function, and then in the expression, you'll call the function with the needed field names, like so : Code block : def picture_name(current_name, map_number): return current_name[current_name.rindex("\\"):] + "|" + map_number + ".tif" Expression : picture_name(!Pictures!, !MapNumber!) I haven't test this code, ...


3

Pieside's answer gives you the straightforward way of doing it. An alternative you may wish to consider is to use the 'Statistics by categories' tool in the Processing toolbox (just open the Processing toolbox and type statistics in the search bar and you'll find it. This tool creates a table of basic statistics (min. mean, max, stdev, count) in one field ...


2

In the menu, click on Vector->Analysis Tools->Basics statistics. See the end of: http://www.qgistutorials.com/en/docs/calculating_line_lengths.html.


2

!shape.length3D! does work. I had to make sure that I selected the PYTHON_9.3 Expression type in the Calculate field Options dialog. (I'm running 10.2.)


2

You can also append text or put spaces between using alternate quotations: "Streetnum" || ' ' || "Streetname"


2

I can see from your field name !DEAD_VOL_PER_HA_SPP1_125! that the field you are calculating is likely a float or integer type field. Assuming this is true, you cannot write a space or '' into a number-based field (e.g. return ''). Valid values for number-based fields include None or a numeric value. You will need to either create a new text field to ...


2

Ok, this is clearly an ArcGIS bug (as we've deduced in the comments on @ian's answer). Here's my attempt at a workaround, which assumes there can be either zero or one commas in the number (and therefore, as a result of the bug, you effectively pass the function either a single integer or a tuple of two integers): def giveResult(*args): floatValue = ...


2

Assuming that the numbering of your rows always starts at 1 and proceeds with increments of 1 to a different number each time I think your model/code needs to do this: Use GetCount to count the number of rows (numRows) Use Calculate Field to do (numRows - ID) + 1


2

You are missing the wrapping exclamation marks, try this: arcpy.CalculateField_management("Layer", field_0, '!' + field_1 + '!/!' + field_2 + '!', "PYTHON_9.3")


2

You have embedded the string variable within a string so python sees it as a string. I would suggest you make you code something like: field_0="field_name0" calcString = "!field_name1! / !field_name2!" arcpy.CalculateField_management("Layer", field_0, calcString', "PYTHON_9.3")


1

Have a search in help for the subject "Performance tips for joining data" it offers advice on improving join performance. Your code does not indicate you have added an attribute index which can often improve performance.


1

Create a new field and put field type is text after that you should use field calculator the value by simply select all "nulls" and change it in to "0".


1

Edited: this expression relies on knowing the total (23) beforehand, but would be possible to calculate in the script, if needed. For the example series in the comments (3, 6, 5, 9) this expression returns 23, 20, 14, 9. total = 23 prev = 0 def cumsum(inc): global total global prev total -= prev prev = inc return total


1

You need a codeblock in your field calculator. The example below is with a Python parser total = 0 def cumsum(inc): global total total+=inc return total The first line initialize a variable to 0, then you define a function called cumsum with one argument. for the incrementation, you want your variable to be "global" that will keep incrementing the ...



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