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'
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jun 25, 2022 at 2:02
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
answered Jun 25, 2022 at 2:09
3
  • Thanks! The first way worked for me! Apparently the "_management" section was what was causing the issue. Commented Jun 27, 2022 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 Commented 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. Commented Jun 27, 2022 at 13:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.