Tag Info

New answers tagged

2

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


0

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

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.


2

Instead of using an if/than you could just do a select by attribute RASTERVALU = '1201' than use the field calculator CN_LEVEL3 = "Developed, Open Space" it will only calculate the selected records all of which will have a RASTERVALU of 1201.


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

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


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


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

def calc(a): if "AVENUE" in a: return "AVE" calc (!STREET1!)


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


0

Open Field Calculator on FieldB. On Field Calculator, check Show Codeblock. Paste this code under Pre-Logic Script Code: # assuming FieldB is Long Integer as you mentioned "FieldB is longstring". # there is no such data type. I'm taking "longstring" as typo error for Long Integer def get_numbers(value): return value if str(value).strip().isdigit() ...


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


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


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


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

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.


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.


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


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


1

Try def Reclass(Age_Databa,Riparian_S): if Age_Databa <= 200 and Riparian_S != 1: out = 5 elif Age_Databa > 200 and Riparian_S == 1: out = 2 return out You'll need to expand that for your third condition. I suspect you should be looking at the reclassify tool.


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


1

following on phloem's comment - it appears you are almost there, you just need a few more pieces: The following assumes you have the Field Calculator parser set to Python. I've always indented one space for Field Calculator Pre-Logic Script Code following ESRI documentation which I can't seem to locate at this time; it's counter-intuitive to most all other ...


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


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


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


0

you can use the spatial join to get the attribute of your service area overlapping the parcels. Then you can change the values using the field calculator.


3

if/elif statements in python will do this for you. In your field calculator, select Python as your parser. In your code block, input something like this: def newFieldVal (Perturbation, TER_CO...): if Perturbation == "X": return Perturbation elif Perturbation == "Y": return Perturbation elif TER_CO == "Q": return TER_CO ...


2

Often times when it looks like I would wind up with a complex set of if/then clauses in a field calculator expression (which can be trouble because of the limited debugging), instead I'll just do a series of this - Select certain rows by using Select by Attributes. For example, select all rows where 'perturbation = "X"' Use Field Calculator to set a value ...


5

In general, you need a pre-defined list of the road types, since not all your values end in a road type. For ArcGIS, the following is a simple example of populating SitusRdType: In the Field Calculator, check that Python is set as the parser and check Show Codeblock. In the Pre-Logic Script Code box: def setRdType(myInput): lstRdTypes = [' RD', ' AVE', ...


2

Since you mentioned in the prev question that your input file is a Shapefile, it should be noted that QGIS is not using the data in the attribute table at all! Instead it reads the coordinates from the .shp binary file part. You can use affine transformation to move the geometries. https://gis.stackexchange.com/questions/tagged/affine-transformation+qgis



Top 50 recent answers are included