I'm trying to change my slope map's labels and colors to the specific ones I want which are shown in the code, but when I run this script it produces an AttributeError that doesn't make sense to me since I imported arcpy into my script.
Code:
def main():
import arcpy
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
arcpy.env.workspace = "C:\\Users\\user\\OneDrive\\Documents\\ArcGIS\\ArcMap_Folder"
inRaster = "USGS_13_n37w082_20220512.tif"
outSlope = Slope(inRaster, "PERCENT_RISE")
outSlope.save("C:\\Users\\user\\OneDrive\\Documents\\ArcGIS\\ArcMap_Folder\\slope2.tif")
myRemapRange = RemapRange([[0, 3.99, 1], [4, 9.99, 2], [10, 15.99, 3], [16, 30.99, 4], [31, 60.99, 5], [61, 999999, 6]])
outReclassRR = Reclassify(outSlope, "VALUE", myRemapRange,"NODATA" )
outReclassRR.save("C:\\Users\\user\\OneDrive\\Documents\\ArcGIS\\ArcMap_Folder\\reclass2.tif")
arcpy.management.MakeRasterLayer_management("outReclassRR", "outReclassRR_layer")
arcpy.management.ApplySymbologyFromLayer(outReclassRR, reclass_copy.lyr)
if __name__ == '__main__':
main()
Error:
Runtime error
Traceback (most recent call last):
File "<string>", line 24, in <module>
File "<string>", line 17, in main
AttributeError: 'module' object has no attribute 'MakeRasterLayer_management'
1 Answer 1
arcpy
tools can either be used from their module or are aliased so they can be used from the top level.
From the management
module:
arcpy.management.MakeRasterLayer
Or by the top-level alias:
arcpy.MakeRasterLayer_management
-
Thanks! The first way worked for me! Apparently the "_management" section was what was causing the issue.Darell– Darell2022年06月27日 12:49:51 +00:00Commented Jun 27, 2022 at 12:49
-
@Darell no,
arcpy.*management*.MakeRasterLayer_*management*
is what won't work.arcpy.MakeRasterLayer_management
will work as well asarcpy.management.MakeRasterLayer
user2856– user28562022年06月27日 13:24:50 +00:00Commented Jun 27, 2022 at 13:24 -
Ohh my bad, I read that wrong. Yes, that's true. arcpy.management.MakeRasterLayer is what worked for me.Darell– Darell2022年06月27日 13:38:36 +00:00Commented Jun 27, 2022 at 13:38
Explore related questions
See similar questions with these tags.