Tag Info

New answers tagged

0

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


0

I don't know arcmap but in excel you can have it easyl done with MID and Find formula. Here is an example (A1 the string, B1, C1, D1 are the columns where you insert the new values): a1: "Node 1_1234.23,Node 2_567.88,Node 3_45.25" b1: =MID(A1,FIND("1_",A1,1)+2,FIND(",",A1,1)-FIND("1_",A1,1)-2) c1: ...


0

You can use Hawth Analysis Tool . It is very easy to use . You need to specify the number of sample to be drawn. Installation process in arcgis is here. Just select and export the layer. You can also use arcscirpt at here


3

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


2

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


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


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


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


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

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


0

Remove the Dim a as String line and it will work. Calculate Field is using VBScript, and in VBScript all variables are of type Variant.


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


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.


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


0

I see a couple potential errors/improvements. One is that your very last line should be indented one block so that it occurs in the for loop, but maybe that's just a formatting issue on this post, and your actual code is fine. Issue 2 is what the error message is referring to. When calculating text fields, the value needs to be encapsulated in double ...


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


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


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


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


0

The ArcMap calculator breaks Python rules and accepts only if, not the elif. Just replace all the elif code with if instead. It is correct that the file must be a geodatabase and not a shapefile.


0

If it is a gpx track, the points should be in order, so you can just walk the track and compare the timestamps of the two adjacent points and output point1id, point2id, deltatime fields to a table. You could actually do in python working directly on the gpx track without messing with qgis.


2

For shapefiles, the time portion is truncated from the datetime value. So you should work inside a geodatabase if you need the time. If you really need to work in a shapefile, I suggest that you try it within a text field


1

You can use the substr() function in the field calculator substr("field-name", 4, 100)


2

You have different possibilities String manipulation toint( substr( tostring( 16011234 ), 5, length( tostring( 16011234 ) ) - 4 ) ) And for your second question: Take the substring starting at position 3 ( 16011234 ) with a length of the total number of digits (8) minus the first two minus the last two resulting in a length of 8 - 4 = 4 In the end ...


1

I think you can change python encoding, you may look at link below. http://stackoverflow.com/questions/2996475/what-character-encoding-should-i-use-for-a-web-page-containing-mostly-arabic-tex http://stackoverflow.com/questions/728891/correct-way-to-define-python-source-code-encoding


2

Sorry, but the layers are not in the same CRS. The Catchments is in an Albers Equal area projection (units-meters) and the other two are in Haartebeesthoek94, with degree as units. So your area calculations are in square degrees. If you reproject the transmissivity and intersect polygons to Albers Eq Area (with the "Save As..." option in QGIS) then ...


0

The Field Calculator uses the Calculate Field tool, and like many geoprocessing tools it honors at least some of geoprocessing environments. If the input is spatial (i.e., not a table), and the extent has been set, the calculation will be limited only to those features/records that are within the extent. If the extent doesn't cover any features, no ...


0

I would use a dictionary in the code block, that way it's easy to update or add options if necessary. Before running the calculation, be sure to save the expression so you can reuse it. Code Block: def translate(input_value): out_value = None dict = { ["A", "Ae", "D", "V"]:"1 PCT", ["X"]:".2 PCT" } for key, value in dict.iteritems(): ...


0

As a couple others have pointed out, you're missing a return value. You're also confusing the assignment operator = for an equality operator == (in the 2nd if). The if structure is also incorrect (if/if/else), and will calculate the wrong value for anything less than 60 (should be if/elif/else). If you still want to use CalculateField (the other answer with ...


3

It is much more intuitive, in my opinion, to work with Cursors (rather than trying to emulate the field calculator in a script) for this type of problem. This is how you would port the problem over to an Update Cursor: import arcpy # The input FC fc = "C:/W/Sik.gdb/yourFC" with arcpy.da.UpdateCursor(fc, ["aspect", "aspect_m60"]) as cursor: for row in ...


3

Your function is not returning anything. I've modified your code to return the value of aspect_m60. # Calculate Field import arcpy # Set environment settings arcpy.env.workspace = "c:/W/Sik" # Set local variables inTable = "Point" fieldName = "aspect_m60" expression = "getCalc(!aspect!)" codeblock = """def getCalc(aspect): if (aspect < 60): ...


2

You are trying to set the field within the code block, when actually you need the code block to return the value you're looking for. If you just just add return aspect_m60 after the else block, it should work fine. Think of the code block as a place to write functions whose results can be used in your field calculator expression.


2

You can't sum columns using the Field Calculator (although it would be useful in certain situations). To be able to sum columns and obtain a value, you can use: QGIS function - Basic Statistics (Vector > Analysis Tools > Basic Statistics) QGIS Plugin - GroupStats (Plugins > Manage and Install Plugins) QGIS Plugin - Statist (Plugins > Manage and Install ...



Top 50 recent answers are included