Hi I have made a simple tool to clip from a couple of rasters after a list of bool is passed in, it will eventually clip fromn more than just 2 rasters.
The clipped rasters are sat in %scratch data%
I want to zip them up and offer them as a download at the end of this tool.
I have looked at the clip and ship example but that seems to ue a tool to zip and email all in one go, I want to zip then offer a download.
How do I zip my clipped tiffs.
How do I offer the resulting zip as a download.
Should I be using "in_memory"?
<SPAN class="keyword token">import</SPAN> arcpy
# Set geoprocessing environments
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> True
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"\\dacspreprodstorage.file.core.windows.net\preprodcontentstore\Jim\BSelect.gdb"</SPAN>
boolList <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetParameterAsText</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> boolList <SPAN class="operator token">==</SPAN> <SPAN class="string token">'#'</SPAN> or not boolList<SPAN class="punctuation token">:</SPAN>
boolList <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>True<SPAN class="punctuation token">,</SPAN> False<SPAN class="punctuation token">]</SPAN> # provide a <SPAN class="keyword token">default</SPAN> value <SPAN class="keyword token">if</SPAN> unspecified
outname <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetParameterAsText</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> outname <SPAN class="operator token">==</SPAN> <SPAN class="string token">'#'</SPAN> or not boolList<SPAN class="punctuation token">:</SPAN>
outname <SPAN class="operator token">=</SPAN> <SPAN class="string token">'download'</SPAN> # provide a <SPAN class="keyword token">default</SPAN> value <SPAN class="keyword token">if</SPAN> unspecified
#<SPAN class="keyword token">set</SPAN> params
poly <SPAN class="operator token">=</SPAN> <SPAN class="string token">"clipit"</SPAN>
tiflist <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"Whole_UK_Mosaic"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Whole_UK_COMORG"</SPAN><SPAN class="punctuation token">]</SPAN>
def <SPAN class="token function">cliptif</SPAN><SPAN class="punctuation token">(</SPAN>clippee<SPAN class="punctuation token">,</SPAN> clipper<SPAN class="punctuation token">,</SPAN> output<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
desc <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Describe</SPAN><SPAN class="punctuation token">(</SPAN>clipper<SPAN class="punctuation token">)</SPAN>
extent <SPAN class="operator token">=</SPAN> desc<SPAN class="punctuation token">.</SPAN>extent
coord_string <SPAN class="operator token">=</SPAN> <SPAN class="string token">"{} {} {} {}"</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">format</SPAN><SPAN class="punctuation token">(</SPAN>extent<SPAN class="punctuation token">.</SPAN>XMin<SPAN class="punctuation token">,</SPAN> extent<SPAN class="punctuation token">.</SPAN>YMin<SPAN class="punctuation token">,</SPAN> extent<SPAN class="punctuation token">.</SPAN>XMax<SPAN class="punctuation token">,</SPAN> extent<SPAN class="punctuation token">.</SPAN>YMax<SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Clip_management</SPAN><SPAN class="punctuation token">(</SPAN>clippee<SPAN class="punctuation token">,</SPAN> coord_string<SPAN class="punctuation token">,</SPAN> output<SPAN class="punctuation token">,</SPAN> in_template_dataset<SPAN class="operator token">=</SPAN>poly<SPAN class="punctuation token">,</SPAN> clipping_geometry<SPAN class="operator token">=</SPAN><SPAN class="string token">"ClippingGeometry"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">for</SPAN> i <SPAN class="keyword token">in</SPAN> <SPAN class="token function">range</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token function">len</SPAN><SPAN class="punctuation token">(</SPAN>tiflist<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
# outTif <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"C:\Jim\BathySelect\output\output"</SPAN><SPAN class="operator token">+</SPAN><SPAN class="token function">str</SPAN><SPAN class="punctuation token">(</SPAN>i<SPAN class="punctuation token">)</SPAN><SPAN class="operator token">+</SPAN><SPAN class="string token">".tif"</SPAN>
outTif <SPAN class="operator token">=</SPAN> <SPAN class="string token">"%scratchFolder%\\output"</SPAN><SPAN class="operator token">+</SPAN><SPAN class="token function">str</SPAN><SPAN class="punctuation token">(</SPAN>i<SPAN class="punctuation token">)</SPAN><SPAN class="operator token">+</SPAN><SPAN class="string token">".tif"</SPAN>
<SPAN class="token function">cliptif</SPAN><SPAN class="punctuation token">(</SPAN>tiflist<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> poly<SPAN class="punctuation token">,</SPAN> outTif<SPAN class="punctuation token">)</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Thanks