Tag Info

New answers tagged

2

You could simply use the Coalesce function which returns the first non-NULL value from the given columns (fields). Insert this expression into the Field Calculator as a new field: coalesce( "Field_1", "Field_2", "Field_3" ) Below is a simple example: If a feature has columns with multiple values (eg. 1, NULL, 3), then you may need to include ...


1

I really like using feature layers and selection for this kind of thing. Below I find all my relevant fields, then try selecting Nulls/''. If there's a selection, I field calculate. I haven't tested the script, so it may not be perfect. def removeNumericNulls (inFeatureClass): import arcpy #Relevant field types fieldTypes = ["Double", ...


0

Just for fun, I noticed ESRI 10.3 only shows NULL as 0 so you have no idea what is in there. In QuantumGIS Brighton or later, the field shows as NULL, but you don't know which one. I modified this as the following (I added a zero after copying off Jamie): def RemoveNULL(x): if x is None: return '0' elif x == '': return '0' else: ...


1

If you want this as a python script, then you could do something with an update cursor... inputData = "" #Needs to be the full path codeField = "" updateField = "" with arcpy.da.UpdateCursor(inputData, [codeField, updateField]) as updateRows: for row in updateRows: if row[0] == "TestValue1": row[1] = "NewValue" elif #... etc ...


0

I would recommend the batch solution, because no data selection (Group By) is necessary and will run faster. By integrating the answer of that question and loop over shapefiles you can achieve your goal. Just modify the code as necessary: - edit the number of ranks, - shapefile folder and so on Code: import arcpy import numpy as np import os #loop ...


4

Out of the box, field calculator does not support spatial joins across feature layers. But, if you have a look at NathanW's post on the function editor for qgis expressions you will be able to make out that we can script our own data interaction. The following script will allow you to express what you're after. It works by iterating through all features ...


1

There is a much simpler way using a Dictionary object. To be accessible/updateable for each iteration it must be outside the scope of the function (global) otherwise it's reset for each calculation. preDict = {} def CalcField3(Field1,Field2): global preDict # tell python this isn't a new variable but the other one if preDict.has_key(Field2): # if ...


1

Assuming "Nearby:" is at the beginning of the line (and never in the middle), you can simplify this logic with a one-liner, without the need of a codeblock: str(!Street1!).replace('Nearby:', '').lstrip()


2

as written, the function returns a string with 'Nearby:' removed only if the 'Nearby:' test is true (if 'nearby:' exists within the field string. If the test is false, the function is set to 'pass', which returns no value (deleting the original value in the process) to remedy, a value should be passed for both cases - true and false - something like def ...


1

I would assume you're using this in the advanced field calculator (show codeblock)... In this case "Tertiary" would never be hit as you're getting the select case of the uppercase and that word contains lower case characters. In this case a=10 at the start and none of the Case in the block are ever hit. As to why none of these cases are ever hit depends on ...


2

Use the ModelBuilders' Calculate Field to insert a python code like this: Expression: calculate(!Field1!, !Field2!) And a code block of: previousValue1 = "" previousValue2 = "" previousUnchangedValue1 = "" def calculate(field1, field2): global previousValue1 global previousValue2 global previousUnchangedValue1 #First item in list if not ...


2

Based on where you are, use the field calculator. Select Python as the parser and then in the formula block, put: ','.join([Polys].split(',').sort()) Note that if you are using a personal or file geodatabase, you would need to put !Polys!. However, there are simpler alternatives if you wish to do the whole thing from the beginning again.


0

These are great string functions that I didn't know about. Just for good measure, I'll add a method I've used in the past: expression: zeros(!photoStr!) code block: def zeros(value): desired_len = 5 return (desired_len-len(value))*"0"+value


7

In addition to @DWynne's answer, I'll add that there is a built-in python function that does exactly this (located a little bit further down the page on DWynne's link). It's called zfill and according to the documentation: Returns the numeric string left filled with zeros in a string of length width. A sign prefix is handled correctly. The original ...


4

Actually, you could do this without a function. Try using str.rjust. An expression of !photoStr!.rjust(5, '0') will return a string with padded 0's to the left of your number string. '1' becomes '00001' '12' becomes '00012' '123' becomes '00123' '1234' becomes '01234'


3

Using the Python parser in the field calculator: Pre-logic script code: def convert(x): a = x.split(":") return a[0] + ":\Engineering" + a[1] convert(!text_field!) You can also use an UpdateCursor to do this import arcpy fc = r'path\to\your\fc' with arcpy.da.UpdateCursor(fc, "your_field") as cursor: for row in cursor: if row[0] ...


0

Arcgis solution: Open the attribute table. Right click on the header of the field column you want to modify. Choose Field Calculator. In the list of fields on the left, double-click on the filed you want to copy over, so that the field name appears in the box below. Press OK. If you need to make a new field/column to copy into, choose Add Field from the ...


1

I don't have experience coding but i modified one of the esri resources examples and it worked for me... # Name: CalculateField_COORDINATES.py # Description: Use CalculateField to calculate start and end points of a line # Import system modules import arcpy try: # Set environment settings arcpy.env.workspace = "D:\SIG_MPIOS\MPIOS14.mdb" # Set local ...


0

My answer to a similar question works for this one also. The Hydrologic Soil group code is in the component table and is easily queried and joining to the spatial. the query can be completed in the MS Access database provided with a ssurgo download or queried from the Soil Data Access site. MUKEY is your join column. Use a dominant component sql on the ...


0

There appears to be a problem with either earlier versions of Arc (I use 10.0) or some installations of Arc where anytime your Python script sees a <Null>, <Null> is returned. I am aware of the if myfield is None approach, but this did not work for me, or a commenter here, or several other users with similar problems in gis.stackexchange. No ...


2

You can use the field calculator to update the column removing unwanted chars: replace( "mycolumn", '#F','') You can also use this directly in an label expression, if you do not want to delete the char from the record. You have a long list of string function for you convenience.


1

In the advanced field calculation be sure to select python as the syntax: The code (to copy and paste): def FormatThis(number): AsString = str(int(number)) # just the whole numbers Dec = number-int(number) # extract the decimals G3 = [AsString[::-1][i:i+3][::-1] for i in range(0, len(AsString), 3)][::-1] return ','.join(G3) + ...


1

Assuming that you are looking for positive numbers, as it looks like you are extracting address elements. Run a field calculate on Name_Num field. Put this in the pre-logic Script Code (make sure Parser is Python): def extract_from_number_to_end(input_string): output = input_string # return input if no number found for char in input_string: ...


0

Alright, due to my lack of not paying enough attention I managed to solved the problem. I wasn't returning the value, only making assignments.


1

Here's a way to implement Chris W's answer without the need for ArcGIS. (It does require gdal/ogr, free and open source.) When gdal/ogr is installed, run the code below from a command terminal (mac/linux/windows). To get the list of fields Chris mentions: ogr2ogr -f csv fields.csv union.shp -where "0=1" Search + replace that text to create the math ...


0

First create a field on your table to summarize the values in. Then take a look at Calculate Field. In the below, update the Expression parameter to include all the field names you want to sum per row.


1

Field calculator (Python) def TotalTHem(fid, layerName,wildcard): mxd = arcpy.mapping.MapDocument("CURRENT") lr=arcpy.mapping.ListLayers(mxd, layerName )[0] destFields=arcpy.ListFields(lr) dNames=[row.name.upper() for row in destFields] list2add=[] for fname in dNames: if wildcard in fname:list2add.append(fname) with ...


2

you could use some Python scripting, I assume that the field "resultfield" exists and that you can identify the fields to sum based on one common string (i.e. "score") : import arcpy allfields = arcpy.ListFields("featureclassname") scorefields = [x.name for x in allfields if x.name.find("score")>-1] with arcpy.da.UpdateCursor("featureclassname", ...


5

Export your table to a text format. Grab the header row and paste it to a new file. Delete irrelevant column headings (could also turn them off prior to export to avoid this step), and then use find/replace functions to change the delimiting characters to proper syntax for the formula (ie quotes around field names, a plus sign in the middle). Copy and paste ...


3

The ultimate result of this calculation is a boolean typed value (i.e., True or False). ArcMap does not have a boolean type built in, but you can simulate it in one of two ways: If you are using a geodatabase, best practice would be to store the result of this calculation using an Attribute Domain that you define to your needs. If that's overkill, you ...


0

update_field = 'Map_Feature_ID' expression = '"WP_{}".format(!OBJECTID!)' arcpy.CalculateField_management(feature_class, update_field, expression, 'PYTHON') http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000004m000000


3

Seems you're correct in thinking there is a problem with the 'calculate' variable. i believe you would want something like arcpy.CalculateField_management(layerforNewField, newfieldname, '"!{}!"'.format(oldfield), "PYTHON_9.3") otherwise, by setting calculate = '!oldfield!' the code is trying to insert values from the column 'oldfield', which i'm ...


1

Use the Spatial Join tool with the One to Many option and a Search Radius value of 1000 (assuming your geometry units are already in feet). Your Practice Sales1 will be the Target features and the Practice Stops will be the Join Features. This will duplicate the Practice Sales1 features to match the number of Practice Stops points within 1000 feet of each ...


4

If done in Python: Expression parameter: getSinuosity(!shape!) Codeblock parameter: import math def getSinuosity(shape): length = shape.length d = math.sqrt((shape.firstPoint.X - shape.lastPoint.X) ** 2 + (shape.firstPoint.Y - shape.lastPoint.Y) ** 2) return d / length Make sure to use an expression type of PYTHON_9.3. ...



Top 50 recent answers are included