Questions tagged [loop]

A sequence of instructions that repeats either a specified number of times or until a particular condition is met.

Filter by
Sorted by
Tagged with
13
votes
5answers
1k views

Looping through 16 million records using ArcPy?

I have a table with 8 columns and ~16.7 million records. I need to run a set of if-else equations on the columns. I've written a script using UpdateCursor module, but after a few million records it ...
12
votes
1answer
3k views

Simplify repetitive tasks in QGIS Graphical Modeler

Are there iterators that can be used in QGIS graphical modeler to simplify the model shown above. If not, is there any better way of simplifying the model? The first column represents my input layers,...
11
votes
2answers
3k views

Stopping PyQGIS script that has infinite loop, using keyboard?

So I wrote a script that does what I want over and over again using a "while True:" in a certain time interval (every 5 seconds using time.sleep(5)). So far so good, BUT when I want to stop it I just ...
7
votes
3answers
438 views

Counting in for-loop using ArcPy Cursor?

When using the UpdateCursor, is there a "built-in" way to count within the loop? In the moment I am using a variable i and add 1 after each iteration: cur = arcpy.da.UpdateCursor("points.shp","ID1") ...
5
votes
3answers
7k views

Loop with arcpy.ListFiles

I'm super new on here and have also not much experience with Python but I really like to learn to work with this language. I'm tying to write a script for this: I think I need a for loop instead the '...
5
votes
4answers
2k views

Get a coordinate system from raster file

I am writing a code to loop through all the files in a folder and reproject them, using a raster as the spatial reference. I have a suspicion that there is a different way to get the coordinate system ...
5
votes
3answers
2k views

Loop in ModelBuilder for compositing bands of multiple Images

I'm attempting to automate the "Composite Bands" tool somehow in ModelBuilder, but haven't been able to figure out an effective method. I have landsat 7 data that is separated into folders and each ...
5
votes
1answer
1k views

How to do loops on raster cells with python console in QGIS?

I'm new here and beginner with python. I'm looking for a solution to my problem for some hours but now you are my last chance... I'm using the python (2.7.5) console in QGIS (2.4.0). Is there a ...
5
votes
1answer
324 views

Loop NDVI calculations for hyperspectral datacubes in R

I am writing a script for the processing of different hyperspectral datacubes. The datacubes contain flight lines that I've recorded with a UAV. In total there are 10 flight lines that need to be ...
4
votes
3answers
591 views

Looping if condition in ArcPy?

I want to use "Calculate field" based on the string in another field. I would like to loop if condition but something is wrong and I am little bit confused. I am super new in Python. Here is my ...
4
votes
1answer
570 views

Iterate through list of field names and calculate fields with PyQGIS?

I am using QGIS 3.2.1 Bonn 64 bit on Windows 10. I would like to loop through a list of field names and perform calculations on each field. Only the first loop in the iteration performs any ...
4
votes
1answer
816 views

Problems with nested loops - How to start from 0?

I have : 12 lines feature classes (lineFC) A polygon feature class (grid) Another polygon feature class with much bigger polygons (gridDivision) The process: Select one lines FC from a list Select ...
4
votes
1answer
843 views

How to loop in PostGIS to add the next lat long to a route

I want to loop over the results of a query and then pass row(n)'s longitude, latitude and row(n+1)'s longitude and latitude to another function. I have a query which returns a set of coordinates from ...
4
votes
1answer
604 views

Improving performance of looping over MXDs using ArcPy?

I am attempting to find the fastest method for looping over multiple map documents while keeping memory resources down. I'm running this script outside of Arcmap 10. I have 5 map documents which are ...
4
votes
1answer
250 views

Recursive loop to modify vector layer and refresh mapcanvas

I'm trying to plot one point "jumping" each second in the canvas (like a gps tracking). I need to take points from a .csv file. This functionality is made in a QWidget of my application, so the code ...
3
votes
2answers
5k views

Create an array from field values in ArcPy

I have a feature class that has a field of unique ID numbers. I would like to create an array of these numbers so I can loop over them in ArcPy. Any ideas?
3
votes
3answers
2k views

ArcPy nested loop problem

I have a question connected with ArcPy. I was trying to make a nested loop with 2 cursors - 1st with 2 elements and 2nd with 5 elements. The statement should return 10 connections, e.g. 1-1, 1-2, ... ...
3
votes
2answers
250 views

Update Cursor for automation of tedious data entry which keeps crashing ArcMap

I coded the Update Cursor for automation of tedious data entry where I am applying a previous Survey Company Identification Data to STRUCTURES_15096.shp from "OFFICIAL_STRUCTURES2015.shp" and it keeps ...
3
votes
2answers
479 views

Finding layer based on source name using ArcObjects?

I am relatively new at creating tools with ArcObjects and I am having trouble finding a layer based on the layer's source name by looping through all layers. I've seen here that it is possible, but I ...
3
votes
1answer
1k views

Raster calculation loop - R

I have a raster stack of 108 elements The stack 'images' is created using 4 bands (RGB+NIR) of 27 satellite images. The sequence of the rasters in the stack is: Position [[1]]: blue band image 1 ...
3
votes
1answer
170 views

Not getting correct result from for loop

The for loop below works without error, but the result is get in the table of my database is wrong. Its as if the for loop skips right over the first 3 if and elif statements and goes to the else. The ...
3
votes
2answers
1k views

Looping through raster layers in folder with PyQGIS?

I'm looking to apply a mask to a number of rasters in PyQGIS. (updated but still not working) import processing rstr = "/Users/rasterfilepath/" shp = "/Users/shapefile.shp" outputDir = "/Users/output/...
3
votes
1answer
361 views

Iterate through shapefile and output an image for each feature using sf in R

I would like to create some statistical profiles for a range of features; specifically, 2016 Census profiles for the Census Divisions (CD) within British Columbia (BC), Canada. This would require a ...
3
votes
2answers
5k views

Handling multiple-extent-problem to create raster stack in R?

I am storing ~ 30 raster files in a folder and want to create a raster stack. I know that not all of these rasters have completely the same extent. They do have the same resolution and CRS. Thus I ...
3
votes
1answer
55 views

doubleloop vs numpy

I would like to rewrite the following piece of code to use numpy, as it is too slow in its current format. The problem is that I cannot wrap my head around numpy to make it work pixels = band....
3
votes
2answers
239 views

ST_Distance loop

I want to create a postgresql function which calculates the distances between random points who are stored in one table. For the Table: CREATE TABLE s_1( id bigserial primary key, the_geom geometry, ...
3
votes
1answer
2k views

Loop to check multiple polygons overlap in r

I have a set of polygons (available here: http://ulozto.cz/x39ELbFt/polygons-zip) created in QGis and processed in R. I would like to know if they are overlapping or not, and if yes, where is the ...
3
votes
1answer
134 views

Can't do anything else in QGIS during While-Loop

I've written a Python QGIS plugin that reads data from an AIS receiver via the Serial package. It will be similar in function to the GPS Information panel in that it will show your position on the map ...
3
votes
1answer
128 views

Loop through 2 folders and perform raster calculation on the same file name

I was able to run the below script from @EmilBrundage. However, the raster to be calculated were not paired correctly. I am trying to loop files from 2 folders and perform raster calculation ...
3
votes
1answer
435 views

Creating layers from selection with while loop using PyQGIS?

I am trying to write a short snippet of code to break a shapefile up according to a specific attribute. Here is my code: from qgis.core import * import processing layer = processing.getObject('2012')...
3
votes
2answers
391 views

Creating Python Addin Button?

I want to create a Python AddIn button to execute a specific script. I know how to use the python addIn wizard and add the toolbar I created in my ArcMap. The trouble I am having is writing the script ...
3
votes
1answer
176 views

fTool in pyqgis: Is it possible?

I am doing a work which I need to sample random points for many layers (classification of land use). Then, I'm trying to do a loop with my several layers and applied a functions of random pointos. I ...
3
votes
1answer
271 views

Exit searchCursor loop after first result

I am attempting to join 2 tables together, and the tools in arcmap, such as add field can't do what I want so I tried using python and arcpy. My approach is to use 2 nested loops and find the values ...
3
votes
1answer
132 views

Updating attribute information

I need to write a script that updates the "LOCALITY" field in a feature class if it is empty with the suburb it is in. I have identified the number of properties with select by location and the ...
3
votes
1answer
89 views

Loop and perform loop in order depending on attribute

I have a lot of points in one layer. All of which represent the same type of real world feature. I want to perform a delete identical within XY of each point but in a specific order. (by splitting ...
3
votes
1answer
152 views

Finding Points in Polygons with Matching ID's?

I'm fairly new to using PyQgis, so sorry if this question is basic. I'm working with two vector layers: (layer 1) A series of polygons, each with an ID field specifying what geographic district the ...
3
votes
1answer
385 views

Looping a location-allocation problem in ArcMap's Model Builder

I have developed the model below in which I iterate through a series of values for a variable in the Location-Allocation type of problem. The variable is the number of facilities to solve. The model ...
3
votes
1answer
111 views

Loop over directory with XTools tool

I'm trying to loop through a directory of shp files with an XTool Pro tool via arcpy. My script successfully performs the operation on the first shp file, but then fails on the rest with a 000584 ...
3
votes
1answer
84 views

Keeping the Highest Valued polygon

I have a single polygon feature class that contains large polygons which represent signal strength. Often times these polygons overlap. I dissolve to get multi-part polygons with a value range of 3 ...
3
votes
2answers
799 views

arcpy.SearchCursor loops one time but then does not repeat

The part of the script I'm having trouble with is the arcpy.SearchCursor. The cursor runs 1x and then does not re-run. The goal was to re-retrieve the field value and apply it to the image layout. It ...
3
votes
0answers
536 views

Accelerating python looping process for A-star path finding on DEM surface?

I try to make an A-star Path Finding program base on tile-graph (image raster data as graph) where each pixel values represent as cost and elevation.. In my case, DEM raster data was called by using ...
2
votes
1answer
2k views

Invalid Input Data Error 000368 Running ArcPy tools in for loop

I am attempting to iterate over all the feature classes in a folder and I'm getting the error 000368. The other solutions in on SE were not helpful to me unfortunately, so I'm posting a separate ...
2
votes
2answers
120 views

Update Cursor: Unable to populate specific field

I am attempting to create a loop to recognize the entry/exit point of a pipe to/from a structure by associating it with a North, South, East, or West direction and then populate the corresponding ...
2
votes
1answer
435 views

GDAL utility in Bash for loop (Ubuntu) [closed]

In Windows GDAL terminal (in Windows, GDAL has a specific terminal/prompt) I usually do loops and it works like a charm. What I'm trying to do the same in a Shell terminal in Ubuntu with the ...
2
votes
2answers
8k views

Looping through list of shapefiles to rename them using ArcPy?

I am trying to upgrade a simple script to list all shapefiles in a folder and if necessary in any folders within and then loop through the list of shapefiles and rename them. import arcpy # Set ...
2
votes
2answers
469 views

Debugging Cursor object has no attribute _exit_ from ArcPy?

I am trying to replace NULL values for -999 in a table inside a gdb. I know how to replace the value for individual fields, but get an error when looping through the complete table. import arcpy fc =...
2
votes
2answers
190 views

How to interact layers with a nested loop?

I've dealing with the code below with such a long time. I have to show in a raster image the result of calculating the cost of the electricity for a solar plant. The thing is that I have to interact a ...
2
votes
1answer
103 views

Designing Update Cursor that updates rows found between two values?

I am new to python, and have not successfully coded an Update Cursor. I am unable to understand the documentation. I have a geodatabase table of wells that i have built using python. I now want to ...
2
votes
1answer
2k views

Using Loop for calculating NDVI in R?

I am using MOD09Q1 now and I would like to calculating NDVI whole year data. One year, I have 46 band 1 images and 46 band 2 images. list.files I creating list of band 1 and list of band 2. ...
2
votes
3answers
279 views

Arcpy: Processing multiple files subsequently

I have an indexed dictionary containing files and want to "mosaic" (arcpy.MosaicToNewRaster_management) all files with the same index. The number of files per index range from 1 to about 30. ...