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.

Filter by
Sorted by
Tagged with
-1
votes
1answer
45 views

What does if-else code do?

I just started a new job and in one of the procedures I was given for one of my tasks I found this piece of code. It just adds a comment to a field that's already filled up. For instance, field1 might ...
1
vote
2answers
52 views

Filling attribute tables with values from the same attribute table

Just wondering if there's an easy way to fill null values in one column in an attribute table with values in another column of the same attribute table by just writing a query "just the "null values" ...
1
vote
0answers
25 views

Reclassifying string variable in ArcGIS Field Calculator with Python Parser?

I am trying to calculate a roadway pedestrian restriction based on its functional class, using if/else logic in Python. Every time I enter this, it only turns up 'No'. The categories are strings, and ...
0
votes
1answer
67 views

Simple condition on rasters with different extents, R

I have multiple raster objects, with the same resolution but slightly different extents. I have use the following function in order to reclassify them and now their values are between 1-6. What I ...
1
vote
1answer
56 views

Setting up if/then/else for choice of two options or boolean in ArcGIS ModelBuilder?

I'm using ArcGIS Desktop 10.6 and have a model as shown in the image below. I'm calling it option 1. The model exports GIS data to CAD DWG format and is comprised of two submodels, "Setup" and "Export"...
1
vote
1answer
27 views

Enabling model tool even if field already exists using ArcMap ModelBuilder? [duplicate]

I made a quick little tool in ModelBuilder to add specific fields based on a precondition (checked boxes). The issue I'm having is that if any of those fields already exist in the feature I'm trying ...
1
vote
1answer
27 views

Using a wildcard in an elif statement in pyscript…?

I’m trying label up a blank field with ‘yes’ or ‘no’ to the presence of names with either the word ‘Estuary’, ‘Loch’, or ‘Firth’ using * as a wildcard, in Field Calculator. I think I'm getting mixed ...
0
votes
1answer
173 views

ee.Algorithms.If throwing both cases in Earth Engine

I'm trying to work with the ee.Algorithms.If in the sense that: if list = 0(i.e. not containing any points within a buffer) -> do a function() else (buffer is containing points)-> do a function() My ...
2
votes
1answer
38 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
48 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
73 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
49 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
423 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
254 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
66 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
306 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
1answer
48 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
1k 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'...
1
vote
1answer
579 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
113 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
267 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
617 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 ...
6
votes
1answer
3k views

Writing Python code block in field calculator?

I am a novice in Python as well has having minimal experience with ArcMap. Currently I am using a U.S. Census TIGER file, mapping roads in Harris County, TX. I want to add a new field called SPEED, ...
0
votes
1answer
79 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
71 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
130 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
399 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
265 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 ...
1
vote
0answers
46 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
80 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
256 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
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 ...
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=...
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
122 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 "...
8
votes
2answers
845 views

Performing multiple calculations in ArcGIS Attribute Table?

I have an existing Excel spreadsheet developed to track specific fire hydrant data, this is periodically updated and joined to the spatial hydrant data in ArcGIS. In the spreadsheet there is a number ...
2
votes
1answer
467 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
433 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
943 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
59 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
159 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
359 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 ...
2
votes
1answer
1k views

Using If Then Else statement in ArcMap 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 ...
6
votes
1answer
645 views

Classifying time periods in new field using Python Parser of ArcGIS Desktop?

I have a datetime field (Horario) in my feature class, showing only the time. Although the date doesn't appear, it seem to be stored automatically as 30 Dec 1899, I'm not sure why. I want to use ...
5
votes
1answer
36k 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 ...