Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [if-else]

An if-else statement is a programming conditional statement that runs a different set of statements depending on whether an expression is true or false.

2
votes
1answer
30 views

Checking for the existence of a workspace (arcpy), issues with if else statement

I am trying to describe, list, and test for existence of featureclasses in a geodatabase using the following code. import arcpy #Set geoprocessing environments arcpy.env.workspace = "C:"" #Check if ...
1
vote
1answer
42 views

How to write Python if/then statement using information from two fields in field calculator

I am using ArcGIS Desktop 10.6.1. I create a new field of type short integer in the Attribute Table. My new field is named CIPOT and I want to populate it with values from the field CI, but only if ...
2
votes
1answer
64 views

Simplifying variable (if condition) with field calculator in QGIS

I want to simplify the variable ("SIOSE_CODE") which has values like this: A(90MTRfr_05PST_05SDN) A(65PST_35MTRfr) A(70FDCfr_10PST_10MTRfr_05MTR_05SDN) The first number (here 90 resp. 65, resp. 70) ...
1
vote
0answers
41 views

Using IF-Statements in Calculate Field Code Block inside an Iteration

I have created a model in ArcGIS 10.2 that iterates through some feature classes in order to add a field 'Zmin10' (double) and calculate the field value based on a variable (called "Minimum") to which ...
2
votes
3answers
187 views

Writing label expression with ArcMap and If then Statement?

I am having problems with label expression in ArcMap 10.2.1. I want to show two labels per polygon, but only when there are two labels to show. Every polygon has at least one label (Veg_Dominant), ...
2
votes
3answers
99 views

Using IF/ELSE Statement for field calculation in ArcPy?

I would like to calculate the slope value in %, but I don’t want to have any negative values. If there are negative values in the slope field, I would like to multiple them by -1 and if not, multiple ...
2
votes
1answer
43 views

Calculating field on if-else-condition checking input parameters for <Null>?

I want to calculate a field depending on 3 input string parameters. Two of them can contain Null-values. My old VB expression was not able to work with Null-values, so the script stopped. Now I want ...
1
vote
1answer
179 views

conditional statements for raster in R - land surface temperature

Im trying to calculate Land surface temperature estimating with Landsat 8 images, but i got stuck in one place and i cant move on. I m following split window algorithm. I calculated NDVI and I have ...
0
votes
0answers
23 views

Inline Substitution causing empty selection in ArcGIS ModelBuilder?

I created an Inline Substitution for the user to choose from a drop down list consisting of pre-defined values. The problem is, when no value is selected from the list, ModelBuilder will treat it as ...
0
votes
1answer
40 views

Using If Then Else statement against selected records in ArcPy?

I am working on a Python script that will count how many selected features there are and if there are it will make a feature layer from them. If the script runs and finds there are 0 selected records ...
2
votes
1answer
601 views

Writing If-Then statement in ArcGIS Pro field calculator using Python?

I've been using ArcGIS Pro over ArcMap recently because ArcMap is giving me some incorrect summary statistics that I use to populate a data field in a number of feature classes. The problem is that I'...
0
votes
0answers
14 views

assigning numbers to a new field in Arcmap [duplicate]

I want to assign number to each value in a field to a new field. For example in my table there are values like, A, AE, X, AC.. In a new field there should be A=1, AE=2, X=3, AC=4. How can i do this ...
1
vote
1answer
389 views

Field calculator to calculate if field contains certain text

I have a field (WS_Type in the screenshot) that I want to use to calculate values based on the text within the field. The number of occurrences of each WS_Type in the field is not important, but the ...
1
vote
4answers
92 views

Using ArcGIS field calculator with if else to populate field?

ArcMap 10.4.1 on Windows 7. I am trying to fill in some blank rows in a column using field calculator. The field I am trying to fill is: label. If it is empty I want it to be populated with a value ...
1
vote
1answer
190 views

Checking field type in ModelBuilder using if else?

I am creating a model in gis ModelBuilder. I want to check the type of a particular field and if it is long integer than the tools should be different and else (i.e. not a long integer) my tools ...
1
vote
2answers
569 views

Python syntax error with If/elif statement in field calculator when using concatenation

I am unsure what syntax issue I am having with my If/Elif statement. I want to not use a column in my calculation if the value is blank. The end goal is to not have extra spaces before, after and ...
0
votes
1answer
73 views

If else no statistics arcpy

I need to run my code through a lot of rasters that i've downloaded with "Download Raster" function, but some rasters have no information, so my script fails. I wonder if there's any way to use an if/...
0
votes
1answer
64 views

Field Calculator: Simple Python If-then and maths

I want to take all positive values in a field and multiply them by -1000. To do this, I put together the following code block: def myCalc(x): if (x > 0): x*(-1000) return x else: ...
1
vote
1answer
108 views

Creating If Then statement in Field Calculator between 2 values? [closed]

I have a FC with a column for NEAR_ANGLE from the output of the NEAR tool. The angle is displayed in degrees (i.e. -154.67687) which is fine. I am trying to create a column, HEADING, that reads this ...
4
votes
1answer
300 views

Adding fields by user input in ArcPy?

I'm new to Python and I'm trying to create a script which adds fields to a feature class. The provided script is running well, but I want to create an additional parameter, which asks for the required ...
0
votes
2answers
195 views

How to apply if-else condition on two different rasters to produce another rasters?

I want to create a new raster image which meet certain criteria from two underlying images. I created a dummy raster with each pixel having value = 1. Raster values are to be set to 0 if underlying ...
2
votes
0answers
44 views

If else iteration in ModelBuilder? [closed]

I have done this model calculating least cost path I'm using "Test input" as set of points with ID as start and also end points. When least cost path is calculated(Cost path tool), it can't use the ...
2
votes
1answer
76 views

Iteration through shapefile rows is taking too long

I'am using a shapefile with leaflet in r, where i am iterating through each row of that shapefile with a for loop and then i run an if statement on each of the rows as it iterates through the ...
1
vote
1answer
200 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 ...
10
votes
1answer
1k views

QGIS Modeler if/else condition, custom script for Modeler

I want to make a simple if/else function inside my Model and I wanted to know if it's possible or not. I want this thing to do that if an Input for 'Segment Layer' is selected that it doesn't have ...
-1
votes
2answers
1k 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 ...
1
vote
1answer
89 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=...
1
vote
2answers
40 views

Refering in one layer to another layer in ModelBuilder or ArcPy?

I have a problem in using Python in ModelBuilder. My model is going to calculate pace of lateral erosion. I subtracted two polygon layers by Symmetrical Difference and add field "tempo" to new ...
1
vote
0answers
97 views

If/Else Statement in Python ArcGIS Field Calculator [duplicate]

I have a shapefile and want to calculate a field based on another field. The two fields are "DURATION" and "STATUS". I need "STATUS" to display three different outputs based on "DURATION". I want "...
2
votes
1answer
405 views

if-else & arcpy.Exists to check if a raster file exists and then execute code

In a geodatabase, I have several rasters with different suffixes such as (_a, _b, _c). Some gdbs contain all three rasters and others are missing one or more. I'm trying to use if-else statement along ...
1
vote
1answer
384 views

Skip empty rasters in ArcGIS

I'm trying to write some code to skip over empty raster sets when converting rasters to point (the empty sets stop the conversion, leaving me with a half complete model run). I know that I can ...
0
votes
2answers
741 views

If/Else Create File Geodatabase statement ArcPy

I am trying to check to see if a scratch File Geodatabase exist. If it does not, then create one. If it does exist I would like to delete all Feature Classes in the scratch File Geodatabase. In the ...
0
votes
2answers
58 views

Volume using VB Script of the field calculator

I am trying to compute the volume of the area given certain condition. I wrote the following VBScript code, however I am getting error that it has failed to do so. Can anyone look into it and ...
2
votes
1answer
144 views

Script slow because of conditional statements

I have created a Python addin for ArcMap. It has two comboboxes. Combobox1: Search for facility by name. If there is one facility with that name the mxd zooms to the selected extent. Combobox2: ...
0
votes
1answer
345 views

Spatial Reference not working with If-Else

I'm attempting to use a script to check a folder of data sets to see if they match a projection of another data set in a target folder. I need to be able to re project any that don't match the same ...
1
vote
1answer
942 views

Using If Then Else statement in ModelBuilder?

I have a model that adds several fields, two which are manual inputs (County Name and User). I am manipulating several parcel layers (approx 90 counties). In my model, one field takes the state and ...
4
votes
1answer
34k views

Writing conditional (if/then) statements into ArcGIS Field Calculator using Python Parser?

I have gotten stuck on seemingly simple ArcGIS field calculator python expression. I obtained a great answer to a another similar question a few years ago: Using Range in Python expression of ArcGIS ...
-2
votes
3answers
2k views

Using arcpy.da.UpdateCursor and if/else statement?

I have been working on this code for awhile and I can't make it work the way I need it to. The code is suppose to move a feature according to a set distance from types in a designated field. As the ...