<?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: Where is the syntax error in this python toolbox? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/where-is-the-syntax-error-in-this-python-toolbox/m-p/1072414#M61490</link>
    <description>&lt;P&gt;Interesting. On my machine I needed to a) use a full path and not a map layer, and b) disable the `callback` options. I tried with both default Pro python and a clone env (created using File &amp;gt;&amp;gt; Python &amp;gt;&amp;gt; Manage).&lt;/P&gt;&lt;P&gt;I think there might be something screwy with my install though, because a test python toolbox with nothing in it but the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/geoprocessing_and_python/controlling-the-progress-dialog-box.htm" target="_self"&gt;demo Set Progressor&lt;/A&gt; takes over 4 minutes to run, but the actual tool execution part is only 18 seconds.&lt;/P&gt;</description>
    <pubDate>Fri, 25 Jun 2021 00:23:23 GMT</pubDate>
    <dc:creator>MattWilkie1</dc:creator>
    <dc:date>2021-06-25T00:23:23Z</dc:date>
    <item>
      <title>Where is the syntax error in this python toolbox?</title>
      <link>https://community.esri.com/t5/python-questions/where-is-the-syntax-error-in-this-python-toolbox/m-p/1072270#M61484</link>
      <description>&lt;P&gt;ArcGIS Pro tells me there is a syntax error when I run the single tool in this toolbox. Contrary to what the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/tool-reference/tool-errors-and-warnings/001001-010000/tool-errors-and-warnings-00976-01000-000989.htm" target="_self"&gt;doc page for ERROR 00989&lt;/A&gt; says it does not report what or where the error is. I can't find it visually and&amp;nbsp; `python -m compileall ImageRepo.pyt` says it's fine. Can any of you see what is wrong?&lt;/P&gt;&lt;P&gt;I'm using ArcGIS Pro v2.8.1.&lt;/P&gt;&lt;P&gt;The toolbox: &lt;A href="https://gist.github.com/maphew/0bae6f3005ca129f2a9566e343cf37d7" target="_blank"&gt;https://gist.github.com/maphew/0bae6f3005ca129f2a9566e343cf37d7&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MattWilkie1_0-1624564437194.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/16917i660A2F69A86ED457/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MattWilkie1_0-1624564437194.png" alt="MattWilkie1_0-1624564437194.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;GdalToCog&lt;BR /&gt;=====================&lt;BR /&gt;Parameters&lt;BR /&gt;&lt;BR /&gt;Input Raster Finlayson124_SP6_13Sep2017_150cm_pro_nd.tif&lt;BR /&gt;Output Raster D:\work\ImgRepo\2021-06-10\pro_pyt_to_cog.tif&lt;BR /&gt;=====================&lt;BR /&gt;Messages&lt;BR /&gt;&lt;BR /&gt;ERROR 000989: Python syntax error: within script T:\ENV.558\ImageRepo.pyt&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jun 2021 19:58:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-is-the-syntax-error-in-this-python-toolbox/m-p/1072270#M61484</guid>
      <dc:creator>MattWilkie1</dc:creator>
      <dc:date>2021-06-24T19:58:39Z</dc:date>
    </item>
    <item>
      <title>Re: Where is the syntax error in this python toolbox?</title>
      <link>https://community.esri.com/t5/python-questions/where-is-the-syntax-error-in-this-python-toolbox/m-p/1072327#M61489</link>
      <description>&lt;P&gt;It is working fine for me in Pro 2.8.1 when I specify an input tif file stored on disk. I can make it error when choosing a tif file from my map, however the error is different (No such file or directory). I think GDAL cannot resolve the path when running it this way. In your parameters, the input file doesn't have a path - maybe try passing it the full path and filename. Does it error on other input files?&lt;/P&gt;&lt;P&gt;The other option is that something messed up when creating your local copy of the script or maybe some issue with your Python environment? Are you using the default environment?&lt;/P&gt;&lt;P&gt;This works:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# -*- coding: utf-8 -*-
import arcpy
from osgeo import gdal
gdal.UseExceptions()

class Toolbox(object):
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "Toolbox"
        self.alias = "toolbox"

        # List of tool classes associated with this toolbox
        self.tools = [Tool]

class Tool(object):
    def __init__(self):
        """Gdal to Cloud Geotiff translator."""
        self.label = "GdalToCog"
        self.description = "Compress a raster to Cloud Optimized Geotiff, using the options that work best for our imagery at Environment Yukon"
        self.canRunInBackground = False

    def getParameterInfo(self):
        """Define parameter definitions"""
        params = []
        params += [arcpy.Parameter(
            displayName = "Input Raster",
            name = "in_raster",
            datatype="GPRasterLayer",
            parameterType="Required",
            direction="Input"
            )]
        params += [arcpy.Parameter(
            displayName="Output Raster",
            name="out_raster",
            datatype="DERasterDataset",
            parameterType="Required",
            direction="Output"
            )]
        return params

    def isLicensed(self):
        """Set whether tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        return

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter.  This method is called after internal validation."""
        return

    def execute(self, parameters, messages):
        """Source code (adapted from 'gdal-to-cog.py')"""
        
        infile  = parameters[0].valueAsText
        outfile = parameters[1].valueAsText

        gdal.SetConfigOption('GDAL_CACHEMAX','30%')
        options = ["COMPRESS=ZSTD", "PREDICTOR=YES", "LEVEL=17", "BIGTIFF=YES",
            "NUM_THREADS=ALL_CPUS",]

        def progress_cb(complete, message, cb_data):
            '''Emit progress report in numbers for 10% intervals and dots for 3%'''
            if int(complete*100) % 10 == 0:
                print(f'{complete*100:.0f}', end='', flush=True)
            elif int(complete*100) % 3 == 0:
                print(f'{cb_data}', end='', flush=True)

        arcpy.AddMessage(f'Translating {infile} to {outfile}')
        gdal.Translate(outfile, infile, creationOptions=options, 
            format="COG",
            callback=progress_cb,
            callback_data='.'
            )
        return&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jun 2021 21:15:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-is-the-syntax-error-in-this-python-toolbox/m-p/1072327#M61489</guid>
      <dc:creator>Tim_McGinnes</dc:creator>
      <dc:date>2021-06-24T21:15:36Z</dc:date>
    </item>
    <item>
      <title>Re: Where is the syntax error in this python toolbox?</title>
      <link>https://community.esri.com/t5/python-questions/where-is-the-syntax-error-in-this-python-toolbox/m-p/1072414#M61490</link>
      <description>&lt;P&gt;Interesting. On my machine I needed to a) use a full path and not a map layer, and b) disable the `callback` options. I tried with both default Pro python and a clone env (created using File &amp;gt;&amp;gt; Python &amp;gt;&amp;gt; Manage).&lt;/P&gt;&lt;P&gt;I think there might be something screwy with my install though, because a test python toolbox with nothing in it but the &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/geoprocessing_and_python/controlling-the-progress-dialog-box.htm" target="_self"&gt;demo Set Progressor&lt;/A&gt; takes over 4 minutes to run, but the actual tool execution part is only 18 seconds.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jun 2021 00:23:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/where-is-the-syntax-error-in-this-python-toolbox/m-p/1072414#M61490</guid>
      <dc:creator>MattWilkie1</dc:creator>
      <dc:date>2021-06-25T00:23:23Z</dc:date>
    </item>
  </channel>
</rss>

