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
5

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 Earth Engine Client vs. Server docs page for a complete discussion. For your simple example, you can use an ee.List() object to accumulate values, and later ...


5

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 code: FieldToUse = "Field" # change this to your field name with the unique values for fc in fcList: uVals = [] # new empty list # loop through each ...


5

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" elif le > 4000: buffer_width = "300 Feet" else: buffer_width = "175 Feet" print le,buffer_width


4

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")


4

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'] with arcpy.da.UpdateCursor(in_table, field_names) as cursor: for row in cursor: row[1] = row[0].split("-")[2].split(".")[0] cursor.updateRow(...


3

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 will exhaust once all raster files are iterated (of course you would get wrong results as the same - the first - raster was used). You should move this line ...


3

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. import arcpy #from arcpy import env #this line can be removed arcpy.env.workspace = r'D:\Documents\Archaeology\Dissertation\Data\GIS\Places_Bounds\Places\...


3

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-processing tools honour selections first all you need to do is select the points of interest and have that selection feed into the Kernel Density tool. So you need to ...


3

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 list. Try- length = [1990, 2016, 3051, 3279, 1855, 3432, 4323, 3016, 4218] buffer_width = [] for le in length: if le < 3000: buffer_width.append("...


3

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.


3

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\Buildings.shp" arcpy.GetCount_management(fc) <Result '9'> arcpy.GetCount_management(fc).getOutput(0) '9' int(arcpy.GetCount_management(fc).getOutput(0)) 9


2

Your rasterlist items include full paths, so when you try to create an output name tx_name you are creating that with the full path. n1992_USA = "C:\\Angela\\OK\\nlcd_1992_30meter_whole (1)\\nlcd_1992_30meter_whole.img" n2001_USA = "C:\\Angela\\OK\\nlcd_2001_landcover_2011_edition_2014_10_10\\nlcd_2001_landcover_2011_edition_2014_10_10\\...


2

The failure reason of your code is because the return() statement is out of the loop, but if you place into the loop, the result will be the same. You need to create a list to store each polygon iterated: # reproducible example library(sp) data(wrld_simpl, package='maptools') # what you have iterate.spdf = function(x){ for(i in 1:nrow(x)){ p = x[i,] ...


2

You don't need a nested loop (and it's written in a wrong way because you will scan your table only once) So. First of all read all the data from the table and sum it up. data = {} with arcpy.da.SearchCursor(table_datei, ["src_FID", "LENGTH"]) as sc: for row in sc: try: data[row[0]] = data[row[0]] + row[1] except KeyError: ...


2

whereclause won't work as written. When writing a compound SQL statement, all of the parts must be valid SQL statements by themselves. Also, your fieldname can't equal 2 distinct values at the same time. To match either of the values, use the OR operator. Two possible solutions are: whereclause = """{} IN (2000, 3000) """.format(arcpy.AddFieldDelimiters(fc,...


2

This does not have to be done in a python script, it can be done simpler by using the calculate field tool as shown below: If you want to run this as python the code would be: arcpy.CalculateField_management("myRaster","crop","cropnumber( !class! )","PYTHON_9.3","""def cropnumber(s):/n if s.find("-1.") != -1:/n return 1/n elif s.find("-2.") != -1 :/n ...


2

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\\Bulk Density\\In Rasters" or: arcpy.env.workspace = "H:/GIS Project/Bulk Density/In Rasters" The backslash is a special character to Python and so strings for ...


2

You are closing your outfile in the loop iteration. Either close it after the loop or use a with statement. Also, you should use .getOutput() to get the actual value from the GetRasterProperties tool. Something like: env.workspace = r"C:\Users\pyb609\Desktop\Updated Files\GIS\Dark\Shapefiles\15M" #Check out the Arcgis Spatial Analyst extension licence ...


2

Some of these points have already been mentioned by others in comments (and you have subsequently fixed some of them already in your updates): your indenting needs fixing (fixed) make sure that your splitext does not have a double 't' (fixed) ensure that your feature dataset ('Brute' or 'Brute_fd'?) exists and has the same coordinate system as the ...


2

Use list slicing with a step to extract the x and ys as separate tuples and the zip function to put them into a list of tuples. >>> coords = (51.901071, 7.543488, 52.002215, 7.692406) >>> coords[0::2] # extract every 2nd element starting from 0 (the first element) (51.901071, 52.002215) >>> coords[1::2] # extract every 2nd ...


2

Use the da.SearchCursor to iterate over each line/row of the profilelines and create a feature layer for each using objectid. Then pass this feature layer to StackProfile. One output folder will also be created for each output table. import arcpy,os WORK_DIRECTORY = r'C:\somefolder' arcpy.env.workspace = WORK_DIRECTORY arcpy.env.overwriteOutput = True ...


2

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 first item of every entry in the big list". bigFC = [itemA[0] for itemA in bigNeighborList] #retrieve the first item subtype = [itemA[1] for itemA in ...


2

Seems like you are passing a list to the read function instead of a single file When you call shp_paste<- paste(input_path, ifile, sep = "") the ifile object can be a list of files, so shp_paste has a length greater than 1. You might change this by changing the code to shp_paste<- paste(input_path, f, sep = "") since you are iterating over files....


1

You can use the in operator, for example: with arcpy.da.UpdateCursor(in_table, field_names) as cursor: for row in cursor: if '1.' in row[0]: row[1] = 1 ... And instead of writing 24 if statements you can use a dictionary: d = {'1.':1, '2.':2, '3.':3} #add all values here with arcpy.da.UpdateCursor(in_table, field_names) as cursor: ...


1

I worked on the problem through the day and came up with the following solution. I hope it will come handy for everyone. # Creating the objects x <- stack() threshold.m <- vector("numeric", 2) auc.m1 <- vector("numeric", 2) l.T1 <- list() l.model <- list() run = 2 for(i in 1:run){ # Creating the k-fold data group.k1 ...


1

I agree with @Spacedman commentaries, I recommend you to read some basic tutorials to know how to handle spatial objects in R. But I have an example of what you want to do. Reproducible example, a raster stack of 100 layers: library(raster) set.seed(123) r <- raster() s1 <- list() for (i in 1:100) { s1[[i]] <- setValues(r, rnorm(n = ncell(r))...


1

The buffer argument in raster::extract is intended for point feature classes, not polygons. You are going to need to create a new polygon feature class, using rgeod::gBuffer, and extract for the new set of buffered polygons. The buffered results should remain ordered to the original polygons so, can just be merged later. If need to do this over multiple ...


1

You can parse your text based on dash (-) to split the text and select the 3rd number to convert it to integer. Try the following python code in your field calculator: def select(f): if f == ' ': return 0 else: txt = f.split("-")[2] digit = int(round(float(txt),0)) return digit The above code assumes all the column ...


1

If you look at the syntax section of the Select tool it explains the parameters of the tool. Parameter 2 is the output feature class (what is you KEY from your dictionary) and parameter 3 is the where clause (what is value from your dictionary). Your output featureclass name is invalid for a geodatabase, it cannot have spaces in it. Suggest you read this ...


1

AS I mentioned in my comment, that after checking the same Model as yours and check different iteration values, a different expression for the field calculator. That everything works perfectly. So I suggest in this case, that the error is a system error (maybe restart ArcMap or restart windows) will help. Also checking field calculator manually will be a ...


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