<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Arcpy &amp;quot;Slope&amp;quot; Function does not work. in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-quot-slope-quot-function-does-not-work/m-p/1360766#M76370</link>
    <description>&lt;P&gt;I found that the error "KeyError: 'METRE' only appears when using the 'arcpy.sa.Slope()' function from the Spatial Analyst toolbox. When using the slope function from the 3D-Analyst toolbox it works:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;try:
    
    for raster in arcpy.ListRasters():
        if "DTM_mask" in raster:
            raster_name = raster
    
            arcpy.ddd.Slope(
                in_raster= raster,
                out_raster=f"{raster}_slope",
                output_measurement="DEGREE",
                z_factor=1,
                method="PLANAR",
                z_unit="METER",
                analysis_target_device="GPU_THEN_CPU"
            )

except Exception as e:
    print(f'Error: {str(e)}')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Still, when I use the function manually, no matter from the Spatial Analyst or 3D-Analyst toolbox it works without any problems. Also the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/spatial-analyst/slope.htm" target="_self"&gt;documentation&lt;/A&gt; specifies a 'Slope()' function, which seems to does not even exist (I'm using ArcGIS Pro 3.1.1):&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Error: name 'Slope' is not defined&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 14 Dec 2023 08:25:44 GMT</pubDate>
    <dc:creator>MikeMoehlmann</dc:creator>
    <dc:date>2023-12-14T08:25:44Z</dc:date>
    <item>
      <title>Arcpy "Slope" Function does not work.</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-quot-slope-quot-function-does-not-work/m-p/1350702#M75277</link>
      <description>&lt;P&gt;I'm using ArcGIS Pro 3.1.1&lt;/P&gt;&lt;P&gt;I'm encountering an issue when I try to run the "Slope" tool in arcpy. First of all, when I run the tool manually the tool runs without any problems. But in Arcpy, it does not work, even if I use the code from "Send To Python Window" from the manual execution.&lt;BR /&gt;&lt;BR /&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;out_raster = arcpy.sa.Slope(
    in_raster="dtm_mask",
    output_measurement="DEGREE",
    z_factor=1,
    method="PLANAR",
    z_unit="METER",
    analysis_target_device="GPU_THEN_CPU"
)
out_raster.save(r"C:\Users\Desktop\slope_test")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Resulting in the following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Traceback (most recent call last):
  File "&amp;lt;string&amp;gt;", line 1, in &amp;lt;module&amp;gt;
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\sa\Functions.py", line 8685, in Slope
    return Wrapper(
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\sa\Utils.py", line 55, in swapper
    result = wrapper(*args, **kwargs)
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\sa\Functions.py", line 8632, in Wrapper
    z_meters_per_unit = linear_unit_factors[zlu]
KeyError: 'METRE'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So it says that there is a KeyError with "METRE", but I defined in the "z_unit" "METER".&lt;BR /&gt;How can I solve this problem? Is there maybe something wrong in the source code of the "slope" function?&lt;/P&gt;</description>
      <pubDate>Fri, 17 Nov 2023 11:56:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-quot-slope-quot-function-does-not-work/m-p/1350702#M75277</guid>
      <dc:creator>MikeMoehlmann</dc:creator>
      <dc:date>2023-11-17T11:56:19Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy "Slope" Function does not work.</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/arcpy-quot-slope-quot-function-does-not-work/m-p/1360766#M76370</link>
      <description>&lt;P&gt;I found that the error "KeyError: 'METRE' only appears when using the 'arcpy.sa.Slope()' function from the Spatial Analyst toolbox. When using the slope function from the 3D-Analyst toolbox it works:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;try:
    
    for raster in arcpy.ListRasters():
        if "DTM_mask" in raster:
            raster_name = raster
    
            arcpy.ddd.Slope(
                in_raster= raster,
                out_raster=f"{raster}_slope",
                output_measurement="DEGREE",
                z_factor=1,
                method="PLANAR",
                z_unit="METER",
                analysis_target_device="GPU_THEN_CPU"
            )

except Exception as e:
    print(f'Error: {str(e)}')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Still, when I use the function manually, no matter from the Spatial Analyst or 3D-Analyst toolbox it works without any problems. Also the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/spatial-analyst/slope.htm" target="_self"&gt;documentation&lt;/A&gt; specifies a 'Slope()' function, which seems to does not even exist (I'm using ArcGIS Pro 3.1.1):&lt;/P&gt;&lt;LI-CODE lang="python"&gt;Error: name 'Slope' is not defined&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Dec 2023 08:25:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/arcpy-quot-slope-quot-function-does-not-work/m-p/1360766#M76370</guid>
      <dc:creator>MikeMoehlmann</dc:creator>
      <dc:date>2023-12-14T08:25:44Z</dc:date>
    </item>
  </channel>
</rss>

