Tag Info

Hot answers tagged

4

In the pre-logic script code block (after having chosen python as the parser), you'll want something similar to this - def categorize(value): if 0 <= value <= 500: return 'red' elif 501 <= value <= 1000: return 'green' else: return 'light purple' and in the text box below it, you'll want to call the functio ...


4

To update the field values, your function needs to include a return statement, like so. def function(A,C): if (A == 0): A = (C/3) if A < 1: A = 1 return A The reason you get the 'The field is not nullable' error is that shapefiles don't support nulls and since your function didn't explicitly return anything, it is trying to Calculate ...


4

The easiest way to do this is to use Python (can be run in Python window in ArcMap if you are not familiar with any IDE or Python prompt): import random print random.sample(range(800000), 240) This will give you a list of unique value (with no repeating), such as [1,2,5,12]. Now you can use the Select By Attributes in ArcMap and select the features which ...


3

You're in need of a global variable where you can increment your new fid_1 field as CalculateField moves from record to record. Substitute this in for your last few lines of code: (Your first record will have a value of 0, the second will be 1, the third will be 2,...) codeblock = """id = -1 def getCalc(): global id id += 1 return id """ ...


3

Field Calculator can only update one field at a time, so you could perform slight variations of a calculation for each field. Or, if you're willing to try a little Python you could use arcpy.da.UpdateCursor to do it all at once. Could even just drop this into the Python window (modifying for your own table path and field names of course). import arcpy ...


3

Here's the code and steps you will need to follow in Field Calculator: def get_node(node_text,node_number): parts = node_text.split(',') node_val = float(parts[node_number][parts[node_number].find('_')+1:]) return node_val Make sure that Python is selected as the Parser option Click on the Show Codeblock check box Paste the above code into the ...


3

The following Python can be used to sort features by some attribute, here the area, and increment some field, here named 'Rank'. The field should exist. Make your polygon layer the active layer and paste the following code into Python console. aLayer = qgis.utils.iface.activeLayer() # get active layer # create list of tupels of area and feature-id aList= ...


3

You could give this a try: !ADDRESS!.lower().split(" apt")[0].strip().title() for 10221 Yukon Ave Apt#5, it returns: 10221 Yukon Ave or if you want them all uppercase: !ADDRESS!.lower().split(" apt")[0].strip().upper() for 10221 Yukon Ave Apt#5, it returns: 10221 YUKON AVE Of course this will not work in all situations. For example, if you have a ...


2

There two things going on here. '==' evaulates truth, while '=' assigns the value. A == (C/3) translates to: does A = C/3? No. This returns False. As DWynne also points out, you need to return a value. def function(A,C): if (A == 0): A = C/3 return A function(!A!,!C!)


2

Yes, in the recent versions of QGIS, if you have a selection the 'Only update x selected features' checkbox is enabled as default. Any expression written will be updates to the chosen column of the selected rows. Below picture is from QGIS 2.8.1.


2

Please let me know if I am misunderstanding your work. It looks like you want to add HydroCodes to NRCS SSURGO data. What is the source of the HydroCodes? Are HydroCodes something in the SSURGO database, like the Hydrologic Soil Group? Most of us don't work with NRCS data in the US, so here is a description. NRCS SSURGO data consists of a shapefile of Map ...


2

Along the lines of Branco's comment the expression would look like this:


2

The formula you're looking for is as follows: t=\sqrt{2d/g} where g = 9.807 To add this to the field calculator you can either use a (python code block)[http://resources.arcgis.com/en/help/main/10.1/index.html#//005s0000002m000000]: sqrt(2 * distance / 9.807) Or, in the field calculator directly (since it does not support square root function): (2 ...


2

Using a Python parser, calculation would look like: This will return a 0 for your first two records, and a 1 for the last three. Edit: for @Masonerman9's comment about good enough matches. Could try difflib. I haven't used it much, but it does build in some tolerances for string comparisons. The below will give you a 1 only for the fourth record (Randy ...


2

Without precisely knowing the projection of your data, it's difficult to be sure what went wrong with your calculation. That said, it's always risky methodology to allow any kind of reprojection on the fly in your GIS when you're additionally performing geometry calculations. The same is true if you have several layers in a mixture of projections, in which ...


1

Using an Update Cursor in a Python script is an efficient approach. The following example takes the last word in the Owner_1 string and the first word in the owner string and compares the values. import arcpy fc = r'C:\path\to\your\database.gdb\feature_class' with arcpy.da.UpdateCursor(fc, ["Owner_1", "owner", "NAME_CHK"]) as cursor: for row in ...


1

Normally, I try to direct anyone using the Field Calculator to use Python. But to answer your question directly, you'll need something similar to this below. It's a basic pattern of if/elseif/end if. (substitute your own values of course, I use 9999/Z just to show an elseif) Note: You mention that MUSYM is a number, but the way the values in your table ...


1

In a model, this is just a combination of Calculate Value and Calculate Field. Use a bit of Python code/cursors in Calculate Value to pull out the first value from the data source. If your data elements are different in your model, adjust the use of '%Feature Class%' and '%Field Name%' as appropriate. And then hook that up to Calculate Field. With ...


1

It's not a direct answer to your question as you are looking for a post-processing step, but as you say that you will do this step "after each polygon created into each field" you may be interested in the setting Setting > Options > Digitizing > Reuse laste entered attribute values. This will set the previously used attribute values as default while ...


1

On the last line, CalculateField really needs an extra level of quotes on the expression to make that work. Because otherwise the expression is being evaluated by the tool in Python and seeing it as a variable, hence the NameError: name 'Route1' is not defined that is being bubbled up by the tool. So this should solve your problem: ...


1

You can use an Update Cursor to do this type of classification: import arcpy fc = r'C:\temp\yourFC.shp' with arcpy.da.UpdateCursor(fc, ["Field1", "Field2"]) as cursor: for row in cursor: # row[0] = "Field1" # row[1] = "Field2" if 500 >= row[1] >= 0: row[0] = "red" elif 1000 >= row[1] > 500: ...


1

Yeah, you have a basic if/else logic, check out this: Basic If/Then in ArcGIS 10.2 Field Calculator (Python or VB) dim n if[integerfield] > 500 then n = 'Red' elseif[integerfield].....



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