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
1
vote
1answer
53 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
80 views

Select by location inside a for loop in Python Terminal at QGis 2.18.17

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 code to be ...
-1
votes
1answer
51 views

Making looping through line segments for vertex points faster?

I am trying to speed up some current code that I have for looping through lines, getting their segments and ultimately the vertex points in Python. Can anyone recommend a faster method than what I ...
1
vote
0answers
15 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
42 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 ...
0
votes
1answer
36 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
2answers
46 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(...
1
vote
1answer
38 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) <- ...
0
votes
1answer
41 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 ...
-1
votes
1answer
56 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
vote
0answers
28 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 ...
0
votes
0answers
33 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
1answer
145 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 ...
1
vote
1answer
98 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 ...
0
votes
1answer
32 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 < ...
1
vote
0answers
30 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
1answer
221 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
0answers
29 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
1answer
210 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
46 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 = ...
3
votes
1answer
120 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 ...
0
votes
0answers
36 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. ...
1
vote
1answer
62 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
2answers
2k 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 ...
0
votes
1answer
79 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
0answers
49 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
350 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
1answer
54 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
170 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 ...
2
votes
1answer
103 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. ...
0
votes
1answer
184 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
87 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 ...
2
votes
1answer
387 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 ...
0
votes
2answers
140 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
175 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 ...
6
votes
4answers
862 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 ...
1
vote
1answer
92 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
0answers
258 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 ...
2
votes
2answers
693 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 ...
1
vote
2answers
185 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
votes
1answer
47 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 ...
2
votes
2answers
304 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 ...
1
vote
1answer
72 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
2answers
819 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){ ...
0
votes
1answer
123 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 ...
-1
votes
1answer
75 views

SQL query new feature within definition within loop of cursor

I am using ArcGIS 10.4.1.5686 and running code within ArcMap. I thought that this question is similar to SQL query new feature with loop, or even Using a for loop to execute a query in arcpy, but ...
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
95 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, ...
2
votes
1answer
497 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
0answers
169 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, ...