Questions tagged [for-loop]

A for-loop statement is a programming loop statement that performs predefined tasks while or until a predetermined condition is met.

Filter by
Sorted by
Tagged with
0 votes
1 answer
26 views

What does "del aprx" at the end of Python code do?

More of a general/theoretical question: Often times a Python code for ArcGIS Pro requires the statement "del aprx" at the very end, what does this statement do and is it necessary? I ...
user avatar
  • 452
3 votes
2 answers
139 views

How to use a list with spatial dataframes in a for loop? - R

I have three spatial dataframes (polygons), created via this tutorial. The three spatial dataframes must be exported as shapefiles via a for loop. I created a list polygons containing the three ...
user avatar
1 vote
1 answer
21 views

How to assign a coordinate reference system to x (buffer) datasets of x iterations in a for loop - R

My aims are 1) to create different buffer sizes around three points via a for loop, 2) to assign a coordinate system to each buffer for each iteration, and 3) to store each buffer in a list ...
user avatar
2 votes
0 answers
35 views

generate sequential value across multiple layers in QGIS

Running QGIS 3.16, relative beginner in q I am trying to make an auto-generated id number that: is a sequential integer, starting at 1 can be used in 2 or more different layers without duplication Is ...
user avatar
1 vote
0 answers
31 views

Subtract pairs of images from two image collections to create a collection of difference images, GEE

I have made two image collections, for pre- and post-event, that correspond to a feature collection of points representing event locations each with a date. I want to subtract each of the pre-event ...
user avatar
  • 43
0 votes
1 answer
38 views

Watershed tool in for loop on single feature point shapefiles creates empty rasters in ArcPy

I am using ArcMap 10.8. I have a flow direction raster and many point shapefiles with one feature each. I want to calculate one raster watershed for each point shapefile fd = "C:/sample/raster/...
user avatar
  • 1
1 vote
1 answer
67 views

File input loop in ArcGIS ModelBuilder

I want to automate a task on ArcGIS, and I have created a function chain working well. The chain simply evaluates a point, calculates multiple hydrological rasters & values and gives output. I ...
user avatar
  • 13
1 vote
1 answer
27 views

Setting Region with Python Loop in GRASS GIS not Updating to include Extent of Multiple Rasters

I am using the Python simple editor in GRASS GIS to write a script that can import multiple raster files into GRASS GIS mapset. The first for loop successfully pulls in the orthophoto and its relevant ...
user avatar
0 votes
0 answers
29 views

rasterio.features.rasterize doesn't work inside for loop

I'm trying to rasterize GeoPandas dataframe using rasterio.features.rasterize, to rasterize GeoDataframe based on specific column value, as mentioned in this answer. I want to rasterize by column &...
user avatar
  • 1,797
0 votes
0 answers
26 views

Nested for: I execute changeAttributeValue in the outer loop, print it and is still NULL... but inner loop works kind of fine?

A bit hard to explain, untill now my script is: I have a for, where: if an "Analized" attribute is NULL, I will change it to "Parent",store a "Join Value" attribute in a ...
user avatar
2 votes
1 answer
56 views

For loop to buffer shapefile at multiple distances, add each to the layers window, style & save to geopackage; PyQGIS

Can someone help me straighten this code out. I want to create three buffers, at 100, 250 and 500m respectively and add these to the contents table. I've tried creating a for loop but not having ...
user avatar
0 votes
0 answers
46 views

Conducting 'if' conditional and 'for' loop in Google Earth Engine

I'm going to conduct if conditional and for loop in Google Earth Engine. However, the process is completely different to other programming language such as MATLAB. I know about ee.Algorithm.IF and map ...
user avatar
  • 11
0 votes
0 answers
43 views

ListFields in Feature Classes in Multiple Feature Datasets in Oracle SDE

I need to create individual reports for feature classes that contain the field "FACILITY_STATE" AND "FACILITY_STATE = 'PPC'". These feature classes span multiple feature datasets ...
user avatar
  • 1
0 votes
0 answers
323 views

How to read and plot multiple TIFF files in Colaboratory?

I'm new in python and I would like to know how I can read and plot MULTIPLE TIFF files in Colaboratory with (maybe) a for loop. Here is what I did for a single TIFF image: from google.colab import ...
user avatar
0 votes
1 answer
143 views

Looping through multiple gdbs and shapefiles in ArcGIS with ArcPy?

I am trying to get my script to loop through a folder of shapefiles and a folder of gdbs. I need it to compare the name of the shapefiles and gdbs and if they match to continue on to loop through the ...
user avatar
2 votes
1 answer
65 views

Reducing number of for loops in ArcPy code

I want to clean this code in such a way that there are not so many for loops. For loops in the following code are placed to trap FCs in multiple group layers and do some work on them. My Data in TOC ...
user avatar
0 votes
1 answer
46 views

Batch conversion of .hgt files to .tif using Powershell returns filename.hgt.tif files

I have a folder which contains DEM in .hgt. I want to convert them via GDAL. So to convert a single file, it's gdal_translate -of 'GTiff' N16E122.hgt N16E122.tif. To do it in Powershell, I figured it'...
user avatar
  • 1,127
0 votes
0 answers
34 views

ArcGIS ModelBuilder: Why is inserted substitution variable %Value% in output value name automatically converted to _Value_?

I have several thousands netCDF raster datasets with daily precipitation from the years 1991 to 2020 for a certain region. They are stored in one folder and named RR_19910101.nc, RR_19910102.nc and so ...
user avatar
  • 29
2 votes
1 answer
33 views

Sum of raster file in QGIS using Python Console

I have 8760 raster file for the precipitation in the netherlands on hourly base, from the first day of the year (01.01.2020) till the last hour of the year (31.12.20). What I have to do with these ...
user avatar
  • 21
1 vote
1 answer
340 views

Extracting temporal series data from netcdf4 using xarray and for loop

I have a netcdf4 file (see print output) import xarray as xr ds = xr.open_dataset("../Desktop/ERA/moisture/humidity.nc", engine = "netcdf4") print(ds) <xarray.Dataset> ...
user avatar
0 votes
0 answers
42 views

Cropping and masking rasterstack to a list of shapefiles

I have a raster stack (nlayers = 366, ncells~10 million). I am hoping to crop and mask this raster stack to a data.frame of coordinates for which I have made a series of concentric circle shapefiles ...
user avatar
  • 23
1 vote
1 answer
153 views

Alternative to nested loops with fourth level depth in PyQGIS

I am developing a processing plugin for QGIS 3.10. I want to avoid nested loops when filtering one layer based on another layer. How can I implement this? I created some random layers/data for this ...
user avatar
0 votes
1 answer
39 views

Loop for exporting records from a shapefile and zip each record [closed]

I'm trying to build a shapefile for each record in my original shapefile, buffer it and then zip them (i.e. the record and its buffer). I have updated a scripts based on early script published on this ...
user avatar
  • 43
1 vote
1 answer
93 views

Speed up Python script

I am using Python code to calculate the closest facilities. Here, first I create a random point dataset. Then I use that random point dataset as an incident dataset when I'm creating the closest ...
user avatar
  • 115
0 votes
1 answer
41 views

Geolocating and writing many TIFFs at same time using R

I have found a way to give a PNG the CRS and location of a geolocated TIFF, and to convert the PNG to TIFF. Now I have to apply it to different PNGs in the same folder (all named Pt6_frame1, ...
user avatar
1 vote
0 answers
27 views

Process 100 of feature classes through script and fc name to end of each output

I have about 100 tiled 'area of interest' polygons in a geodatabase that need to be processed through my script. My script has been tested on individual tiles & works great. I need advice how to ...
user avatar
0 votes
1 answer
82 views

Using expression operators in if/else conditions without getInfo in Google Earth Engine

İ have a two-segment list with id and value and i want to make a new list from imageList using second element value. i want to get the first values in first column until 100 in second colum and save ...
user avatar
1 vote
1 answer
86 views

Work with individual Polygons of a SpatialPolygonsDataFrame (R)

I'm trying to work with individual polygons of a SpatialPolygonsDataFrame (SPDF). I've seen these two questions: Using sapply on SPDF and a for-loop on a SPDF. The latter I thought may be helpful, but ...
user avatar
  • 1,219
1 vote
1 answer
77 views

Nested for loop ArcPy

I have multiple GDBs from an earlier process. Each GDB contains a single feature class (FC). I want to copy (FeatureClassToFeatureClass) each FC into a "Main" GDB for later processing in a ...
user avatar
  • 855
2 votes
1 answer
119 views

Raster calculation with Python QGIS

I have this code in which I would like to perform a for loop in which every time I get one raster as input (the one called L, different for every month) and divide it always by the same raster (the ...
user avatar
  • 165
2 votes
1 answer
97 views

QGIS Python raster calculator

I would like to run this code that makes calculation at every loop between different input rasters and Itot that is a raster that in the loop remains always the same. The code doesn't give me any ...
user avatar
  • 165
2 votes
1 answer
146 views

Display GeoPandas on rasterio doesn't work inside loop

I have written a loop that suppose to open raster from file, display it as rgb and then plot on top of it GeoPandas plot. The problem is that the plots do not appear on to of the rasters inside the ...
user avatar
  • 1,797
0 votes
1 answer
283 views

Sum of multiple rasters in QGIS Python

I would like to make the sum of 12 different rasters to get one raster as output. I wrote the following code but it doesn't work (or better, it works, but at the end it doesn't give me any layer, but ...
user avatar
  • 165
2 votes
1 answer
82 views

Composite band through Batch processing using Sentinal 2 data in arcpy

As we know sentinel satellite data have many sub folder. I want to create composite band of each datasets with the band 2, band 3, band 4, band 8 which are located in one folder(10m) and band 11, band ...
user avatar
2 votes
0 answers
192 views

QGIS Python script with raster calculations

I have a problem with this code, that works, because it gives me the output rasters that I want, but the problem is that these outputs show wrong values because they are all 1.79769e+308. I think the ...
user avatar
  • 165
0 votes
1 answer
128 views

Display and label a stack of Sentinel 1 images with the date [closed]

I have a stack of Sentinel 1 images and I want to display all of them one by one and want the label to be the date of corresponding image. I am trying a for loop for that but I am unable to visualize ...
user avatar
2 votes
1 answer
109 views

Copy multiple shapefiles that intersect a polygon to a new location

I am trying to select and copy shapefiles from one folder to a new location based on if they intersect a polygon feature class. I am getting stuck in somewhere in the for loop. EDIT: The goal is to ...
user avatar
  • 63
4 votes
1 answer
200 views

Error in r: "mean" is not a valid subset when averaging over years in a raster

I am using a moving window average to estimate change between historical climate (here, a 36-year average for a period) and the moving window averages of climate into the future. Each moving window ...
user avatar
2 votes
1 answer
53 views

When calculating a field in an attribute table, how can I find one value out of many fields when every other field has a null value?

I have 4,018 rows of data with about 50 fields. About 45 of those fields are the same variable, but the data came from different layers, so out of those 45 fields, only one has a value for the row, ...
user avatar
  • 23
2 votes
1 answer
47 views

Using 2 different for loops in Python, skips second process

I am trying to do the following in Python 2.7: Clip all files in a geodatabase with a single layer (so a batch clip) Export the resulting clip layers (identified with _clip on the end of their names) ...
user avatar
  • 855
0 votes
1 answer
36 views

Using loops within an equation for Python and inputting values into QGIS [closed]

I would like to incorporate the use of loops within my Python coding equation. I am looking to find the value for the radius (distance) for multiple earthquakes and their corresponding intensity ...
user avatar
  • 173
0 votes
1 answer
50 views

Error while exporting plots results from cor function in a for loop over subfolders

I'm trying to plot the results from cor function that is running over multiple subfolders that contain TIF files. The process I have followed so far didn't work. It seems there is a problem while ...
user avatar
1 vote
1 answer
1k views

Naming raster layers in a rasterstack with the same name

I have a for loop where I loop layers from a rasterstack into a predict function, which requires the output of a model and two raster files, including one layer for the present ("rastFile") ...
user avatar
1 vote
1 answer
411 views

Subset by year in a raster stack, save individual raster stacks, & then loop into biovars function in R

I have raster bricks of monthly max temperature, min temperature, and precipitation for various time periods (e.g., from 2090-2100, in this example). > tmax class : RasterBrick dimensions : ...
user avatar
1 vote
0 answers
481 views

Converting every pixel of TIFF file from decimal to binary

I have a folder of .tif-files. I would like to convert every value in each of these files from decimal to binary. This code mostly works. The inner loop correctly outputs the binary equivalent for ...
user avatar
  • 395
2 votes
1 answer
132 views

For loop for access to a directory files in ArcPy

I have a Python Toolbox and I want to use a directory to read different shapefiles. But when I run the script It only works for the first shape. fd is the directory and the code is: fd= parameters[0]....
user avatar
  • 301
0 votes
2 answers
432 views

I want to create composite band image through batch processing using ArcPy

I have multiple Sentinel 2a raster images in separated folders at same location, which means every image is in separate folder. Now I want to create composite band of each raster. I have written a ...
user avatar
-1 votes
1 answer
279 views

Creating composite band image form multiple Sentinel 2 raster data using ArcPy

I have multiple Sentinel 2a raster images in separated folders at same location, which means every image is in separate folder. Now I want to create composite band of each raster. I have written a ...
user avatar
3 votes
1 answer
44 views

Spatial join features from different geodatabases

I have two geodatabases with several feature classes in both of them. I want to spatial join the feature classes in gdb1 to those in gdb2. I tried to use "arcpy.ListFeatureClasses()" ...
user avatar
3 votes
2 answers
131 views

I want to create NDVI of multiple raster using ArcPy

I have multiple raster data which are layer stack. Now I want to create NDVI of each raster data. I am stuck in the code, I developed a script but dose not generate any output. import arcpy, os from ...
user avatar