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
4
votes
2answers
67 views

Nested if statement in QGIS label expression

I'm trying to create labels for features, based on the value (or missing value) of three different columns and combinations can be possible. I have three columns: Veg_dom, Veg_codom and Veg_onderg. ...
2
votes
1answer
25 views

How does gridmetrics handle IF condition in user defined functions?

I noticed a kind of "inconsistency" in the values returned from two user-defined functions. I tested on a tile of 200mx200m to return a raster of pixel size 50m (16 pixels) In the following ...
1
vote
1answer
26 views

ArcMap labels that come from different fields

I am trying to make labels for a feature class called m_GraveLotSingle. I have a field that is called "Raised_Flat". If the field is "RAISED" I would like it to show the label of ...
0
votes
2answers
65 views

ArcGIS Pro Python Field Calculating

I am trying to use Python in ArcGIS Pro to cleanse some data via imported Excel sheets. The expression works, but the Code Block if-else statement to return nothing if !Street_Id! is returns an error....
1
vote
1answer
33 views

Carto: Can I use some “if/then/else” structure in popup custom HTML?

I believe I am asking a question similar to this question that was asked a few years ago about popup functionality in the old CartoDB. I just tried my best to replicate the solution to that question ...
2
votes
1answer
66 views

Writing If-Then Statement in ArcGIS Pro Field Calculator Code Block using Python Parser

I have two columns in my shape file with text values called GP and Z which contain abbreviations and a third column called UpOrDown which is meant to hold the binary 0-1 generated from the if-then ...
1
vote
1answer
67 views

Why does Python if/else statement only return else condition when trying to reclassify field using ArcMap field calculator?

Using arcgis v 10.4. I'm trying to reclassify values from a field (ECOREGION_DIVISION), which is in string format, into new values using the following Python syntax: def Reclass(ECOREGION_DIVISION): ...
0
votes
0answers
45 views

If/else condition in Model Builder QGIS 3.10 Batch processing

I have a set of images I need to process - all except one I have to calculate in Raster calculator with one expression, and the only one is the other expression. All following steps are the same for ...
0
votes
1answer
30 views

ArcGIS Pro field calculator if - else - string error

I try to calculate some fields with the field calculator using a simple if-else condition. I would like to write the values in the field volume, based on some calculations including values of fields ...
0
votes
1answer
34 views

How to use if else statement to create attribute in shapefile using R [closed]

I am working on a if statement within R to populate a new variable called d1 with values from my income field if variable A equals 1, otherwise autofill zeros. I'm having issues with getting it to ...
1
vote
1answer
76 views

Using Python Code from QGIS modeler with if and else

I am using QGIS 3. The following script code is generated from a model. At the end the code has to create a field Fl_m2, if the blnFl is true. if ['blnFl'] is True: If it is not true the ...
4
votes
1answer
127 views

Using Boolean Parameter in QGIS Graphic Modeler

I am trying to create an if/else condition with a boolean parameter in QGIS graphic modeler. The parameter will be used inside Field Calculator2 algorithm.By default the parameter is False. I am ...
4
votes
1answer
939 views

Using if/else structure in Google Earth Engine

I wrote some simple code to test the if/else structure in GEE: var flag = ee.Algorithms.IsEqual(1,5); print(flag) if (flag) { print("this is true"); } else { print("this is false"); } the output ...
-1
votes
1answer
48 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
75 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
66 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
321 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
167 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"...
2
votes
1answer
133 views

Using if statement with ArcPy and GetCount?

I am looking to get a count on the polygonNieghbor and if it has polygons in it then I want to move to the next step MakeFeatureLayer. and If it doesn't have any features I would like it to finish. ...
1
vote
1answer
120 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
60 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
840 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
50 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
54 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
98 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
85 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
1k 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
572 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
130 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
945 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
74 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
3k 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
995 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
212 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
326 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
701 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
4k 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
81 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
72 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
145 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
576 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
344 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
81 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
327 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
2k 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
109 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
45 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
131 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 "...