Tag Info

Hot answers tagged

9

This will depend on what software you're using. Since you mentioned Field Calculator in your question, you are going to be using a programming language parser to convert values. For Python (ArcMap, QGIS), you can use python's built in conversion functions. This page explains it fairly well and shows examples. If you're using ArcMap and VBScript, there ...


4

You need to indent the function you're defining. Don't further an indent for an if statement until after the if statement. def calc(f1,f2,f3): remove_list = ['01ST', '02ND', '03RD', '04TH', '05TH', '06TH', '07TH', '08TH', '09TH'] if f2 in remove_list: f2 = f2.replace('0','') else: f2 = f2 ...


4

In your Field Calculator, have the python parser enabled. You can do some neat things with the Field Calculator. I suggest checking out the Field Calculator Unleashed from ESRI for a bit of a code introduction to the Field Calculator. Then check out their documentation for more advanced ideas. I am using lower() and strip() in case there are values that ...


4

Here is the solution to your question in ArcMap 10.1 when using VB Script. Your example for this will be: "abc" & [integer] within the expression box. If you would like to have a space between your expression will be : "abc" & " " & [integer] (Note that there is a space between the middle parentheses). From what Adam said: Using the Python ...


4

The first line should not contain the field call (!Classe!). Your code should look like this... def TextValue ( classe ): if ((classe == "Steppe arbustive") or (classe == "Steppe arbustive à arborée") or (classe == "Steppe arborée") or (classe == "Savane arbustive") or (classe == "Savane arbustive à arborée") or (classe == ...


4

Your code is not correctly formatted Python code: Indentation is important in Python, as it defines where functions and conditions start and end. You need a : after the function definition The correct operator for equality-comparison is the == and not simply = which assigns a value to a variable. Also, with respect to the field calculator in ArcGIS, if ...


4

With cursors and the "SHAPE@" token, a geometry object is returned. The getPart() method returns an Array containing all the points for that particular part. Interestingly, field calculator also returns a geometry object, but the getPart() method does not appear to return an array, although it is something similar. Maybe an unpacked array? Luckily, arcpy ...


3

Although you're asking for an answer related to value map combo-boxes, I thought to provide an alternative where you could use the following code to read the values in the first row for each column and copy it for each of the attributes. Select the layer in QGIS and copy/paste the code into the Python Console (Plugins > Python Console or Ctrl + Alt + P): ...


3

I'm not sure how to do this is VB Script, but I do in python. In the field calculator, set your Parser to Python. Click the Show Codeblock box. In the input box (where you see fieldname = above), type in getYear (!fieldname!), where fieldname is the name of the field with the years. The code block code depends on if your field is a string or a number type ...


3

Your code isn't formatted correctly and you're using the wrong things for parameters. def TextValue ( input ): #needs to be a variable, not your field if input == "Steppe arbustive" or input == "Steppe arbustive à arborée" or input == "Steppe arborée" or input == "Savane arbustive" or input == "Savane arbustive à ...


2

This could be the solution to your issue. My line dataset had lines dissolved by an attribute, so that two (or more) lines in separate locations were merged (the dissolve command has an option for this or the merge command may have been used) to a single record of the attribute table. When editing the vertices of such a record you can see ...


2

use field calc to return the MAX M measures: !Shape.extent.MMax! use field calc to return the Min M measures: !Shape.extent.MMin! you can then calculate the M-length of the line using subtraction.


2

Using python parser in field calculator you may use the following functions to run the city/state splits and ignore those records with empty values (I know this is not vbscript but it is very easy to implement too): Note, it would probably be better to have "," delineating the city/state names in the CityState field to ensure a more robust split for cities ...


2

Things you may be able to try: -Get a better internet connection to your VPN. -Try running subsets of your records (500/time) --Select 500 records (so they're blue), run the Field Calculator, rinse/repeat -Try not doing it during an edit session (faster but can't revert) -Make sure the VPN is letting you access your license server (if applicable) --You ...


2

My comment above provides one way to do this. If you need to do it programmatically, ensuring that only the rows that contain single letters in the table be updated then you can use the following Python in the field calcualtor. pre-logic: def newText(txt1, txt2): if (len(txt2) == 1): return txt1 else: return txt2 execution: newText(!NAME!, ...


1

Your input and output column should be text type. It's expecting a string or buffer and you passed probably integer or double.


1

This should work for you: import arcpy fc = r"C:\Users\us\Documents\ArcGIS\Default.gdb\_PointDistanceFc" field1 = arcpy.GetParameterAsText(0) field2 = arcpy.GetParameterAsText(1) codeblock = """def myFunction(field1_dum, field2_dum): if field1_dum >= 1 or field2_dum >= 3: return -3 elif field1_dum == 0 and (field2_dum==1 or ...


1

Use block rec=0 def autoIncrement(): global rec pStart = 1 #adjust start value, if req'd pInterval = 1 #adjust interval value, if req'd if (rec == 0): rec = pStart else: rec = rec + pInterval return rec Call it using: str(autoIncrement( )).zfill(5) It will work on text field


1

Thanks to Paul Here is the solution: in Pre-logic Script Code Box: def foo(MamerMN): if (MamerMN <= 0.200000): return 1 elif (MamerMN >= 0.200001 and MamerMN <= 0.400000): return 2 elif (MamerMN >= 0.400001 and MamerMN <= 0.600000): return 3 elif (MamerMN >= 0.600001 and MamerMN <= 0.800000): return 4 ...


1

You are calling your function with text values " " instead of field names ! !, therefore it returns true to the first condition. just try this : codeblock = """def mthree(mthre, mtwo): if mthre >= 1: return -3 if mtwo >= 2: return -5 else: return None """ ...


1

There is also a split function in VB Script. So, your code would look something like (VB Script Parser Checked and Show Codeblock checked): Pre-Logic Script Code: Dim result a = Split([YOUR FIELD], " ") 'first parameter is field name, 2nd is delimter result = a(0) 'or a(1) depending on what part of the split string you need FIELDNAME = Part result ...


1

Try the following: !Legal!.split(" AC")[0].split(" ")[-1] The first split will separate the rest of the text from " AC" and the second will give you last text element separated by a space.



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