Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

6
votes
4answers
775 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
489 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
110 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 ...
2
votes
2answers
538 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
285 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
440 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
221 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
76 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
96 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
319 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
161 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
2answers
634 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
207 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
87 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
66 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
45 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
1k 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
144 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
566 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
53 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
82 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
155 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
54 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
81 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
45 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
27 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
26 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
25 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
256 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
228 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
130 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
76 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
46 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
96 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
79 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 ...
0
votes
1answer
29 views

Map.addLayer automation

As in the Hillshade Example, I wanted to automate adding all Layer from one Image for visual inspection. var band_names =Image.bandNames() print(ee.String(band_names.get(0))) for (var i = 0; i < ...
0
votes
1answer
143 views

Running MaxEnt modelling in “dismo” using “loop” and storing the results in seperate objects and folders [closed]

I am doing a MaxEnt modelling using "dismo". I am using a loop to give multiple runs. I wanted to save results from individual runs in separate objects and at the same time the results from individual ...
0
votes
2answers
119 views

Selecting layers of a raster stack using a sliding windows as a step in R in for loop

I would like to create a loop that every time selects the first ten layers of a raster stack, calculates their mean and saves it to a layer of a new raster stack. Also, I would like to have a step ...
0
votes
1answer
141 views

Extract raster information from a spdf and for different buffer size in a loop

For a project in geoprocessing, I need to extract information from a raster but for different buffer sizes. I have a raster of the population (100 m size pixel) and a SpatialPolygonDataFrame with the ...
0
votes
2answers
146 views

For loop in ModelBuilder?

I have a roads dataset downloaded for Christchurch, New Zealand, from OpenStreetMap. The attribute table contains a column titled 'fclass', which contains the type of road each feature represents (e.g....
0
votes
0answers
25 views

Extract values from multiple rasters based on lookup of raster file name

I have 11 raster files (waveheightfiles), and need to extract one value from a different set of coordinates (station) for each raster. I have a list of 11 coordinates (df2) and have used part of the ...
0
votes
0answers
28 views

Using dictionary key values in for loop for dynamic output variable assignment in Arcpy

I am wondering why I need to include a '/' at the end of my path name when changing my workspace. I am writing a script where I'm trying to create a geodatabase and then reassign my workspace to it. ...
0
votes
0answers
37 views

arcpy.Delete_management crashing ArcGIS

I'm running a for loop to rescale a bunch of rasters and then save them for use in another function. However, I'm having trouble saving the rasters properly. My current solution is to copy the rasters ...
0
votes
1answer
28 views

gdalwarp for clipping images using multiple polygon in a bash shell for loop

C:\OSGeo4W64\bin\gdalwarp.exe -dstnodata 0 -q -cutline D:\hillsborough_Images_work\split_Polygon\120-140k\Hillborough_FINAL_140000_region_IGD_120570003d29ed0dc.shp -crop_to_cutline -dstalpha -tr 0....
0
votes
1answer
271 views

GEE hangs in a for loop using dates

I want to have a loop on a date variable in Google Earth Engine, but it hangs and show me nothing when running just below simple code: var aDate = ee.Date.fromYMD(2015,12,21); var bDate = ee.Date....
0
votes
0answers
29 views

Applying Various Symbologies in Loop

The code runs, but the output layers do not display the symbology layer(s). Any suggestions? def Copy_Symbology( Symbology_Template , Input_SHP , Output_Layer_Directory ): baseName = os.path....
0
votes
1answer
149 views

For loop to convert .lyr files to KML files gives ERROR 000814?

I must convert .lyr files to Kml files. After searching, I already tested 3 codes. Unfortunately, when running the 3 codes Python displays same error: Runtime error Traceback (most recent call ...
0
votes
1answer
71 views

arcpy for loop to save shapefiles as .layer files

I have 150 shapefiles in folder in "D:\ss3\polygons". I want to save each polygon as .layer file with the polygon name in "D:\ss3\layers" However, Python displays: "Parsing error SyntaxError: invalid ...
-1
votes
1answer
46 views

Merge and save results after selections using loop

I want to merge shapefiles after selection inside a loop and then save results to excel files. However, the codes could save the last result to excel files and can not save each merge file. import ...
-1
votes
1answer
44 views

Python For Loop is Adding Extra Records to Output

I'm using Python in ArcGIS Pro to run through a couple of point layers to find the Closest Facility between them. I think I'm really close to getting what I want in an output, but I'm getting more ...