Tag Info

Hot answers tagged

9

Here is a simple approach using the built-in Python .isdigit(), .isalpha() and .zfill() methods. This approach uses the Python parser. Pre-logic Script Code: def changeAddress(y): integer = ''.join(x for x in y if x.isdigit()) string = ''.join(x for x in y if x.isalpha()) final = integer.zfill(3) return final + string ...


6

you can use the field calculator with the Python parser sum([!field1!, !field2!, !field3!, !field4!])/4 EDIT: for accounting for null values sum([a for a in [!field1!, !field2!, !field3!, !field4!] if a is not None )/4 not that, in this case, it works as if you assume that null values are ZERO as in your comment. Alternatively, you can IGNORE null ...


6

You don't need a complicated codeblock for this. The one-line expression is: !NAME!.replace(" ", "_")


5

str is a class, not a method, so you need to do: str(!Time!).zfill(4) This should work if the Time field is an integer. If it's a float or other type, you will need to recast it as an int.


4

In this example, the "soils" field is text and the "WScore" field is double. The following approach should work for you: Pre-logic Script Code: def reclass(x): if x in ["Ds", "Oo", "Mu", "P", "Se"]: return 2.5 else: return 0 reclass(!soils!)


4

To expand on the other answers: If you will be defining other values from RASTERVALU, besides the 1201, to CN_LEVEL3 you can put a dictionary into the codeblock. Example (I made some random values): def calcVal(inVal): values = {1201: "Developed, Open Space", 1202: "Forest", 1203: "Water"} if inVal in values.keys(): ...


3

Assuming the data type for DIST_EDGE is numeric, the function should be (note, no quotes): def Reclass(dist): if dist >= 5: return dist else: return 0 However, if DIST_EDGE is a string data type, you must cast it to a number before making your comparison: def Reclass(dist): if int(dist) >= 5: return dist ...


3

Have a look at this bit of code as your fieldB is of type string it does not need to do any type conversion. This bit of python goes in the code block: def numonly(s): if s.isdigit(): return s else: return ""


3

In your field calculator, select Python as your parser. In your code block: def calcVal (inVal): if inVal == 1201: return "Developed, Open Space" Then in your field calculation box: calcVal(!RASTERVALU!) Tweak as needed. Look into if/elif/else statements for a bit more complex logics.


3

For a quick solution instead of using an if/than you could do a select by attribute then calculate the field on the selected records like this: This is a quick approach if you only have to run this for one value however gm70560's answer is far superior if this has to be repeated for multiple values.


3

This can be achieved with use of a Spatial Join (right click in table of contents -> join -> join data based on spatial location). The spatial join will allow you to transfer attributes from one feature class to another based on location. However, I have always run into issues with boundaries when I perform a spatial join between polygons. To make sure your ...


3

in the field calculator, with Python parser, check for "codeblock" and enter import math def test(maxspeed): if maxspeed >= 40: return 73.5 + math.log10(25) * (maxspeed/50) else: return 71.1 then enter NOISE = test(!MAXSPEED!)


3

A couple things to note: Your code block is currently taking two arguments, but you really only need to take one. AKA_STREET_TEST1 is the result you want, not something that Calc() will consider when calculating. So your expression should be Calc(!STREET1!) -- because you want the function Calc to do something using the information from field STREET1, and ...


3

You are using the wrong rounding function: ceil: rounds up (to the ceiling) round: rounds to the nearest value floor: rounds down (to the floor) If you select a function, you can see the help documentation in the pane on the right hand side of the field calculator window. This will explain how to use each function.


2

It sounds like you've got the right idea but you're testing if STREET1 is perfectly equal to "AVENUE". Because STREET1 has the road number in it though, it will never be equal. Therefore, you would need to see if it contains AVENUE, not just is equal to AVENUE. If you use the python find() function on a string and it doesn't contain the value you're ...


2

you could use the find() function def Calc(street): if street.upper().find("AVENUE") >=0: return street.upper().replace("AVENUE","AVE") Calc(!street!) Note that Python is case sensitive, so I added upper() to take all cases into account


2

Try this if you are updating existing field and @radouxju method for populating new field: def Calc(STREET1): return STREET1.replace('AVENUE','AVE')


2

If you did want to use the codeblock (arcgis 10.0) you need to define a function and return a value. Example: def rename(field): if " " in field: return field.replace(" ", "_") Then below the codeblock: rename(!NAME!) This assumes that the NAME field is a text value.


2

Sorry. Wildcards are for use in strings, and unfortunately the double quotes around a column name don't mean that it's a string. Column names are "identifiers", which I think are basically object names, but I'm no expert. That doesn't mean that there is no way to do what you're asking, but it won't be happening in field calculator.


2

The $x and $y values only work for point layers. Create a layer for polygon centroids and then that will give the x and y values using the $x and $y commands.


2

There are several ways to calculate this, one is using regexp with Python: expression: value(!f!) code block: def value(f): import re if len(re.findall(r'\d', f)) ==1: return "00{}".format(f) elif len(re.findall(r'\d', f)) ==2: return "0{}".format(f) else: return f


2

Most likely the issue that is causing the "invalid field" error happens during the join. When you join two tables togeather in Arc, the field name will change. The alias of each field will stay the same (example: ossz). The actual field names however will change to a combined name based on the two table's names (example ossz.c) Check the real names out, ...


1

I think there are two things going on. First, you can't use "class" as a variable name, since VBScript reserves that for defining classes. And second omit the "as Integer" in your declaration. This should work: Dim rip_class if [AGE_DATABA] >= 200 AND [Riparian_S] <> 1 then rip_class = 5 elseif [AGE_DATABA] > 200 AND [Riparian_S] = 1 then ...


1

I dug up the following article from microsoft about the error you are getting. https://msdn.microsoft.com/en-us/library/5e3hfkby(v=vs.84).aspx It seems there is an issue with either the syntax or using a VB specific work as a variable. I think the word "class" is a reserved word in VB Script. http://support.microsoft.com/kb/216528 Try changing "class" ...


1

Your code does not work because you are using the reserved keyword in VB which is class. Dim n if [AGE_DATABA] >= 200 AND [Riparian_S] <> 1 then n = 5 elseif [AGE_DATABA] > 200 AND [Riparian_S] = 1 then n = 2 else n = 0 End if your field = n


1

To avoid the need to use Python you can use Select By Attribute first. This is available as a tool, from the Selection pulldown or from Table Options. Then use Field Calculator or the Calculate Field tool to update just those features with the desired value.


1

Another option that may work for you is to use the Data Loader. No need for a join in this case. Right click the table, select Load, and follow the prompts to map your fields and load the data.


1

I would suggest the following: Make sure you are performing field calculation on data stored locally on your computer (large calculations over a network will take much longer) Make sure you run the calculation on a feature class, not on a in-memory joined feature class (so perform the join, export to new feature class, then run the calculation) Make sure ...


1

One option is to first use the Join Field tool. Joins the contents of a table to another table based on a common attribute field. The input table is updated to contain the fields from the join table. You can select which fields from the join table will be added to the input table. But, beware because this actually alters the input table- it's not ...


1

This seems to be answered by the Calculate Field (Data Management) documentation: When calculating joined data, you cannot calculate the joined columns directly. However, you can directly calculate the columns of the origin table. To calculate the joined data, you must first add the joined tables or layers to ArcMap. You can then perform ...



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