1

I'm trying to get RemapRange to accept a variable as input for the remap statement. The reason I need to do this is the input is variable based on user input. The reclassify statement in the code block below does not accept this input.

When I check DirRange it outputs [[157,166,1],[166,175,2],[175,184,3],[184,193,2],[193,202,1]]. This assumes Direction = 180

However when I check DirRemap I get [; [; 1; 5; 7; ,; 1; 6; 6; ,; 1; ]; ,; [; 1; 6; 6; ,; 1; 7; 5; ,; 2; ]; ,; [; 1; 7; 5; ,; 1; 8; 4; ,; 3; ]; ,; [; 1; 8; 4; ,; 1; 9; 3; ,; 2; ]; ,; [; 1; 9; 3; ,; 2; 0; 2; ,; 1; ]; ]

How do I get Remap to give the correct value or get Reclassify to accept the input?

import arcpy
from arcpy.sa import *

Direction = arcpy.GetParameterAsText(0)
Dirout = arcpy.GetParameterAsText(1)

DirMin = Direction - 23
DirMax = Direction + 22

if DirMin <= 0:
 DirMin = DirMin + 360
else:
 DirMin = DirMin

if DirMax >= 360:
 DirMax = DirMax - 360
else:
 DirMax = DirMax

Part1 = DirMin + 9
if Part1 >= 360:
 Part1 = Part1 - 360

Part2 = Part1 + 9
if Part2 >= 360:
 Part2 = Part2 - 360

Part3 = Part2 + 9
if Part3 >= 360:
 Part3 = Part3 - 360

Part4 = Part3 + 9
if Part4 >= 360:
 Part4 = Part4 - 360

Cat1 = "[" + str(DirMin) + "," + str(Part1) + ",1],"
Cat2 = "[" + str(Part1) + "," + str(Part2) + ",2],"
Cat3 = "[" + str(Part2) + "," + str(Part3) + ",3],"
Cat4 = "[" + str(Part3) + "," + str(Part4) + ",2],"
Cat5 = "[" + str(Part4) + "," + str(DirMax) + ",1]"
DirRange = "[" + Cat1 + Cat2 + Cat3 + Cat4 + Cat5 + "]"

DirRemap = RemapRange(DirRange)
DRaster = arcpy.sa.Reclassify(Dirout, "Value", DirRemap, "NODATA")
5
  • I've tried taking the square brackets off each end and adding them in the Remap. Doesn't work then either. Commented Jul 5, 2017 at 20:14
  • Try giving it an actual list not just a string that looks like a list: DirRemap = arcpy.sa.RemapRange( [[ DirMin,Part1,1],[Part1,Part2,2]...]) like the example resources.arcgis.com/en/help/main/10.2/index.html#//… Commented Jul 5, 2017 at 20:42
  • I am attempting to do so now. I am trying to avoid this method though as the data is Directional data. As such it has to accommodate the range wrapping around if the middle value is close to 360 or 0. Not included in the code block above is a section built of if statements to account for this. I'd like to not have to rewrite all of it. Commented Jul 5, 2017 at 20:52
  • @MichaelStimson The method you provided worked. I'm working on recoding my if section. Thanks very much. Commented Jul 5, 2017 at 21:39
  • 1
    No problems. Can you answer your own question with your updated code for future users who encounter the same problem thanks. Commented Jul 5, 2017 at 21:44

1 Answer 1

1

Updated Code below. I needed to use real lists not strings that looked like lists. Credit to MichaelStimson for the solve.

import arcpy
from arcpy.sa import *

Direction = arcpy.GetParameterAsText(0)
Dirout = arcpy.GetParameterAsText(1)

DirMin = Direction - 23
DirMax = Direction + 22

if DirMin <= 0:
 DirMin = DirMin + 360
else:
 DirMin = DirMin

if DirMax >= 360:
 DirMax = DirMax - 360
else:
 DirMax = DirMax

Part1 = DirMin + 9
if Part1 >= 360:
 Part1 = Part1 - 360

Part2 = Part1 + 9
if Part2 >= 360:
 Part2 = Part2 - 360

Part3 = Part2 + 9
if Part3 >= 360:
 Part3 = Part3 - 360

Part4 = Part3 + 9
if Part4 >= 360:
 Part4 = Part4 - 360

DirRange = RemapRange([[DirMin,Part1,1],[Part1,Part2,2],[Part2,Part3,3],[Part3,Part4,2],[Part4,DirMax,1]])

DRaster = arcpy.sa.Reclassify(Dirout, "Value", DirRange, "NODATA")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.