POST
|
Did you ever find a way to do this? I would like to do this too... it's maddening having the map move around unintentionally all the time!
... View more
05-12-2020
09:01 AM
|
0
|
0
|
522
|
POST
|
I figured out how to get the results I wanted. After trying several different ways to format the Value field in the expression, I abandoned this approach and used map algebra instead, on someone's advice. This doesn't require adding and calculating a field, or using Lookup. The final code that seems to be working is: for inRaster in arcpy.ListFiles("*.tif"): inRastName = os.path.splitext(inRaster)[0] outRastName = inRastName + "f.tif" raster1 = arcpy.Raster(inRaster) rasterMax = raster1.maximum outRaster = Int(((raster1 / rasterMax) *10) +0.5) outRaster.save("...path/SpeciesR07_Frag1/" + outRastName) A couple of tips I learned in doing this: use int for values and Int for rasters (capitalization matters!) and... adding 0.5 to the raster rounds the float values to integers, instead of just lopping off the decimals.
... View more
04-28-2020
09:43 PM
|
0
|
0
|
749
|
POST
|
Trying to build the expression string: ( !Value! / num ) * 10
... View more
04-27-2020
11:38 AM
|
0
|
1
|
749
|
POST
|
Newbie here. I've been trying to solve this for weeks and have searched and tried many suggestions from this site and still can't get this to work correctly. I'm trying to use a derived value (max) from the Value field of a raster and use it in a calculation on each row of that field, and put the results in a new field (then use that field as a lookup to create a new integer raster). I can do this easily in desktop ArcGIS, but have several hundred rasters to process, so am trying to use an arcpy for loop. It seems, if I specify the calculation expression outside of the For loop, I can get it to run a calculation on each row in the field, but can't get the derived value, using all the values in the field, into the calculation. If I define the expression inside the for loop (as below), it uses the constant value (max), but then won't iterate through each row in the Value field. (This way the output rasters have only two values: 0 and 10. The other way, they have the original raster values multiplied by whatever I set the maxValue variable to initially). Can someone tell me what I'm doing wrong? import arcpy import os from arcpy import env from arcpy.sa import * arcpy.CheckOutExtension("Spatial") # Set environment settings env.workspace = "...path/SpeciesR07_1" # Set local variables fieldName = "Frag" # Processes: AddField, CalculateField, LookUp for inRaster in arcpy.ListFiles("*.tif"): inRastName = os.path.splitext(inRaster)[0] outRastName = inRastName + "f.tif" maxValue = 0 values = [row[0] for row in arcpy.da.SearchCursor(inRaster, "Value")] maxValue = max(values) expression = "(!Value! / {}".format(maxValue) + ") *10" arcpy.AddField_management(inRaster, fieldName, "SHORT") arcpy.CalculateField_management(inRaster, fieldName, expression, "PYTHON") lookupRast = Lookup(inRaster, fieldName) lookupRast.save("...path/SpeciesR07_Frag1/" + outRastName)
... View more
04-27-2020
09:46 AM
|
0
|
4
|
872
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|