0

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'
0

1 Answer 1

2

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
3
  • Thanks! The first way worked for me! Apparently the "_management" section was what was causing the issue.
    – Darell
    Jun 27 at 12:49
  • @Darell no, arcpy.*management*.MakeRasterLayer_*management* is what won't work. arcpy.MakeRasterLayer_management will work as well as arcpy.management.MakeRasterLayer
    – user2856
    Jun 27 at 13:24
  • Ohh my bad, I read that wrong. Yes, that's true. arcpy.management.MakeRasterLayer is what worked for me.
    – Darell
    Jun 27 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.