7 votes

Append element to an array in Google Earth Engine

Your code is returning "unexpected" results because you are mixing client-side Javascript control structures with server-side Earth Engine methods. In general, you should avoid doing this. Review the ...
Tyler Erickson's user avatar
7 votes

Looping every features pair with PyQGIS

You can use zip and indexing: layer = iface.activeLayer() featurelist = [f for f in layer.getFeatures()] #List all features for featurepair in zip(featurelist[::2], featurelist[1::2]): f1, f2 = ...
BERA's user avatar
  • 71.2k
6 votes
Accepted

How to put this in a for-loop? I'm recreating ArcMap's 'Tabulate Area' tool in Python

loc primarily "label of the index" based. So, for the first iteration gdf1['NAME_2'][0] returns muni1. Then you get error using gdf1.loc['muni1'], because Pandas interprets 'muni1'('Abad') ...
Kadir Şahbaz's user avatar
6 votes
Accepted

What does "del aprx" at the end of Python code do?

In Python del means delete the object which would release memory and file locks. So if you saw del abc,bob,x this would mean delete the objects abc, bob and x, what ever they are. aprx is the commonly ...
Hornbydd's user avatar
  • 43.2k
5 votes

Using IF statement in FOR loop?

Your code is correct, your indent is misplaced. Try this: length = [1990, 2016, 3051, 3279, 1855, 3432, 4323, 3016, 4218] for le in length: if le < 3000: buffer_width = "75 Feet" ...
Delonix R.'s user avatar
5 votes

For-Looping through Bookmarks in Python Script tool?

you need to add the export function inside the for loop, indent the line for bkmk in bkmks: mf.zoomToBookmark(bkmk) lyt.exportToPDF(r"C:\arcGIS_Shared\Exports" + "\\" + bkmk.name + ".pdf")
NULL.Dude's user avatar
  • 2,131
5 votes

How to run for loop with unique values

Although Hornbydd is absolutely correct (+1 for that by the way), the first part of the question is to loop through all the unique values in a field.. this snippet should be usable in your existing ...
Michael Stimson's user avatar
5 votes
Accepted

Getting same result with less code with PythonWin ArcPy?

Use a dictionary: The main operations on a dictionary are storing a value with some key and extracting the value given the key. d = {1:"Lightning", 2:"Equipent use", ... } with arcpy.da....
BERA's user avatar
  • 71.2k
5 votes
Accepted

For loop for access to a directory files in ArcPy

Here are four approaches. The first uses the arcpy Walk function. The second, third, and fourth approaches use built-in python modules. The fourth approach is the one you provided. Here are the time ...
Aaron's user avatar
  • 51.6k
5 votes
Accepted

Reducing number of for loops in ArcPy code

I've put some comments inline, but the main one is - don't keep reopening a file for appending, just do it once. You might also want to consider using more descriptive variable names. import arcpy ...
user2856's user avatar
  • 65.3k
5 votes

Looping every features pair with PyQGIS

In most latest QGIS versions like QGIS 3.34.1 Prizren​, it should come with the pairwise() function from the itertool module. Since Python 3.10. # imports from itertools import pairwise from qgis.core ...
Taras's user avatar
  • 32.7k
4 votes
Accepted

Using LIKE in a For Loop with UpdateCursor

I would isolate the class you are after rather than searching for it. Then, simply assign row[1] that isolated value. For example: in_table = 'l12wm_agsup02.img' field_names = ['Class_Name', 'crop'] ...
Aaron's user avatar
  • 51.6k
4 votes
Accepted

Using 2 different for loops in Python, skips second process

At the time of you listing features: inputfc2 = arcpy.ListFeatureClasses("*.clip"). They dont exist, you create them later. And shouldnt "*.clip" be "*_clip"? So feature ...
BERA's user avatar
  • 71.2k
4 votes
Accepted

Copy multiple shapefiles that intersect a polygon to a new location

I see the very last line as error-ing out as inpfile is not defined anywhere. You also didn't store the selection set as a variable or test whether the returned selection layer had any records before ...
John's user avatar
  • 607
3 votes

How to run for loop with unique values

If you read the help file for this tool and look at the syntax section what does it takes as input? A Feature Layer. Unlike a Feature Class, you can do selections on Feature Layers. As all geo-...
Hornbydd's user avatar
  • 43.2k
3 votes
Accepted

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

The problem is that you re-define rasNumber = 1 in each iteration, so you will be accessing the same raster in each iteration. This would not result in infinite loop though, because the for loop ...
Alex Tereshenkov's user avatar
3 votes

Looping script with Zonal Statistics

I corrected your code for you. After each line you find a comment to show you what was corrected. Also reading about about for loops, the range and len functions can help you understand the changes. ...
LMB's user avatar
  • 1,166
3 votes

Using IF statement in FOR loop?

Your buffer_width being a variable is getting changed on every iteration of your loop. If you want the the value of buffer width for each element in length, you'll need to define buffer_width as a ...
nash's user avatar
  • 1,976
3 votes
Accepted

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

Try replacing: arcpy.env.workspace = "H:\GIS Project\Bulk Density\In Rasters" with: arcpy.env.workspace = r"H:\GIS Project\Bulk Density\In Rasters" or: arcpy.env.workspace = "H:\\GIS Project\\...
PolyGeo's user avatar
  • 65.1k
3 votes
Accepted

Error in reprojecting raster from WGS 84 to GDA 94

You seem to be using the Project tool which is for vector data. You need to use the Project Raster tool which is for rasters.
user2856's user avatar
  • 65.3k
3 votes
Accepted

For loop within for loop with ArcPy cursor?

Change: f=arcpy.GetCount_management(TL) To: f=int(arcpy.GetCount_management(TL).getOutput(0)) Without getOutput, f is a Result object, not the actual count. Example: import arcpy fc = r"C:\Test\...
BERA's user avatar
  • 71.2k
3 votes
Accepted

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

The problem is in the fact that what you wrote is different from what you think you wrote. The comment says "retrieve the first item", but what really happens is "build a list that consists of the ...
ralien's user avatar
  • 196
3 votes

Select by location using for-loop in Python Terminal

If your end goal is to create a separate shapefile for each river and all its tributaries. You could try this approach using a recursive query (@Taras check this out :) ) I am assuming the main ...
M Bain's user avatar
  • 1,997
3 votes
Accepted

Accumulate selections by expression using a for loop (Pyqgis)

The reason why your selections are being overwritten on each iteration is because you passed QgsVectorLayer.SetSelection for the SelectBehaviour parameter. This sets a new selection each time, ...
Ben W's user avatar
  • 21.2k
3 votes
Accepted

Using for loop to print last messages from multiple processes?

You could use Result.GetMessage/GetMessages, instead of arcpy.GetMessage/GetMessages For example: import arcpy def log(result): # Last message print(result.getMessage(result....
user2856's user avatar
  • 65.3k
3 votes
Accepted

For loop not recognizing writeLAS command

There is no argument filename in writeLAS(). The signature of writeLAS() is writeLAS(las, file)
JRR's user avatar
  • 9,264
3 votes
Accepted

Including float value in loop processing of Surface Volume tool using ArcMap ModelBuilder

An alternative method is to create a table and store your floats in that, 1 row per float value. Then use the Iterate Field Value iterator to drive your model. But I think @user2856 has the simplest ...
Hornbydd's user avatar
  • 43.2k
3 votes

Including float value in loop processing of Surface Volume tool using ArcMap ModelBuilder

You can use the Iterate Multivalue tool and add a list of floats:
user2856's user avatar
  • 65.3k
3 votes
Accepted

Spatial join features from different geodatabases

As per @Vince's comment, you need to fully qualify the paths to your feature classes by prepending the appropriate path the to file geodatabase they come from. For example, by using a list ...
Anna Forrest's user avatar
3 votes
Accepted

Naming raster layers in a rasterstack with the same name

The raster package is very strict about names, it seems, and really doesn't want you to have two layers in a stack with the same names. Weirdly you can make a plain R list with two elements with the ...
Spacedman's user avatar
  • 63.2k

Only top scored, non community-wiki answers of a minimum length are eligible