Tag Info

New answers tagged

0

I would recommend using the format method of the string class to perform this type of operation. Here is a link to a similar question: Concatenating string and numeric data in ArcGIS As a general rule you should avoid using concatenation in favour of the format method. You will have cleaner code and more control over the final output string.


0

in Arcmap they given this example http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000004s000000 Concatenate two fields with a space separator !SUB_REGION! + " " + !STATE_ABBR! in python


8

This will depend on what software you're using. Since you mentioned Field Calculator in your question, you are going to be using a programming language parser to convert values. For Python (ArcMap, QGIS), you can use python's built in conversion functions. This page explains it fairly well and shows examples. If you're using ArcMap and VBScript, there ...


4

Here is the solution to your question in ArcMap 10.x. Your example for this will be: "abc" & [integer] within the expression box. If you would like to have a space between your expression will be : "abc" & " " & [integer] (Note that there is a space between the middle parentheses).


0

The field calc function you are after is concat() e.g. concat( 'abc', 123)


2

QGIS has created a function called format_number to address this. You simply do format_number(12345,0) to get 12,345.


3

In this case, the same thing could be accomplished with !FieldName!.lstrip("0").


5

A bit explanation why the OP's function is not working: f1 = a string list= a list When you are iterating over the list, for each member of list you will get either positive or negative response. So your list has nine members; you will get nine responses(+ and -). Then what the calc function will return, whole nine responses or one? Of-course python ...


3

You could just check if your field value is in the remove list: def remove_zero(field): remove_list = ['01ST', '02ND', '03RD', '04TH', '05TH', '06TH', '07TH', '08TH', '09TH'] if field in remove_list: field = field.replace('0','') return field else: return field Then you'll want to do: remove_zero(!FIELDNAME!)


3

You can use function editor tab in the field calculator and make your azimuth function like this: from qgis.core import * from qgis.gui import * @qgsfunction(args="auto", group='Custom') def azimuth(x1,y1,x2,y2,feature,parent): p1 = QgsPoint(x1,y1) p2 = QgsPoint(x2,y2) a = p1.azimuth(p2) if a < 0: a += 360 return a Once ...


3

Use the Right Function Right( [textField], n ) (where n is the number of characters) eg: Right(“abcdefg”, 3) = “efg” This is pretty handy for learning how to use the field calculator http://www.esri.com/news/arcuser/0405/files/fieldcalc_1.pdf


0

I was able to figure it out with a work around. I added the Lat/Long Fields and then us Convert Coordinate Notation. That generated a new feature class with two new fields: DDLat and DDLon. That got me what I needed even though I had to add a couple additional steps. The output was 076.###W, 37.####N as opposed to what I wanted which was (-76.###, 37.####) ...


1

I was experiencing a similar issue with my iterating model. I was calculating a field in a series of tables to equal the names of the tables. I was left with blank fields. Since the data type is string, the expression needed to include quotes around the substituted variable, such as '%Name%' as opposed to %Name%. With this change, the model worked as ...


0

It used to be that AutoCAD couldn't handle stacked text. We always just had separate lines of text in CAD if they were multiple lines. I imagine it can handle it better now, but I still can't help but think there are some conversion issues there. I would do single line labels in ArcGIS and see if that exports to AutoCAD better.


0

I think your "long winded" way of using the Field Calculator to concatenate the field values into a new field may be your best bet. If you are comfortable with cursors then using arcpy.da.UpdateCursor() to concatenate the field values into a new field is an alternative but the principle is the same. I would not expect an out-of-the-box tool for something ...


4

As stated in the tool documentation for Calculate Field: Python expressions can use the geometry area and length properties with an areal or linear unit to convert the value to a different unit of measure (for example, !shape.length@kilometers!) These expressions are not usable with points or individual coordinates. Fortunately, you can use other ...


1

Expression type needs to be PYTHON_9.3 This code worked for me: from arcpy import * fc = r"C:\test\test.gdb\test" fld = "testfld" shapeFldName = Describe (fc).shapeFieldName CalculateField_management (fc, fld, "!{}!.firstPoint.Z".format (shapeFldName), "PYTHON_9.3") Happy ...


2

You can't use punctuation marks in variable names in python. Your function should probably read more like this: def calc(LONG_x): if LONG_x >= -113.90550 and LONG_x <= -113.90559: return "05" else: return "0" You can then pass in !LONG_x! as an argument to the function. eg. result = calc(!LONG_x!)


3

so if it helps - i think it would look something like - def calc(f, fn, f1, f1n): #note colon here # everything within function is indented f = str(f) f1 = str(f1) f = f.replace(" ", "") fn = fn.replace(" ", "") f1 = f1.replace(" ", "") f1n = f1n.replace(" ", "") if f+fn == f1+f1n: # each return of if or elif ...


0

Spatial joins are available in the field calculator after installing the refFunctions plugin. geomwithin(targetLayer,targetField)


2

Try this: arcpy.CalculateField_management(var_sel, "VR_Rate", '!' + VRField_Calc + '! + 2', "PYTHON_9.3") To search for a specific field before calculating: findField = 'some_field_name' for field in VRField: if field.name == findField: arcpy.CalculateField_management(var_sel, "VR_Rate", '!' + field.name + '! + 2', "PYTHON_9.3")


3

It's possible without using a python function, with a little bit of hacks: minute( age( todatetime('2000-01-01 10:18:00'), todatetime(2000-01-01 10:16:30') ) ) will return "1.5". To break it down, "age" returns the difference between two datetimes as an interval type. This needs to be wrapped in the "minute" function to extract the length of this ...


4

If you're using 2.8 or later, you can use the Python function builder. This code will do the calculation. I don't think you need to use Qt objects for this. from qgis.core import * from qgis.gui import * from datetime import datetime import time @qgsfunction(args=2, group='Python') def timedifference(values,feature,parent): ''' call this function ...


1

Your code logic seems fine, you just have to change the bottom script to: Type = change(Value) You are getting a "N/A" as a value on all of your columns because you are running it on the [Type] column of data where none of the values are 1-5 as you've expected, instead of running that function on the [Value] column, where those numbers(i'm assuming) are.


3

Recap: Your problem was just that you were passing the wrong field to the function. Think about it this way: Field calculator produces a new value for each row a given field (the field shown just above the expression where it says "Type =") based on the expression. In the expression, you are able to reference other fields by using !Field_name!. By using ...


4

If you plan to do this often you might be better off doing this as a function so you can reuse it. Open the Field Calculator Click on the Show Codeblock check box Enter the code block included below You can click on the Save button to save the code and load it later on with the Load button Here is a screen capture as an example. It's the same result ...


4

This should just work as a normal string in check def myCal(reportnumber, spatialjoin): if reportnumber in spatialjoin: return 1 else: return 0 or even one like: def myCal(reportnumber, spatialjoin): return 1 if reportnumber in spatialjoin else 0


1

i haven't tested it, but you may not need the wildcards at all - if you convert the value in the spatial join field to a list - something like def myCal(reportnumber,spatialjoin): #spatialjoin = spatialjoin.split(';') if reportnumber in spatialjoin: return(1) else: return(0) heck, may not even need to convert spatial join to a ...


0

Hi eplanner.You don't need an expression in the Field Calculate codeblock. If the PhotoNumber matches the OID value for every record in your table, just Field Calculate: "Photo_" + str(!OID!).rjust(4, "0") + ".jpg" using Python syntax This is by far the simplest solution.


1

The code below demonstrates how to get this to work using code very similar to that in the question, but I recommend also reviewing the detailed explanation that follows in order to understand why it works: import arcpy dmyString = "01.07.2015" d,m,Y = dmyString.split(".") dmyDate = datetime.datetime(int(Y),int(m),int(d)) epoch = datetime.datetime(1899, ...


0

For symmetry, here is an Update Cursor approach that uses the zfill method to pad 0's. import arcpy fc = r'C:\path\to\your\fgdb.gdb\fc' with arcpy.da.UpdateCursor(fc, ["OID@", "Name"]) as cursor: for row in cursor: row[1] = ''.join(['PHOTO_', str(row[0]).zfill(4), '.jpg']) cursor.updateRow(row)


1

Based on the screenshot you've provided, it looks like you can do this really easily by using the OID field. Those integers match the photo numbers. code block: def makeName(oid): n = 4 - len(str(oid)) return "PHOTO_{0}{1}.jpg".format(n*"0",str(oid)) expression: makeName(!OID!) Test this on a new string field to make sure it works, because it ...


3

open CalculateField tool for 'Field Name' parameter specify: DI for 'Expression' parameter specify: x(!Max_GRIDCODE!) for 'Code Block' parameter specify the code below def x(v): if v > 2: return 5 elif v > 1.5: return 4 elif v > 1: return 3 elif v > 0.5: return 2 else: return 1


0

You'll need to create a quick python script to auto increment through values. In the field calculator, set the Parser to Python. Click Show Codeblock. In your Pre-Logic Script Code block, use: def UID (): global i try: i += 1 except: i = 1 try: return i except: return str(i) Then in your field calculator, just type: UID () If you need to ...



Top 50 recent answers are included