Tag Info

Hot answers tagged

6

The following approach, using the Python parser, selects the min value from a list of input values. min(!L_ADD_FROM!, !R_ADD_FROM!)


5

I would use the following approach which incorporates logic to check for your "FIPS" code. import arcpy fc = r"E:\Test_Errors_onE\myPath\myFile.shp" with arcpy.da.UpdateCursor(fc, ["FIPS", "kg", "kg_new"]) as cursor: for row in cursor: if row[0] == 06307: row[2] = row[1] * 3 if row[0] == 06308: row[2] = row[1] * ...


4

In QGIS you can use abs("fieldname") to turn them into always positive values.


3

In my opinion, the best way to calculate a field using complex logic when you're already using Python is to do it with an UpdateCursor instead of the Calculate Field tool. (As @FaridCher's answer shows, you end up defining a Python function in a string, which makes it difficult to read, as well as to write.) In your code, I would replace ...


3

Rather than using if-elif statements, just reclassify using a one-liner expression with a dict: {"R<10_min": "1", "R_10-20_min": "2", "R_30+": "3"}.get(!SA_All!, "0") which you can put the CalculateField_management function: arcpy.CalculateField_management( fc, reclass_field, '''{"R<10_min": "1", "R_10-20_min": "2", "R_30+": ...


3

You should declare your method, calc_value, as a code block in CalculateField_management tool: codeBlock="""def calc_value(orig_field): if (orig_field == "R<10_min"): return '1' elif (orig_field == "R_10-20_min"): return '2' elif (orig_field == "R_30+"): return '3'""" And then use: ...


3

Right-click FROMADDRESS, as you want to populate that one, and open the Field Calculator. Check the Python button Check Show Codeblock Now, in the bigger area you will insert this function: def findSmallest(l_add, r_add): if l_add < r_add: return l_add else: return r_add And in the smaller part below the "pre-logic script ...


3

You can take care of this before ever trying to load the data into ArcGIS by creating a schema.ini file. Simply use a text editor to save a file called schema.ini (no other extension) in the same folder as your CSV. Then, explicitly specify the data types for columns that you don't want ArcGIS to infer. For example, if your CSV were called mydata.csv and ...


2

Would you consider a Python solution, especially if you have to do a lot of separate calculations in your model? The problem with the field calculator for a script process is that it is slow and not expanding your thinking beyond a manual process. Why process every row in your table every time you do a field calculation when a cursor can process all of ...


2

You're mixing returning values from a function and assignment. You have to return the modified value, not assign it to the old variable. The correct format for the pre-logic script code would be: def mycalc(ADM2_NAME, Projects): if ADM2_NAME == "Bo": return (Projects + 1) else return Projects Although there is an even better (shorter) way of ...


2

Two options. 1.) Perform an intersect of the points with the countries. Use Vector > Geoprocessing Tools > Intersect... For the intersect tool, make the input your arch sites (points) and your intersect layer as the countries (polygons). That will produce a point file with the attributes from the countries attached to each point. 2.) If you know ...


2

with arcpy import arcpy from arcpy.sa import * out = (Raster("rclslope")>=45) & (Raster("rclmosaic")>=2000) & (Raster("rclfocal")>15) out.save("output_path")


2

No need to write a function here. Just hit the Python radio button, and then write this into the box: Address: + " " + str(!Address_No!) + " " + !StreetName! + " " + !Street_Ty! What is important: - field names are represented by their name but embraced by exclamation points: ! - any numeric field needs to be converted to a string when concatenating with ...


2

Using field calculator (or, arcpy.management.CalculateField() if you want): In the code block: def fix_matrix(field_value): if field_value.endswith("A") or field_value.endswith("B"): return field_value[:-1]+"AB" else: return field_value In the expression: fix_matrix(!MATRIX!) + !PLANT! + !PCT! + !SITE!


2

Internally you cannot modify Row Numbers. Your calculation into a new field is the number of rows - $rownum: This will reverse the $rownum into a field. $rownum (row number) objects cannot be modified as they are handled by the driver/database. In the case of shapefiles they are transient as edited features move to the end and then get compressed back to ...


1

Using Python would open up some more elegant solutions, but you can do this entirely in ModelBuilder with the use of a couple of temporary tables. The model would look something like this: The Add Field operation adds a new column called [Normalized_Value] to your existing polygon table. A pair of Sort operations create two new tables, one with your ...


1

In ArcGIS desktop you could use the following python script in the field calculator, where you would create a new field (say, FIELDNAME2) and calculate the following (where FIELDNAME1 is your original values): Pre-Logic script def values(n): if n < 0: return n * -1 else: return n bottom window values(!FIELDNAME1!)


1

I would use a simple Python script within the field calculator tool. Add this in the Codeblock box: def my_concatenation(address_nr, my_street_name, my_street_ty): my_address_nr = str(address_nr) # converts the address number into strings so that it can concatenated with the rest. my_result_string = "Address: {0} {1} ...


1

Use the 'Point sampling tool' plugin. With this plugin you can pick any column, from any polygon layer and raster layers, that your archaeological sites fall within.


1

You would probably not use the field calculator. Rather you want a spatial join. So from the menu: Vector>Data Management Tools>Join Attributes By Location This will create a new shapefile with the "Target vector layer" as your archaeological sites layer and the Natural Earth dataset as your "Join Vector Layer". Then just delete all of the other Natural ...


1

$area is calculated in the layers units, that is square degrees in your case. If you want square meters, you have to reproject your layer into a new file and with a projected CRS that uses meters as units. After calculating the area in meters and adding it to your attribute table, you can reproject back to degrees. The attribute table value will not change. ...


1

Perhaps something like this? Code block: def GetTexture(Text1,Text2): if Text1 is None: return Text2 else: return Text1 With expression NEWTEXTURE = GetTexture(!TEXTURE1!, !TEXTURE2!)


1

It seems you've got a little confused with the field syntax, "!kg!" is the python syntax when used in field calculator ONLY. I think this is what you're after: import arcpy arcpy.env.workspace = r"E:\Test_Errors_onE\myPath" arcpy.env.overwriteOutput = True infc = "myFile.shp" #Add a new filed named fields_in_cursor = ["kg","kg_new"] # kg is 0, kg_new is 1 ...


1

Perhaps the calculator is your answer. From "Raster-Raster Calculator" you can create new layers from others. For the the intersection you can use the "AND".



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