Questions tagged [python-parser]

For questions about ArcGIS Python Parser for labelling expressions and field calculations

Filter by
Sorted by
Tagged with
3
votes
1answer
634 views

Calculating field with hour from date time field with ArcPy?

This expression works in the field calculator to give me the hour from the datetime field called dtrepor arcpy.time.ParseDateTimeString(!dtrepor!).strftime('%H') But how do I call it in python? I ...
2
votes
1answer
398 views

Python labeling Expression how to change font size?

I have a labeling expression using two attributes I want the first one to be size 14 and the second one to be on a new line and be size 8. This was my attempt so far: "<FNT name='Arial' size='14'&...
1
vote
1answer
192 views

Replacing last word in string using ArcGIS field calculator?

In this table I need to change the last word from field !name! using the text from field !abbreviation! I was trying to use Python parser to get the text from !name! field without last word and ...
1
vote
1answer
232 views

Syntax Error Label Expression Debug

I'm attempting to debug a code for a conditional label expression. The code is based on one i have previously used and did not have any issues. The python code is as follows. def FindLabel ( [TF], [...
1
vote
2answers
237 views

Field Calculator Parsing error SyntaxError: invalid syntax (line 2)

I'm writing a conditional in the Field Calculator and it's giving me an error of syntax in line 2. Can someone see it? The Code Block is this: def ZFactor(LAT_CENTR) : if (10.000 < math.fabs(...
3
votes
1answer
653 views

Replacing multiple characters at once

I have a problem with replacing in field calculator. For some reason my Python parser is not working. So I'm going to use VB and having tonns of this Replace([field],"x","y") Replace([field],"z","a")...
3
votes
1answer
277 views

arcpy CalculateFieldManagement - single quotes in expression

I'm using the following to write a value to a field. arcpy.CalculateField_management (newPha, "PHACODE", """'{}'""".format(name), "PYTHON_9.3") The only problem is that the string I'm attempting to ...
4
votes
1answer
939 views

Automatically calculate field with every new entry?

I have a point feature class that has a "Direction" field (north, northwest, west, etc; linked to a domain with 16 options). I then have a numeric field "Rotation" that controls the rotation of the ...
1
vote
2answers
10k views

Remove last 5 characters with Field Calculator in ArcGIS Desktop? [duplicate]

I wonder how to delete a word (or the last 5 characters) using the field calculator in ArcGIS 10.2. I have a column such as: Paris City; London City; Berlin City I need to remove "City", to be left ...
0
votes
1answer
102 views

indentation problem or function problem?

I am trying to create in Field Calculator (arcmap) a function to assing a numeric value in a column (heighs) based on a text value from another column(building). 'Pre Logic' input box def a(heighs, ...
2
votes
1answer
96 views

Populating new field based on existing string field using ArcGIS Field Calculator?

My programming is really rusty at this point, and I am trying to do a simple calculation using a Codeblock, either VB or Python is fine. I have tried about 50 different variations on same theme, and ...
1
vote
1answer
335 views

Run field calculator script in Python window

I have a script that runs perfectly in the "Field Calculator." The codeblock looks like this: def timeday(time, am, diur, pm, noc): if(time >=am and time < diur): return "crep_am" ...
0
votes
1answer
39 views

Calculating Time of Day

I want to calculate a text field call "TIME_DAY," depending of whether or not the time falls within of four time periods it should return one of four values. My script should work, but it doesn't. ...
1
vote
2answers
831 views

Create 'Season' column from 'Date'

I'm somewhat familiar with ArcGIS Desktop, but have no experience in Python. I have about 100 shapefiles which have an attribute table containing a date, but I need a column which contains a ...
1
vote
2answers
77 views

Adding new text field using if/then python statement?

I was hoping someone could help me with an issue I've been having while trying to aggregate data into a new column in an attribute table in arcgis. This is part of a model built using model builder. I ...
-1
votes
1answer
73 views

Address Prefix Strip Using Python

I have a field of data with a lot of prefixes that are difficult to remove. They involve two letters and up to three numbers that are not separated from the Street Number with a space. For instance, ...
1
vote
1answer
80 views

ArcGIS field calculator, shorten text

I am new on Python and using Python within ArcGIS and a bit stuck hoping someone could point me in the right direction. I want to remove the 6 last characters if the field is longer than 6 ...
2
votes
1answer
184 views

Using field calculator to auto-increment within a range?

I am trying to use field calculator to number points between -700 and 700. I have used this code block: rec=0 def autoIncrement(): global rec pStart = 700 pInterval = -1 if (rec == 0): ...
1
vote
0answers
60 views

Select points by continuous numbers

I have GPS points driven over the same road back and forth then clipped to a section of that road. My points are overlapping and need to identify the points going one way or one run down the road in ...
3
votes
1answer
296 views

Trying to shorten length of a field using field calculator

I currently have a field that has text for a hyperlink to a photo that I am trying to shorten. I only need the name of the file at the end but the length of the name varies by a few characters. The ...
2
votes
1answer
466 views

Specifying Font Size/Style in Label Expression?

I want to create a label expression with two lines of text, this should be simple but I'm having a lot of trouble. Basically, I need the top line to be 10 pt font, and the next line to be 8pt font ...
2
votes
1answer
332 views

Calculating mean value of 280 fields with Field Calculator from attribute table of shapefile?

I have to average 280 fields in 1 field. Each field has 300 rows. That is my problem. I think I need a python script. I don't want to create a raster for each field and then use the raster ...
0
votes
1answer
211 views

Calculate field python script returning NULL values

I have a script that I am using to create and calculate a new field based on the features spatial location. Basically, I have a geodatabase that contains parcels by county in florida, and I am trying ...
2
votes
1answer
523 views

Python script to iterate through geodatabase and assign field value based on spatial location

I have two types of spatial data. One is a geodatabase of parcel data by county in Florida, and the other is a shapefile containing wind_zones through out Florida (used for enforcing certain building ...
1
vote
1answer
123 views

Parsing Address in Field Calculator

I'm trying to parse up the addresses in a table using the above code. It runs but only produces NULL. I have run out of ideas
1
vote
0answers
46 views

Create sequential numbers based on field value using Python in the Field Calculator [duplicate]

I'm trying to modify the autoIncrement() python script to auto number based on another field. For example, I need the autoincrement to restart when the field "STD_ID" changes value. This is my attempt ...
5
votes
1answer
161 views

Stacked Label using If/Else in a Label Expression

I have a large set of data with lab results that I'm looking to label in ArcMap. I'm trying to build a label expression that needs to produce a label that essentially needs to look like this: B=5 T=...
1
vote
3answers
242 views

If/Then Field Calculator Return Calculations

After collecting GPS location for road culverts I would like to calculate the $ values for each culvert based on their diameter and length in ArcMap. Existing number fields in the attribute table are ...
0
votes
1answer
149 views

How to translate VBScript to Python-parser in Field Calculator

How do I translate the following VBScript code in Field Calculator to Python using the Python-parser? Function FindLabel ( [MHUNIT], [BLDG_NUM] ) If Not IsNull( [MHUNIT] ) Then FindLabel = [MHUNIT]...
2
votes
1answer
759 views

What is the Python expression for calculating Lat/Long in Decimal Degrees in ArcGIS?

I'm calculating 4 double fields for a polygon feature class (exploded, single-part features): SquareFeet, Acreage, Lat, and Long I found the correct python expressions to calculate SquareFeet & ...
2
votes
1answer
420 views

Calculating row in field based off another row in same field using ArcGIS Field Calculator?

An attributes table has 3 fields: ID, Field1, and Field2 and looks something like this: ID | Field1 | Field2 1. | text......| 10 2. | text......| NULL 3. | text2....| NULL 4. | text2....| ...
1
vote
1answer
74 views

Label expression problem?

I am mapping the municipalities 911 numbers on our road network and built a simple python expression to find the lowest value between 2 fields. Then it shows that value on the line followed by an ...
-2
votes
2answers
1k views

vb script for carriage return in label string over 50 character long

IN ArcGIS, what is the vbscript in the label expression box to build a label which has the outcome that if the string is over 50 characters long then the label should be formatted over 2 lines.
0
votes
1answer
504 views

Parameter variable in expression for Calculate Field Python Script?

Here is what I have import arcpy inputFC = arcpy.GetParameterAsText (0) #Feature Class inputField = arcpy.GetParameterAsText (1) #Field to manipulate inputChar = arcpy....
1
vote
1answer
259 views

Field Calculator Odd IF Statement?

I am working on a street addressing project. I want to add a number to every odd number. Example if [field] is odd [field]+=1. How can I do this in ArcMap using the field calculator. I used to work ...
2
votes
1answer
380 views

Using Field Calculator to assign consecutive letters for each feature?

I have a feature class generated in ModelBuilder using a transect script that contains multiple transects. Before moving on to further build the survey I would like to assign ID's to each feature in ...
1
vote
2answers
476 views

Using Python Function in Field Calculator to find numbers

Disclaimer, I am terrible at writing my own functions especially in the field calculator. I have an address field (Address) with records that are missing street numbers. I would like to find these ...
0
votes
1answer
83 views

Filling Field2 Based on Values in Field 1 using Python Parser of ArcGIS Field Calculator?

I have been trying to rework attributes in a polygon shapefile and think I have figured out how to ask in a sensible manor. I need to fill column Field2 with a 1 IF the value in column Field1 is ...
0
votes
1answer
397 views

Field Calculator GUID remove curly brackets from GUID string

I'm attempting to Field Calculate the GlobalID field into a text-equivalent version of it, named GlobalID_T. This new text field will have the exact values for records calculated into it, except for ...
-1
votes
2answers
2k views

If Then Else Statement in Field Calculator using Python - ArcGIS 10.1

I am trying to populate a field [Hazard] based on the values in two other fields [Depth2D] and [Speed2D]. I have managed to write a code block in VB script that works but I really want to figure out ...
2
votes
2answers
390 views

Fixing address errors using Python Parser of ArcGIS Field Calculator?

I am working on a task that will calculate a field to fix errors stemming from the Standardize Addresses tool and human error with the input data. The script is below. I'm getting Error 000989 "...
1
vote
2answers
9k views

TypeError: coercing to Unicode: need string or buffer, NoneType found in ArcGIS labeling?

I have found out how to label using multiple attributes via an expression and python. What I have is as follows: [ID] + '\n' + [Notes] An ID example is "MH108" and a notes example is "buried, no ...
1
vote
0answers
55 views

Creating sequential numbers in sorted field using ArcGIS Field Calculator? [duplicate]

I have a sorted field that I would like to populate with sequential numbers. They are not in order of OID. Is there any way to do this?
1
vote
1answer
92 views

Using an IF statement in Field Calculator

I'm trying to use an if statement in the field calculator: This is what the code looks like in Python: a= 2 FacilityID= !FACILITYID! if a%2==0: MH_ID_Calc=FacilityID[0:6] else: MH_ID_Calc=...
2
votes
1answer
122 views

Syntax for evaluating strings with wildcards

I'm trying to do a Field Calculation in ArcGIS 10.3 (Python 2.7) that uses the Codeblock (Pre-Logic Script Code) to evaluate the attributes in a different field to inform the calculation). Here's an ...
2
votes
1answer
45 views

Combining values in shapefile using ArcMap?

I have a shapefile with 10 different values (geological ages) which I want to combine into four values (into broader age categories). Is there a tool which I can use to selectively combine values in ...
3
votes
1answer
442 views

Removing white space from field using field calculator

I am trying to remove extra spaces from values in a field programatically using a python script. This is the script I'm using: field1 = "FULLST_NAME" calc1 = "s.join(!" + field1 + "!.split())" s = "\'...
0
votes
0answers
21 views

Ensuring expression always yields same number of digits in ArcGIS Desktop? [duplicate]

I am using ArcGIS Desktop 10.5 and trying to create a unique ID with the following expression: "city_id"='2'&'002'&"popn_rank" The expected result would look like 20020001, 20020002, etc. ...
1
vote
1answer
264 views

Converting label expression from VBScript to Python in ArcGIS Desktop?

I have a feature class with label expression in VB script. I do not have the skill to convert a VB script to a python script. Here is the VBScript:- Function FindLabel ( [DESCRIPTION] ) if (left(...
-2
votes
2answers
370 views

Writing python script to group and sum records from each group? [closed]

I am doing hydrology analysis in ArcMap 10.2 and have a drainage area feature class containing hundreds of records. Each record is assigned a drainage area name and acreage amount. How do I sum all ...