Hello,
So I've been racking my brain as to why this isn't working. Basically I have a script to process LiDAR .las data and I have a step to "Change LAS Class Code". And eventually I want to have this in a GP Script Tool or as a Notebook where my coworker(s) just need to put in the inputs.
Per the documentation for the Change LAS Class Code tool, the input format for "class_codes" can be
For example, a current class code of 5 can be changed to 25 by specifying "5 2" or [[5, 2]]. Likewise, a change to the synthetic class flag can be made by adding the keyword for the desired modification ("5 2 SET" or [[5, 2, "SET"]]). Multiple changes can be specified as a semicolon-delimited string (for example, "5 2; 8 3; 1 4") or as a list of lists (for example, [[5, 2], [8, 3], [1, 4]]). https://pro.arcgis.com/en/pro-app/latest/tool-reference/3d-analyst/change-las-class-codes.htm
But when I put in the Input() or arcpy.GetParameterAsText to use as a variable, in the same way the documentation has the change class codes formatted, the script will fail. But when I hard code it into the Geoprocessing step (ex: class_code = [[1,0]]) it works just fine.
Example Code
inputClassCodeChange = input("..."): [[0,1]]
arcpy.ddd.ChangeLasClassCodes(in_las_dataset = lasdsets, class_codes = inputClassCodeChange)
Solved! Go to Solution.
If you want to keep the [[1,2]] format, you can parse it out with json.
import json
inputClassCodeChange = input()
rawString = inputClassCodeChange
rawStringType = type(rawString)
# String to list
res = json.loads(rawString)
resType = type(res)
python 'input' uses strings
did you try the "5 2; 8 3; 1 4" option and parse the input accordingly instead?
I tried that as classcode = input("5 2; 8 3; 1 4"), then arcpy.ddd.ChangeLasClassCodes(in_las_dataset = lasdsets, class_codes = classcode), but it would fail.
If you mean like parsing out each individual class change then putting it in a list for the script to loop through each one. I started down that path, but the documentation makes it seem like I should just be able to insert that string, as is, in the parameters and it should work.
Thanks.
teste
teste2
If you want to keep the [[1,2]] format, you can parse it out with json.
import json
inputClassCodeChange = input()
rawString = inputClassCodeChange
rawStringType = type(rawString)
# String to list
res = json.loads(rawString)
resType = type(res)
Thank you!
I have gotten this to work (or at least not fail)!
One more library of tools I need to learn...