Tag Info

Hot answers tagged

6

Just put this as the script code: def Recode(LV, IV): if LV < IV: return 1 elif LV == IV: return 2 elif (LV > IV and LV < (IV * 2)): return 3 elif LV > (IV * 2) : return 4 else: return 0 Recode(!LAND_VAL!, !IMPRVT_VAL!)


5

Your variable names cannot have a dot (.) in it. Simply change your function to the following: def update(field1, field2): if field1 != field2: return field2: else: return field1 Python has some conventions for variable names. You can use any letter, the special characters “_” and every number provided you do not start with it. ...


4

Python's split() returns a list object (an array), so if you use split("_") on "A_B_C_D" you get an array where you can access every Letter by its index. The underscore acts as an separation character in this case, and parsing character separated lists is one of the most common uses of the split() function fielda= field1.split("_")[0] fieldb= ...


3

I take no credit for the following Python snippet, which is taken from an ESRI idea found by Googling 'convert from julian to calendar date arcgis'. As trivia, they mention the data they were working with came from the FAA. There is also mention of data coming over from Excel in that format despite being entered differently. I apologize if my cut/paste ...


3

Looking at the ArcGIS help section, you can see the necessary parameters and descriptions: CalculateField_management (in_table, field, expression, {expression_type}, {code_block}) To translate this to your script; import arcpy file = r'C:\your\file.shp' arcpy.CalculateField_management (file, "FRMEAS", "1")


2

You can open the attribute table, toggle layer editable (if not yet done) open the field calculator and check Create a new field, give it a type / name and use an expression to fill it with values based on existing attributes.


2

Yes, you can do this using a code block in the Field Calculator. There are several examples of doing this in its Online Help. For example: Parser: Python Expression: Reclass(!WELL_YIELD!) Code Block: def Reclass(WellYield): if (WellYield >= 0 and WellYield <= 10): return 1 elif (WellYield > 10 and WellYield <= 20): return 2 ...


2

The answer is yes, the way that is written an operation is being performed on every record. I haven't gotten into python yet, so I don't know if there is a 'do nothing' option - as Ian pointed out, without the else it will null the values. I see two possible solutions that are sort of the same if there is no 'do nothing' option. One, you would have to check ...


2

The return value will only ever be set to the field you are calculating. Any fields you use to compute that value are not changed. In the example below, only SHORT_NAME field would be changed. This will also set every record in the field whether or not the value is the same. So I guess more to your question, if you are setting the values for field1 ...


2

The field calculator cannot be used in that way. If you want to create buffers, use the buffer tool from the vector menu. The buffer function and other geometry functions in the field calculator can be used for calculations but not to create new geometries/features. For example to check if the features intersect a certain geometry: intersects( buffer ...


2

Assuming all of your row values are in the form chunkA_chunkB, you can use the following expression in the field calculator: !yourField!.split("_")[1] This method actually breaks the string into a list of selectable items. To illustrate, in the python interpreter: >>> row1 = '123456_CC' >>> row1.split("_") ['123456', 'CC'] And to ...


2

To ensure that you don't calculate an illegal division by zero, first ensure that all values of KM2AREA are not zero. You can do this using the Select By Attributes functionality (presuming you're using ArcMap - other GIS's will have a similar function. Then ensure that the Field Calculator is set to the default of only using the selected values.


1

I am just playing around with this. I found the same site/formula that @Alex Tereshenkov mentioned in the comment above . Here is what my field calculator expression and codeblock look like: def CalcDate(JD): L= JD+68569 N= 4 * L /146097 L= L - (146097*N+3)/4 I= 4000*(L+1)/1461001 L= L-1461*I/4+31 J= 80*L/2447 K= L-2447*J/80 L= J/11 J= ...


1

with python parser, you can use replace to remove ALL spaces !myfield!.replace(" ","") or, if you want to trim the first spaces only, you can use !myfield!.lstrip() Note that LTrim will work in vb LTrim([myfield])


1

This is a quick and easy way to get around the problem..but doesn't fix the error. This method works in the python window. This design is often used inside of loops, and I'm unsure if the Field Calculator will accept it. try: #the code you want to work goes here except: #handles the error #print "an error occurred, but I can continue to work" ...


1

I think the answer to your question is yes. Your code says to return Field1 if Field1 is equal to Field2, so it is reassigning those same values to Field1. This shouldn't be a problem though, I would not think. I agree with ian in that you could just leave out the else statement, and then it wouldn't be reassigning. I also assume you actually put in the ...


1

As far as I know the field calculator only updates the field you want to calculate (usually you start the field calculator with the right mouse click on the field you want to recalculate and that is where the return value leads to). Same when you start the field calculator by using the arcpy expression calculateField_management.


1

I suspect the field you are calculating is in short or long integer format and thus will not be able to store decimals. Check the field type by right-clicking the field name > Properties... > type: You need to add a new field as either float, double or text and redo the field calculation. Another thing to check is if your field has rounding ...



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