Tag Info

New answers tagged

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


4

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


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


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


0

Here is an answer, but it's a bit hacky... halfway between Field Calculator and true arcpy tool: def CalcThis(YourID): YourFeatClassOrLayerName = "Polylines" # Change this to your layer name desc = arcpy.Describe(YourFeatClassOrLayerName) fList = arcpy.ListFields(YourFeatClassOrLayerName,"L*") # List of matching fields, in this case fields ...


0

This answer from PolyGeo worked for me: http://gis.stackexchange.com/a/81155/44980 .strip() removes all whitespace characters def TestForNull(Field1): if Field1.strip() == "": return 'is null' else: return 'not null'


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


2

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


0

You can use Python string formatting in the Field Calculator without using a code block, which makes things a bit cleaner for simple operations: As a general rule it's usually better to use string formatting and avoid using concatenation. This is especially true when you want to have more complex numeric formatting, such as currency, or date formatting. ...


0

The VB Script version/alternative to BritishSteel's answer: Add a new text field with enough characters to hold your longest address to the attribute table (must be done outside of an edit session). Right-click on the new field and choose Field Calculator (in or out of an edit session, but out of means no 'undo'). In the Fields box, double click the first ...


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


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


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


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


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


0

Fisrt I would compile lookup tables for TEXTURE1, TEXTURE2 and TEXTURE3 using Summary Statistics (to find all the unique values), statistics doesn't matter all you want is each TEXTURE field as a 'case' field. Add Field to add the value you want to apply to each statistics table to make it into a lookup table, delete the statistics fields if you wish with ...


0

I found a solution with the use of dbfpy. I converted my Python list to a dbf using this module, and joined the resulting table to the feature layer. db = dbf.Dbf("C:/data/test.dbf", new=True) db.addField( ("BG10", "C", 12), ("TR", "C", 10), ) for i in l: rec = db.newRecord() rec["BG10"] = str(i[0]) rec["TR"] = str(i[1]) rec.store() try: ...


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


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


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


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

You are try to change the value of the input field (Projects) in line 3: return Projects += 1 change it to: return Projects+1 Furthermore change not all of your code paths return a value. change like this: else: return Projects


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


-1

Another way to convert to real numbers would be (toreal("ElectionYes") / "ElectionTotal"


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


0

Query Layers are designed for this kind of layers. In Arcmap: Go to File > Add Data > Add Query Layer... see this help page for details. Your query should look like: SELECT field1,field2, field1+field2 as field3 FROM Test.dbo.TableName


3

You need to pass the returned value in a variable, not reference the column itself. Expression: result Codeblock: if [ColumnB] > 0 then result = [ColumnA] / [ColumnB] else result = 0 end if Here's how the two parts fit together in the field calculator - my data doesn't have the same field names, but you get the idea.



Top 50 recent answers are included