Tag Info

New answers tagged

-2

geometries = arcpy.CopyFeatures_management("polygon_fc_name",arcpy.Geometry()) peri_tot=0 for geo in geometries: peri_tot += geo.length print peri_tot


3

At your request, here's the equivalent in Python, that can be run within calculate field. You'll need to use the codeblock as well as the expression. Code block: def yr_qtr(dt): date_str = dt.split(' ')[0] # some dates may have a time component date_parts = dt.split('/') # are they always in this format, # or is it ...


3

The query below in VBA should return a string that looks like "Q2 1990" for each record. All credits go to @EvilGenius for this one. "Q" & DatePart ( "q", [MyDate] ) & " " & DatePart ( "yyyy", [MyDate] ) Just make sure your quarter field "QTR_YR" is a Text/String type. If the format "Q2 1990" is not to your taste, you can tweak the format. ...


3

Yes - what you're after is called a "virtual field". Open the layer properties and switch to the "fields" tab. Then, click the "field calculator" toolbar icon. Check the "Create virtual field" checkbox, and make sure you choose an appropriate name and field type for your virtual field. Then, enter the associated expression - eg "Liters" / 3 Click OK, and ...


0

As given in the second Python example for Calculate Field, it should be !SHAPE.CENTROID.Y! (use . not @). @ should be used for converting units on length/area attributes.


1

So, we've ended up changing tact and moving to spatialite and seem to have managed to do it with an SQL query, including the geometry field which means I can add it as a new layer: Select Distinct T1.toid As TOID1, Min(T1.Hubdist) As MinDIST, T1.ID, T1.geometry From [Hub Distance] T1 Inner Join (Select T2.toid As TOID2, ...


7

You could use the Group Stats plugin from Plugins > Manage and Install Plugins. This calculates various data statistics for your attributes such as finding the minimum value in a group. I made an example of attributes from the data you gave: Then from the Group Stats interface, select and drag the toid field from the list into the Rows window; and repeat ...


0

This question, and its first answer, appear to have been written at a time prior to the Python Parser becoming available for writing Label Expressions. In this case I think the expression (untested) would be: def FindLabel ( [StringNumber] ): S = ''.join([letter for letter in [StringNumber] if not letter.isdigit()]) return S


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


2

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


0

I was never able to successfully run the Round() function using the field calculator on the entire data set. I continued to get the subject error every time, no matter what field type the values were in (string or float). What I did do was take the desired numeric values from the string field they were currently in and use the field calculator to put them a ...


0

I have this problem when I'm using topological editing on a shapefile or spatialite layer and on the fly (OTF) reprojection is enabled. The 'avoid intersections' function does not work consistently and some polygons' nodes are unselectable (though the polygon can still be selected and deleted). This also affects the 'Save As...' function: some polygons are ...


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


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


0

I have one more question regarding that issue: >>> test1 = "test1" >>> fieldn = '!{}!'.format(test1) >>> print fieldn !test1! fieldna = '(!{0}!, !{1}!)'.format(test1,test2) >>> print fieldna (!test1!, !test2!) Now I do see a difference. If I use the format funtion I get a tuple, but the format fits anyway. I don't get ...


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


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


0

Well i want did the same but, i can´t find... this the way i solve it. Maybe can help to anybody from qgis.core import * import qgis.utils canvas = qgis.utils.iface.mapCanvas(); layer = canvas.layer(1) maxArea = 0 maxId = 0 selection =[] uniquevalues = []; dP= layer.dataProvider() id = dP.fields().indexFromName('myColumn') #i have the unique values from ...


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


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


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


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


0

Well, you could do what you want with a correctly written field calculator expression, but I would recommend instead a 2 step method to fix the problem. Make a selection of the features needing edited and then run a very simple field calculator expression to fix those selected features, this way you can manually review which features will be affected before ...


0

It looks like it works in a script because you are explicitly getting the Shape@ field. If you run into a feature with a null shape, your first field calculator will try to unpack it and run into an error.


0

use (replace [type], "AVENUE %", "") There are many ways to use field calculator. Trying to use the if then statement in my experience you are likely going to want to try to learn some regex. It is very powerful for finding string or numeric sequences and allowing you to make changes. Short of needing more than what you already eluded in your question you ...


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


0

My impression of what you're saying is that for all avenues that are single letters you want only that letter to appear in subname, and for all other avenues you want the entire name copied to subname. Make sure the parser is Python and then use the following to calculate the SUBNAME field. Code Block: def rename(name): words = name.split(" ") if ...


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


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


0

I borrowed a lot of the code from here. Try this. Turn on the python parser in the Field Calculator. Pre-Logic Script Code: rec = 0 def autoInc(): global rec pStart = 1 pInterval = 1 if (rec == 0): rec = pStart else: rec += pInterval return rec FieldName = "SWCL" + str(autoInc()).zfill(4) The .zfill() function makes sure your ...


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


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


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.


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

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.


0

I would recommend using the format method of the string class to perform this type of operation. Here is a link to a similar question: Concatenating string and numeric data in ArcGIS As a general rule you should avoid using concatenation in favour of the format method. You will have cleaner code and more control over the final output string.


0

in Arcmap they given this example http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000004s000000 Concatenate two fields with a space separator !SUB_REGION! + " " + !STATE_ABBR! in python



Top 50 recent answers are included