New answers tagged

1

If you select "table_1" for the Update existing field option, try using this expression: if( "table_2" = 'test', 'y', "table_1") Basically, you're using an IF THEN ELSE statement.


2

You can try something like this (see also @radouxju's comment): import arcpy pt = r"C:\AIS\Density_Grid_test.gdb\PivotTable" flist = arcpy.ListFields(pt, "*ShipTypeGroup*") for f in flist: arcpy.AddField_management(pt, f.name.replace("ShipTypeGroup","Ave_STG"),"DOUBLE") newflist = arcpy.ListFields(pt, "*Ave_STG*") for nf in newflist: ...


2

Why not just do the following instead of doing it under a nested loop: import arcpy pt = r"C:\AIS\Density_Grid_test.gdb\PivotTable" arcpy.AddField_management(pt, "Ave_STG", "DOUBLE") arcpy.CalculateField_management(pt, "Ave_STG", "!ShipTypeGroup! / 12", "PYTHON_9.3") or you could try doing it with an UpdateCursor import arcpy pt = ...


3

Expanding on my previous comment... The problem with your statement is that the returned value from string.split is a list and the field you're trying to calculate into is a string, these types are incompatible so the parser ignores the value and sets the string to null. To turn a list into a string you need to use join: >>> a = "Johnny be good" ...


6

You are almost there. What you are trying to do is: Codeblock: def calc_speed(field_value): if field_value == 'S1100': return 65 if field_value == 'S1200': return 45 Speed field Speed = calc_speed(!MTFCC!) You have to evaluate the value of MTFCC field and then make decision based on that. Imho a more elegant solution is to use a Python ...


2

Reading through your steps it sounds correct to me, although I would question Was your original dataset in meters so that your output from your first step, which you say is in meters, is actually in the same units. If the units are meters, then I think it's safe to assume the area will be in square meters. Do your census tracts match your areas so that ...


0

Like others have suggested I think field calculator is the way to go on this one. I would just create a new field called TRS using a similar expression to the one you created the labels with.


0

Just modify what you have for your labeling a little bit, for calculating it should be: mid( [RTS] ,3,2) + mid( [RTS] ,1,2) + mid( [RTS] ,5,2)


0

There are many ways to achieve this. For example using the field-calculator. Create your three new Fields (e.g. using Toolbox) FieldCalculator (e.g. Python syntax) Field Township: = ['RTS'][2:3] Field Range: = ['RTS'][0:1] Field Section: = ['RTS'][4:5] Alternatively the following arcpy-code should work: cursor = arcpy.UpdateCursor(myTable) for ...


1

Esri's Attribute Assistant has a tool called Generate ID which will automatically generate a new ID whenever a new feature is created. These IDs can be created per feature class to generate different IDs for different feature classes, and can be created based on a specific template if required.


0

Thanks Everyone for your help! This may not be the most elegant of fixes, but it did work: I found that the %Value% had to have Quotes and I used a try/except sequence to get around the possible lack of a space in some of the values.


4

You want to pass your field name f.name as the name of the field, and then add that to your expression as well. In the field calculator you need to surround your field name with exclamation marks e.g. !myfield! I think something like this should work: import arcpy shp = r"m\team.shp" fields = arcpy.ListFields(shp, "*qty") for f in fields: print f.name ...


1

You do not need the field calculator for replace at all. You can just use the Find & Replace tool which is accessed from the attribute-table which has the search/replace function the same way as in Excel, for example. It also works for all columns simultaneously or can be set to search for whole values etc.


2

You don't necessarily have to define a function for this one. Try this: str(!PlaceName!).replace(' ', '') The "not defined" error is related to the lack of quotes around the NoSpace1. This could be from the % on either side of the Value. Your expression should be ReplaceName(!Placename!)


1

I'm assuming that instead of the second "River" value (under desired ID) you mean "Hill". In the Field Calculator window (for your new field), select the Python parser (in the parser box in the top left of the window), and enter the following into the expression: {"Street": 01, "River": 01, "Mountain": 02, "Hill":02}[!names!] What this does is create a ...


2

Add your new short integer field to your attribute table, right click the field name, and click "Field Calculator". At the top of the Field Calculator window, in the 'Parser' box, check the Python box/bubble. Below the 'Fields' list, check the "Show Codeblock" and enter the following code in the codeblock: def Classify(a): if a == "summer": return 1 ...


1

def replaceZeroVal(input, replaceWith): if input <1: return replaceWith else: return input replaceZeroVal(!Bot_Lat!, !Surf_Lat!) Okay, the issue is in the bottom needs to have the exclamation points to say it is calling data specifically from the data table. I found this through GeoNet.


1

You have to use the "Show Codeblock" above where you have your function. Put the function in the codeblock, then call on it in the window where it is now. Also, you have to be careful about the indentation to make sure it is consistent; use 4 spaces at a time for indenting. It looks like you're trying to replace the value if the borehole value is 0... If ...


3

You have passed wrong parameter to the NumValue function. It should be: NumValue(!PCT_B100P!)


2

If the field is numeric, Python expression: !zip![:4] will fail. It is easier to use vb script option: left([zip],5) This will populate output field of numeric and text type.


0

Just do a dissolve on Trip, then in the Statistics Field(s) just add the fields and the statistic type you want to be added to the attribute table. http://pro.arcgis.com/en/pro-app/tool-reference/data-management/dissolve.htm This has the added benefit of keeping the geometries for your data.


0

You can use the summarize tool on the field Trip, and in the summary statistics, select the relevant fields to calculate statistics for, like ave, min, max etc. The result is a table with a row for each trip, and a column for each statistic.


0

Use the Summary Statistics tool: This is the output:


4

Use the string indices. Instead of creating a whole function, just do something like: !ZIP![:5] --> basically grab everything from 0 index up to but not including the 5th index. So it only grabs the indices 0,1,2,3,4. Check out this tutorial for more information. If there are more than 5 it will just grab the first 5. If there are 5 exact, it will grab ...


8

If you want to use the Calculate Field tool (instead of an Update Cursor), what you're assigning to val needs to be an unevaluated python expression. That is, it needs to be identical to the string you would type into the Calculate Field tool if you were using the GUI version. What you're currently assigning to val is "!FEDIRP! !FENAME! !FETYPE!". Any of ...


1

I figured it out, I just used Calculate XY coordinates into my model and this worked.


2

There is a Toolbox Scripting tool called Add Geometry Attributes that you can use to create and populate a new attribute with areas and lengths.


2

The solution turned out to be making sure you have the table as a table view, and adding the name of the layer in front of the field name. These are shown in the example here: How to Calculate Field in joined table using ArcPy?


0

Do you need to have them in two separate functions? You could combine them into one segment: if 'TownshipNum' not in fieldlist: arcpy.AddField_management(Section, "TownshipNum", "TEXT", "", "", "5", "TownshipNum", "NULLABLE","NON_REQUIRED") arcpy.CalculateField_management(Section, "TownshipNum", twnspexp , "PYTHON") arcpy.AddMessage("\n" + ...


3

You can look up domain values from the geodatabase and query the fields to find the names of the domain they reference. By limiting this lookup to just the field you're interested in (ST_DESIG) you can pull out all the coded domain values into a dictionary. Once you have this dictionary you can make your arcpy.CalulateField_management code block ...


3

If I'm wrong, I'll give an upvote to whoever corrects me, but I don't think you can do that. Coded-value domains aren't usually very long so here's what I suggest. Since you are using Python, create a dictionary for your coded-value domain. dict = {'0': 'None', '1': 'Divided Major Highway yada yada', '2': 'Major Highway - Class II'}; Then your if ...


1

Your def addfields section has quite a few indenting errors. Try cleaning that up and see if that fixes it. def addfields(): if arcpy.Exists(Section): fieldlist = [str(f.name) for f in arcpy.ListFields(Section)] if 'TownshipNum' not in fieldlist: arcpy.AddField_management(Section, "TownshipNum", "TEXT", "", "", "5", ...


1

You can do this with a string with the following VBA in the field calculator: Left([FIELD_NAME], InStr(1,[FIELD_NAME], ".") - 1) That will remove the decimal and everything after. If you want some number of digits after the decimal, replace the -1 with + like so: Left([FIELD_NAME], InStr(1,[FIELD_NAME], ".") + 2) will give you 2 decimal places. ...


1

If you're trying to get rid of the decimal and everything to the right of it, you should be able to do something like this: Left([field],InStr([field],".")-1)


1

Create a new field that is the same data type as your original shape lengths field (probably a double). When creating the new field, make sure it has the following parameters: A 'Precision' that is something high, like 20. Precision is the maximum number of digits allowed. So essentially you want to make sure the max is above the total number of digits ...


1

The argument of the split function is expecting a string value surrounded by "" or ''. You have three double quotes. Try surrounding the string with single quotes: !other_tags!.split('"int_name"=>"')[1] To remove the last bit of text, run this statement after running the one noted above: !other_tags!.split(',')[0].replace('"','')


3

The first thing that I would check is whether your feature class has a field called FULLNAME. The error message that you are receiving suggests that it does not.


0

I like Aaron's approach but depending on the size of your dataset and how many different FIPS values you have, this could be slow. That method iterates over all entries in the FC. I'd say combine the two suggestions with an OR where clause: with arcpy.da.UpdateCursor(infc, fields_in_cursor, "FIPS = '06307' OR FIPS = '06308'") ) ...... Then apply Aaron's ...


3

If you start with a double and want to end with a double, why bother switching to string and back again? Move your SYS_NO over two places by multiplying by 100, then add the IN_ETNO value. (!SYS_NO! * 100) + !IN_ETNO! Note that if you're using shapefiles, you may not be able to store the final digit, while GDB feature classes will.


1

The reason you're getting the message SYS_NO is not defined is because you have already set x = !SYS_NO! by passing CON_IN = Concat( !SYS_NO! , !IN_ETNO! ). In def Concat(x,y): you've specified that the first parameter is x and the second is y, so passing !SYS_NO! as your first parameter means that you're setting x = !SYS_NO! there. def Concat(x,y): ...


2

This can be simplified quite a bit with string.format(), which can be configured to zero-pad your values. You don't need a code block at all, actually: "{f1}{f2:02d}".format(f1=!CON_IN!,f2=!ET_NO!) >>> "{f1}{f2:02d}".format(f1=21614001875,f2=9) '2161400187509' >>> "{f1}{f2:02d}".format(f1=21614001875,f2=28) '2161400187528'


1

Your error is likely due to the fact that you're trying to concatenate numeric values with a string. You'll need to convert the other values before trying to concatenate with a '0'. Having said that, it seems like you're simply trying to pad the 'y' value with a single '0'. If this is correct, then you can actually use the zfill function to pad the final ...


4

Strings in Python are immutable, so you could use the following (SO reference): !SURVSTR_ID![:3] + "_" + !SURVSTR_ID![3:] >>> "ABC11111"[:3] + "_" + "ABC11111"[3:] 'ABC_11111' Similar results with VB script (probably a cleaner way): Left([SURVSTR_ID], 3) & "_" & Mid([SURVSTR_ID],4)



Top 50 recent answers are included