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
1answer
34 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 ...
2
votes
1answer
38 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,...
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 ...
0
votes
1answer
47 views

ArcPy: Excel to Table Conversion on multiple Excel files in a folder

I am trying to convert all of xls files (including single sheet) a folder into dbf tables in a gdb. Here is my code: import arcpy, os, xlrd arcpy.env.overwriteOutput = True arcpy.env.workspace = "C:...
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). ...
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
35 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, ...
0
votes
0answers
14 views

Using doparallel package to use multiple core for changing resolution in R

I want to use an aggregate function for my raster file to change the resolution from 30 30 to 300 300. The top code(For loop) is working very well. I want to use multiple cores to use the aggregate ...
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 ...
0
votes
1answer
54 views

For loop with SearchCursor stops after first iteration

I'm trying to iteratively select and export a layer using da.SearchCursor, but the loop stops after the first iteration. Here is the code: arcpy.env.workspace = ScratchGDB # infc= "PA" field = '...
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
60 views

Create mask for each layer of time-series raster in R

I'm trying to create a mask using each layer of my stacked Pixel Reliability QA rasters in R. I'm trying to exclude pixels with values greater than 1. I will use them to mask my vegetation index time-...
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
82 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
votes
1answer
64 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
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 ...
2
votes
2answers
117 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 ...
0
votes
2answers
137 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
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) <- ...
0
votes
1answer
64 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
2answers
83 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
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 ...
0
votes
0answers
39 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
265 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
105 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
47 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
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
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
3k 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
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
0answers
73 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
54 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
534 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
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:\...
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 ...
1
vote
1answer
274 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:...
0
votes
1answer
246 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
1answer
234 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
91 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 ...
0
votes
2answers
227 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 ...
2
votes
1answer
523 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
1answer
250 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
914 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
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
113 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
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 ...
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 ...
1
vote
2answers
235 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
51 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 ...