<?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 looping through SQL, speed in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/looping-through-sql-speed/m-p/242766#M8285</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I built this model that creates a raster water mask from a SAR image.&amp;nbsp;&amp;nbsp; It take the image, filter it and then extracts a raster water mask (0,1) based on a specific threshold.&amp;nbsp; A processing mask can be used as an option to limit the processing to an area of interest.&amp;nbsp;&amp;nbsp; The raster water mask is then filtered using a mode filter to remove small isolated pixels.&amp;nbsp;&amp;nbsp; The model runs as a tool and prompts the user for an input/ ouput filename, processing mask (optional) and sql expression (default given).&amp;nbsp; See exported model to script below...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Questions:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1) I exported the model to a script and&amp;nbsp; would like to add a looping functionality based on the sql expression.&amp;nbsp; The expression is as follows, "Value &amp;gt; 0 AND Value &amp;lt; 10".&amp;nbsp;&amp;nbsp; For example, upon input of a theshold of 10 I would like to produce a mask with a threshold of 9 (-1) and 11 (+1).&amp;nbsp; Therefore that script would be producing 3 raster mask every time it ran.&amp;nbsp; Ideally it would also name the ouput files automatically based on the threshold.&amp;nbsp;&amp;nbsp;&amp;nbsp; Any advice on how to do this??&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Note:&amp;nbsp; As a temporary solution I used the batching functionality in the model.&amp;nbsp; It works well but I think it leaves a bit too much room for errors.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2) The first image filter is very slow (Focal statistics, 3x3 median).&amp;nbsp; Test were ran with the toolbox tool being the slowest&amp;nbsp; (24min), desktop command line (7 min) and arc command line being much faster (don't have the numbers).&amp;nbsp;&amp;nbsp; Any explanation for this difference is speed and any suggestion on how to speed it up?&amp;nbsp;&amp;nbsp;&amp;nbsp; Do script tools run faster than model tools?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;3) While I am at it, I have another question.&amp;nbsp;&amp;nbsp; Is there any functionality in Model builder to linearly scale an image from 16bit to 8 bit?&amp;nbsp;&amp;nbsp; I did not find a function for this but maybe it does exist?&amp;nbsp; Otherwise I would need to find the min and max from and image and somehow use a formula to scale the image.&amp;nbsp;&amp;nbsp; This will be my next challenge!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am new to model builder and scripting with Python.&amp;nbsp;&amp;nbsp; Thanks for any advice on these issues.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Alice&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;----------------------------------------------------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# ---------------------------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# ExtractWaterMask.py&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Created on: Tue May 18 2010 01:29:25 PM&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#&amp;nbsp;&amp;nbsp; (generated by ArcGIS/ModelBuilder)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Usage: ExtractWaterMask &amp;lt;Input_8bit_scaled_SAR_image&amp;gt; &amp;lt;Processing_Mask&amp;gt; &amp;lt;Water_Threshold&amp;gt; &amp;lt;Output_8bit_water_mask&amp;gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# ---------------------------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Import system modules&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import sys, string, os, arcgisscripting&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Create the Geoprocessor object&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp = arcgisscripting.create()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Check out any necessary licenses&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.CheckOutExtension("spatial")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Load required toolboxes...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Set the Geoprocessing environment...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.mask = ""&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Script arguments...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Input_8bit_scaled_SAR_image = sys.argv[1]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Processing_Mask = sys.argv[2]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Water_Threshold = sys.argv[3]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if Water_Threshold == '#':&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Water_Threshold = "Value &amp;gt; 0 AND Value &amp;lt; 11" # provide a default value if unspecified&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Output_8bit_water_mask = sys.argv[4]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if Output_8bit_water_mask == '#':&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Output_8bit_water_mask = "D:\\EMERG\\test\\Water_Mask" # provide a default value if unspecified&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Local variables...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Con_focalst_1 = "D:\\EMERG\\test\\Con_filter_31"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Input_true_raster_or_constant_value__3_ = "1"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Input_false_raster_or_constant_value__3_ = "0"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;filter_scale1__2_ = "D:\\EMERG\\R1_21mars10\\mosaic\\filter_scale1"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;filter_scale1__3_ = "D:\\EMERG\\R1_21mars10\\mosaic\\filter_scale1"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;filter_33 = "D:\\EMERG\\test\\filter_33"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Focal Statistics (3x3 median)...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.FocalStatistics_sa(Input_8bit_scaled_SAR_image, filter_33, "Rectangle 3 3 CELL", "MEDIAN", "DATA")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Con...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;tempEnvironment0 = gp.mask&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.mask = ""&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.Con_sa(filter_33, Input_true_raster_or_constant_value__3_, Con_focalst_1, Input_false_raster_or_constant_value__3_, Water_Threshold)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.mask = tempEnvironment0&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Focal Statistics (5x5 Mode)...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.FocalStatistics_sa(Con_focalst_1, Output_8bit_water_mask, "Rectangle 5 5 CELL", "MAJORITY", "DATA")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 18 May 2010 16:46:41 GMT</pubDate>
    <dc:creator>AliceDeschamps</dc:creator>
    <dc:date>2010-05-18T16:46:41Z</dc:date>
    <item>
      <title>looping through SQL, speed</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/looping-through-sql-speed/m-p/242766#M8285</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I built this model that creates a raster water mask from a SAR image.&amp;nbsp;&amp;nbsp; It take the image, filter it and then extracts a raster water mask (0,1) based on a specific threshold.&amp;nbsp; A processing mask can be used as an option to limit the processing to an area of interest.&amp;nbsp;&amp;nbsp; The raster water mask is then filtered using a mode filter to remove small isolated pixels.&amp;nbsp;&amp;nbsp; The model runs as a tool and prompts the user for an input/ ouput filename, processing mask (optional) and sql expression (default given).&amp;nbsp; See exported model to script below...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Questions:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1) I exported the model to a script and&amp;nbsp; would like to add a looping functionality based on the sql expression.&amp;nbsp; The expression is as follows, "Value &amp;gt; 0 AND Value &amp;lt; 10".&amp;nbsp;&amp;nbsp; For example, upon input of a theshold of 10 I would like to produce a mask with a threshold of 9 (-1) and 11 (+1).&amp;nbsp; Therefore that script would be producing 3 raster mask every time it ran.&amp;nbsp; Ideally it would also name the ouput files automatically based on the threshold.&amp;nbsp;&amp;nbsp;&amp;nbsp; Any advice on how to do this??&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Note:&amp;nbsp; As a temporary solution I used the batching functionality in the model.&amp;nbsp; It works well but I think it leaves a bit too much room for errors.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2) The first image filter is very slow (Focal statistics, 3x3 median).&amp;nbsp; Test were ran with the toolbox tool being the slowest&amp;nbsp; (24min), desktop command line (7 min) and arc command line being much faster (don't have the numbers).&amp;nbsp;&amp;nbsp; Any explanation for this difference is speed and any suggestion on how to speed it up?&amp;nbsp;&amp;nbsp;&amp;nbsp; Do script tools run faster than model tools?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;3) While I am at it, I have another question.&amp;nbsp;&amp;nbsp; Is there any functionality in Model builder to linearly scale an image from 16bit to 8 bit?&amp;nbsp;&amp;nbsp; I did not find a function for this but maybe it does exist?&amp;nbsp; Otherwise I would need to find the min and max from and image and somehow use a formula to scale the image.&amp;nbsp;&amp;nbsp; This will be my next challenge!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am new to model builder and scripting with Python.&amp;nbsp;&amp;nbsp; Thanks for any advice on these issues.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Alice&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;----------------------------------------------------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# ---------------------------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# ExtractWaterMask.py&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Created on: Tue May 18 2010 01:29:25 PM&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#&amp;nbsp;&amp;nbsp; (generated by ArcGIS/ModelBuilder)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Usage: ExtractWaterMask &amp;lt;Input_8bit_scaled_SAR_image&amp;gt; &amp;lt;Processing_Mask&amp;gt; &amp;lt;Water_Threshold&amp;gt; &amp;lt;Output_8bit_water_mask&amp;gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# ---------------------------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Import system modules&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import sys, string, os, arcgisscripting&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Create the Geoprocessor object&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp = arcgisscripting.create()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Check out any necessary licenses&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.CheckOutExtension("spatial")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Load required toolboxes...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Set the Geoprocessing environment...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.mask = ""&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Script arguments...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Input_8bit_scaled_SAR_image = sys.argv[1]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Processing_Mask = sys.argv[2]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Water_Threshold = sys.argv[3]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if Water_Threshold == '#':&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Water_Threshold = "Value &amp;gt; 0 AND Value &amp;lt; 11" # provide a default value if unspecified&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Output_8bit_water_mask = sys.argv[4]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if Output_8bit_water_mask == '#':&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Output_8bit_water_mask = "D:\\EMERG\\test\\Water_Mask" # provide a default value if unspecified&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Local variables...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Con_focalst_1 = "D:\\EMERG\\test\\Con_filter_31"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Input_true_raster_or_constant_value__3_ = "1"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Input_false_raster_or_constant_value__3_ = "0"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;filter_scale1__2_ = "D:\\EMERG\\R1_21mars10\\mosaic\\filter_scale1"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;filter_scale1__3_ = "D:\\EMERG\\R1_21mars10\\mosaic\\filter_scale1"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;filter_33 = "D:\\EMERG\\test\\filter_33"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Focal Statistics (3x3 median)...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.FocalStatistics_sa(Input_8bit_scaled_SAR_image, filter_33, "Rectangle 3 3 CELL", "MEDIAN", "DATA")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Con...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;tempEnvironment0 = gp.mask&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.mask = ""&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.Con_sa(filter_33, Input_true_raster_or_constant_value__3_, Con_focalst_1, Input_false_raster_or_constant_value__3_, Water_Threshold)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.mask = tempEnvironment0&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Focal Statistics (5x5 Mode)...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.FocalStatistics_sa(Con_focalst_1, Output_8bit_water_mask, "Rectangle 5 5 CELL", "MAJORITY", "DATA")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 May 2010 16:46:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/looping-through-sql-speed/m-p/242766#M8285</guid>
      <dc:creator>AliceDeschamps</dc:creator>
      <dc:date>2010-05-18T16:46:41Z</dc:date>
    </item>
  </channel>
</rss>

