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
6
votes
4answers
918 views

Using LIKE in a For Loop with UpdateCursor

I have a classified raster with a class value that is a very long concatenated string name (Class_Name below). I'm trying to use arcpy to generate integer labels ranging from 1-24 (which are the third ...
3
votes
3answers
503 views

Using IF statement in FOR loop? [closed]

I'm trying to use a for loop in a list to assign different buffer widths to the list depending on the length of the line being buffered. I have my list of lengths, and tried to use a for loop to ...
3
votes
1answer
131 views

Error in reprojecting raster from WGS 84 to GDA 94

I am trying to reproject multiple .tif files with the following code: # Import system modules import arcpy import os # Set environment settings arcpy.env.workspace = r"H:\GIS Project\Bulk Density\In ...
3
votes
1answer
22 views

Reading in different raster files with different bands using a loop

I've downloaded 6 multi-band raster files (each file has 4 bands) from the National Weather Service containing precipitation data for different time periods (30, 60, 90, 120, and 365 day periods). ...
2
votes
2answers
1k views

How to run for loop with unique values

Instead of two shapefiles that are saved in fcList in this loop I would like to do KernelDensity on the unique values of one shapefile. Does anyone have an idea how this might work? import arcpy,os ...
2
votes
2answers
118 views

Select by location using for-loop in Python Terminal

I have two shapefiles ('drenagem' and 'rio_pri'). I need to loop through every feature from 'rio_pri' and save all those features from 'drenagem' that intersect 'rio_pri'. So I wrote the following ...
2
votes
2answers
324 views

arcpy: For loop to sequence Processing of two items in list using ArcPy?

I have multiple rasters, organized by years. I.e. raster y1 = from year 1 raster y2 = from year 2, etc...). All of rasters contain values 0-11, representing forest (0-6) and disturbance (7-11). I ...
2
votes
1answer
699 views

How to iterate in a Spatial Polygon Data Frame in R?

I'm trying to iterate in a SpatialPolygonDataFrame that contains 110 features. I tried to use the following code with no success: iterate.spdf = function(x){ for(i in 1:nrow(x)){ p = x[i,...
2
votes
1answer
323 views

Loop for in arcpy: for several rasters, clip with the same shapefile and create an output

I am building an arcpy script, where I would like to create a for loop, that for each raster, it clips it from a shapefile, and creates a new output, with name based on the file itself. The code: ...
2
votes
1answer
41 views

Finding minimum distance from list of coordinates

My understanding is that this should work like this, the code will start with test list sublist [1,2,3] and move to the points list until all lines are run and then move back to test list sublist [2,...
2
votes
1answer
36 views

Executing buffer analysis in ArcPy with for loop?

I'm attempting to run the Buffer Analysis tool with a distance of 3 km over multiple shapefiles at the same time. I was given a folder with different types of files and ran a for loop to create a new ...
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 ...
2
votes
1answer
105 views

Replacing NULL values, loop skips records using Python, OGR, Rtree?

I have a point layer with several NULL values and based on a near analysis with another layer, I would like to replace those NULLs. However, with the code I use it only does a couple and then stops. ...
2
votes
1answer
527 views

Python loop stops before running all files [closed]

I have a Python loop, the loop has to run commands on 200 plus files. But it randomly stops and does not continue producing the new output files. here is the code: from subprocess import Popen, PIPE ...
2
votes
0answers
179 views

Creating instances of QGiS in for loop in standalone python script

I have a Python script which processes data with geographic information. At some stage of my script I need to use an instance of QGiS to make some shapefiles and do some intersects and so on. For now, ...
1
vote
1answer
1k views

Append element to an array in Google Earth Engine

I am trying to write a for loop to append elements dynamically to an array. However, the dimensions of the array change on every loop run, throwing off error. var arr = 1 for (var i=0;i<4;++i){ ...
1
vote
1answer
254 views

For-Looping through Bookmarks in Python Script tool?

I'm using this script tool, in ModelBuilder for ArcGIS Pro, to set up a map layout, reference a bookmark, and export the layout as a PDF. This model iterates through Urgent Care centers and its ...
1
vote
1answer
106 views

For loop within for loop with ArcPy cursor?

Below mentioned one is a part of my script.This is working when I assinged numbers for f.(Instead of "f" I have substitute 2.Then it is working).But i want to run this based on the no of rows of the ...
1
vote
1answer
82 views

Looping script with Zonal Statistics

This is my first time using python in ArcGIS. I have a gdb of about 100 feature classes, and need to get Zonal Statistics for each. I'm using a textbook, and got this so far: import arcpy from arcpy ...
1
vote
1answer
17 views

Iterating through point shapefiles, converting them to polyline shapefiles with unique names using ArcPy

for fc in arcpy.ListFeatureClasses(): outfc = fc + "_l" arcpy.PointsToLine_management(fc, outfc) it comes up with the error "Output Feature Class: Same as input". Looks like it didn't convert ...
1
vote
1answer
36 views

Using for loop to print last messages from multiple processes?

Is there a way to use a "for" loop to print the success messages for all of the following geoprocesses? In this example, I am clipping the entire river system of Kansas to a pre-selected ecoregion, ...
1
vote
1answer
84 views

Accumulate selections by expression using a for loop (Pyqgis)

I need to run a for loop to select features by their attributes, because the values are within lists (strkey and strvalue). I'm using the following script: k=0 v=0 layer = iface.activeLayer() for ...
1
vote
1answer
47 views

Making loop over shapefile attribute using ArcPy?

I have a polyline shapefile. The shapefile has a field called "NAME" I would like to make a loop over each line (A,B,C,D,...). This is the python code for only first line named "A" profileLine = ...
1
vote
2answers
4k views

Arrange pair of coordinates in Python lists [closed]

I have these coordinates of a bounding box in this format: (51.901071, 7.543488, 52.002215, 7.692406) and I want to convert it into a list of coordinates so that I can iterate through the pair. The ...
1
vote
1answer
276 views

Creating loop to reproject multiple rasters in ArcPy gives ERROR 999999?

I am trying to batch reproject multiple raster files using arcpy. Here is the code I have so far: # Import system modules import arcpy import os # Set environment settings arcpy.env.workspace = "H:...
1
vote
1answer
726 views

Using Update Cursor in a double for loop in arcpy

I have some problems using a double for loop and getting results written into a geodatabase. I have got a shapefile with polygons (param_polygone) and I want to add data to it, which is stored in a ...
1
vote
1answer
58 views

Error during a for loop in Python terminal from QGIS 2.18.17

When I run the script below in Python Terminal at QGIS 2.18.17 (Linux Mint 19) it always crash after doing 73 iterations at the 2nd for loop from the script. Could anyone explain why this happens and ...
1
vote
1answer
70 views

Using a dictionary along with geoprocessing tools?

I am new to python and trying to create a script that will select specific parcels from a large parcel layer. Is it possible to create a dictionary with the names of the parcels as the key and the ...
1
vote
1answer
114 views

Iterator in ModelBuilder does not complete final iteration (last action)?

I am using the ModelBuilder to run an iterative process using the "for" iterator. The entire process is about 7 steps that are iterated several times, depending on the input to the tool (to value, ...
1
vote
2answers
239 views

Saving output in ArcPy For-Loop?

How can I save the output of my For loop so that I have a different output name each time? This is the code I´m using: import arcpy from arcpy import env from arcpy.sa import * env.workspace = r'C:\...
1
vote
1answer
58 views

Use results of loop for another raster calculation

I've been looking extensively to find a solution for what I think is a very simple exercise. In general, I would like to know how I can extract a variable from a loop in Python and then use it ...
1
vote
1answer
121 views

Map Automation Script For Looping Help

Working on a Python script that I will run inside of ArcGIS 10.5 that will export PNG maps. Each map will be a different state and for every state there will be 5 different physician specialty types, ...
1
vote
1answer
47 views

Continuously changing values in the same band of a multiband raster

I am having issues with continuously changing the values of pixels within a single band of a multiband raster using python 2.7. Essentially, what I am trying to do is continuously change (increment) ...
1
vote
0answers
15 views

For-loop to call fields for IDW-Interpolation

probably a question easy to answer, but I do not figure it out at the moment. I'm using station-data and do a IDW-interpolation to get average climate values in layer. The station's data is arranged ...
1
vote
0answers
18 views

Capture non-attribute user input in ArcGIS Pro task

I am trying to write an ArcGIS Pro task that involves one or more data layers. However, the exact number of layers may vary between runs. Sometimes the data may be in one file, other times there may ...
1
vote
1answer
51 views

GLCM function for RasterStack using FOR loop in R

I would like to calculate glcm function in R for all (52) bands in my RasterStack. Using this code: LS<-stack(img1,img2,img3,img4,img5,img6,img7,img8,img9,img10,img11,img12,img13) names(LS) <- ...
1
vote
0answers
30 views

Fix an export for loop that recently stopped working? [closed]

I have created several for loops in my GEE script. These loops worked fine up until a week ago (about 4 months old). I receive the following error in my console when the code tries to run the for ...
1
vote
0answers
38 views

Using ModelBuilder to Iterate Row Selection with ArcMap?

I have a model that does a lot of linear calculations, then eventually runs into an ITERATE ROW SELECTION tool. I only want the iterator to cycle through the tools downstream of itself, but instead ...
1
vote
0answers
32 views

Loop over columns of shapefile in modelbuilder

I use a shapefile (rain.shp) with a bunch of columns (rain_1979, rain_1990, rain_1991, ..., rain_2015). I would like to transform every column of the shapefile into a different raster using the ...
1
vote
0answers
261 views

Stopping arcpy for loop in cases where outputs match wildcard and get fed back to for loop list

Using a list of the feature classes matching a wildcard, I loop through 12 feature classes with a dataset. For each feature class, I make second list of all unique values within the REGION field, and ...
1
vote
0answers
279 views

Is it possible to list SpatialGridDataFrame files to be used in a loop?

I have a lot (>50) of SpatialGridDataFrame files that I need to turn into raster files, stack with a set of raster files I already have and then extract data from random points from each layer of all ...
1
vote
1answer
153 views

Loop using Reclassify function: string 'RemapRange' object is not callable

I am a newbie of python teaching myself using the arcpymanual. I am running a Reclassify script on slope grids. It works fine for the first loop then I get an error message for the remap line. I ...
0
votes
1answer
53 views

Getting same result with less code with PythonWin ArcPy? [closed]

I have finished writing code and it does what I need without having any error. However, I am wondering if there is any option to get the same result in fewer lines, pecially the for loop inside the ...
0
votes
1answer
37 views

QGIS 3.10 - Python problem with double for loop

I am new to Python and I am trying to write a custom function which iterates through a table of points and adds a field with all of the lines that touch it. At the moment I am getting a partially ...
0
votes
2answers
140 views

Reading shapefiles using for loop: Error in readOGR() : length(dsn) == 1L is not TRUE

I'm using a for loop to read in multiple shapefiles within a directory and manipulate them individually. Presently I cannot do this because the for loop results in the error: "Error in readOGR(...
0
votes
1answer
68 views

List of small lists in Python: How to retrieve items from small list in a loop?

I would like to automate the process of making some certain feature layers. I made a list of lists that goes like that: [[feature class, subtype],[feature class,subtype],...] I'd like to loop ...
0
votes
1answer
82 views

Arcpy iteration in folder for all shp equivalent

I want to write a scrpit that automatize the process of clip and project (in one GCS) to many .shp in folders and subfolders (row downloaded data), with 2 different GCS (CH1903+ or Lambert93). For ...
0
votes
1answer
77 views

Raster Properties to TextFile using ArcPy?

I have multiple rasters that I want to get the mean of the all the cells. This is what I have: env.workspace = r"C:\Users\pyb609\Desktop\Updated Files\GIS\Dark\Shapefiles\15M" outfile = open(r"C:\...
0
votes
1answer
200 views

For Loop not looping correctly - ArcPy

I have four markets 1000-4000, but I only want to do markets 2000 and 3000. I created a markets list only containing those two markets so that I could use the list in a "for" loop. However, when I try ...
0
votes
1answer
272 views

writeOGR error: length(dsn) == 1L is not TRUE

I'm running a for loop R that results in a shapefile being written with each iteration. The for loop runs successfully once, with a shapefile being written out, but then on the second iteration I get ...