Skip to main content

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
139 views

PyQGIS blocking in for statement

I have the following PyQGIS script that is a combination of personal edits and graphical modeler: cities_layer = self.parameterAsVectorLayer(parameters, 'cities', context) urban_area = self....
Marin Marian's user avatar
0 votes
1 answer
52 views

How to generate sequential numbers for list of input table fields written to a text file (ArcMap script tool)?

In order for a script tool I'm writing in ArcMap to read fields in a source CSV correctly as text, I need to automate the writing of a shema.ini file in the source directory. In order to do that I ...
Paul DiGirolamo's user avatar
1 vote
1 answer
27 views

How to iterate through raster conversion concurrently while using map function in Python

I am trying to troubleshoot some issues I'm having with the Python map function that is part of a larger problem I'm having with trying to run my code concurrently. Why does map() here create an empty ...
ENIAC-6's user avatar
  • 896
5 votes
3 answers
293 views

Looping every features pair with PyQGIS

I need code that loops between each pair of features in sequence (feature 1 with feature 2, feature 2 with feature 3...) but using only a for, I searched the forum and found similar code but with two &...
Mestrexama's user avatar
1 vote
1 answer
35 views

Changing strokestyle to no for all point layers in group or project

I have 700+ point layers in my project in one group ('Groupname'). All of them have the standard symbology (but different colors). I want to change just the setting of the "stroke style" to &...
Immo Woschny's user avatar
1 vote
2 answers
177 views

Reprojecting each tif located in Folder Directory using GDAL in Python [closed]

Python beginner here. I am using python to reproject a folder of rasters (.tifs). Each raster has a projection that I want to change to WGS 1984 (espg:4326). I want to use an open-source GIS library ...
Connor Garrett's user avatar
0 votes
1 answer
313 views

Calculating dNBR for Image Collection in GEE

I'm trying to calculate the differenced normalized burn ratio (DNBR) values for a Landsat image collection in Google Earth Engine for detect fire date and measure burned area using the following code; ...
Gencergis's user avatar
  • 109
0 votes
2 answers
226 views

Multiply two rasters in R, one raster has stack of 25 images, and another raster has one image

I want to multiply two rasters (one has 25 images, and the second raster has 1 image). I am using the loop function for multiplication. But I am not getting the results. library(raster) library(rgdal) ...
user221527's user avatar
2 votes
1 answer
245 views

Add result from for loop rasterstats zonal_stats to gpd shapefile attributes as new columns

I am trying to use a for loop which would produce the zonal statistics of multiple rasters at shapefile points and then add each raster stat to the shapefile. I've gotten it to add a column, but I don'...
sarakota's user avatar
1 vote
1 answer
95 views

Finding the mean of raster layers using for loop in R

I am trying to compute the average of raster layers (mean temperature layers) from PRISM data base using a loop. Number of layers in the stack is 70 tmean10<-list() tmeanR<-stack(tmean_52_61_R,...
Rahul Raveendran's user avatar
0 votes
0 answers
40 views

Get a list of fields from a list of shapefiles [duplicate]

I am trying to get a list of fields from every shapefile in a list I have created that's stored in a variable. My prof says I should be able to call that variable in my if/else statement within my for ...
hanbone's user avatar
  • 33
1 vote
1 answer
52 views

Iteratively name output files in a loop while using arcpy.conversion.FeatureClassToFeatureClass

I have four input feature classes and one feature dataset which I am trying to send them to. I would like the new feature classes to have the same names as the originals. My process is as follows: for ...
dre627's user avatar
  • 29
0 votes
1 answer
132 views

Select by attribute and location within a for loop? [closed]

I have dozens of feature classes in a project geodatabase. I have the code that will identify all the misplaced wells in each dataset, but for the life of me I can't figure out how to get the lines of ...
redleg_64's user avatar
1 vote
1 answer
66 views

Looping GRASS "v.extract" in python

I have a multipolygon shapefile representing different cities. I am trying to loop the "v.extract" GRASS command through the different polygons via the Python interface. This is the code I ...
okapina's user avatar
  • 103
0 votes
1 answer
656 views

how to print all the images of an Image Collection

I have to print all the images (layers) of ImageCollection because it is easier to select manually the best image. Is it possible? var point = ee.Geometry.Point([8.73727, 45.81165]); // Import the S-...
Gianmarco Tenani's user avatar
0 votes
0 answers
249 views

Error using "if" in R: "== : missing value where TRUE/FALSE needed"

I am using st_covered_by function (from sf package) with a for loop and if statement to create a dummy variable to know if specific points from different municipalities are found inside the polygon of ...
Ferran OA's user avatar
1 vote
1 answer
1k views

Shapely Polygons | Calculate Intersection of Union

Goal: Calculate 8 different Intersection of Union area numbers, each concerning the intersection of 3 MultiPolygons. There are 3 sources, each representing the same 8 groups of shapes. Mathematically, ...
StressedBoi_69420's user avatar
-1 votes
1 answer
68 views

Looping through dictionary to update Hosted Features in a Pro doc

I am trying to update a dictionary of hosted feature layers, the key is the layer name, and the value is the SDE path of the layer where the updated data will be truncated and appended with. For loops ...
hBiery's user avatar
  • 13
1 vote
1 answer
214 views

Use nested for loop to find all possible combinations of rasters in geodatabase using Python

I have one geodatabase with multiple rasters where the raster name should automatically identify which category a raster belongs to. I want to combine SLR named rasters with SLOSH named rasters. I am ...
GraminoidCons's user avatar
0 votes
1 answer
852 views

Run a for loop in R to calculate monthly mean from an Excel sheet

I want to calculate the seasonal mean from monthly long-time temperature data. series<-data$Temperature p=5 new=NULL for(i in 1:length){ ydata<-series[((i-1)*p+1):(i*p)] yavg<-mean(ydata) ...
Tirthankar Ghosh's user avatar
1 vote
0 answers
63 views

Loop to download worldmet data in R

I'm rather new to R. I am trying to create a loop to download worldmet data for each uk weather station for a particular year. I have found a previous link but still unable to get the required output -...
Kathryn Adams's user avatar
1 vote
1 answer
473 views

Using ArcPy to iterate through multiple LAZ files and convert them to LAS files with lastools

I'm using Jupyter Notebooks in ArcGIS Pro and I would like to convert multiple .laz files into .las files by using the opensource toolbox 'lastools' and its function 'laszip'. For this I would like to ...
Radde1683's user avatar
  • 193
1 vote
2 answers
124 views

Looping ArcPy function through each point in shapefile

I have been trying to create a geoprocessing tool to delineate watershed basins for each point in a shapefile (parameter 1; CROSSING). The code below returns three 'basins', but they are all identical ...
Jack's user avatar
  • 13
0 votes
1 answer
415 views

Export as CSV after using for loop in GEE

I'm trying to use the for-loop function for a supervised classification over several dates. I have trouble exporting the accuracy metrics that are useful to me in a single CSV file. With my code I can ...
DreyCodjia's user avatar
1 vote
1 answer
361 views

How does "is_child_algorithm=True" work in processing.run in Python QGIS script?

I don't understand how "is_child_algorithm" works in processing.run. Premise: I created a script in python. This script uses a loop, iterating thousands of times over a field on a layer. I ...
Peter's user avatar
  • 31
0 votes
1 answer
53 views

Looping through fishnet feature in ArcPy [closed]

I would like to loop through a fishnet feature and add the extent of the cells to the attribute table. Here is the relevant code part: cur = arcpy.UpdateCursor(fishnet_feature) for row in cur: ext ...
Nirevezs's user avatar
-1 votes
1 answer
591 views

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

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 recently ran a Python snippet changing data ...
sparky's user avatar
  • 450
3 votes
2 answers
1k 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 ...
Foeke Boersma's user avatar
2 votes
1 answer
135 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 ...
Foeke Boersma's user avatar
2 votes
0 answers
90 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 ...
Swordnut's user avatar
2 votes
1 answer
529 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 ...
Erin's user avatar
  • 157
0 votes
1 answer
110 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/...
TVolt's user avatar
  • 21
0 votes
1 answer
134 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 ...
aoenen's user avatar
  • 11
1 vote
1 answer
83 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 ...
pbaltezar's user avatar
0 votes
0 answers
37 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 ...
javir Ib's user avatar
3 votes
1 answer
131 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 ...
Jiinglelocks's user avatar
0 votes
0 answers
114 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 ...
Evan's user avatar
  • 1
0 votes
1 answer
3k 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
757 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 ...
Mackenzie's user avatar
2 votes
1 answer
79 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 ...
Abdul Rauf's user avatar
0 votes
1 answer
328 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'...
BallpenMan's user avatar
  • 1,217
2 votes
1 answer
78 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 ...
Daniele's user avatar
  • 21
1 vote
1 answer
2k 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> ...
Luis Barresi's user avatar
1 vote
1 answer
343 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 ...
Ehsan Aliverdi's user avatar
0 votes
1 answer
262 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 ...
Afana A's user avatar
  • 73
1 vote
1 answer
188 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 ...
Madusha's user avatar
  • 115
0 votes
1 answer
88 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, ...
Esteban Rodofili's user avatar
1 vote
0 answers
34 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 ...
Cödingers Cat's user avatar
0 votes
1 answer
193 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 ...
Mehmet C ARSLANOGLU's user avatar
1 vote
1 answer
465 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 ...
Honeybear's user avatar
  • 2,454