I have a time-enabled MODIS NPP imagery layer for CONUS hosted in our ArcGIS Server. I need to query the tiles resides within the mosaic dataset using some attribute table properties including the time. Then I need to resample the selected tiles into different pixel size and save them as another Imagery layer or a single file.
I used
arcgis<SPAN class="punctuation token">.</SPAN>raster<SPAN class="punctuation token">.</SPAN>ImageryLayer<SPAN class="punctuation token">.</SPAN>set_filter<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
function to filter out and lock the necessary tiles as follows.
npp_layer<SPAN class="punctuation token">.</SPAN>set_filter<SPAN class="punctuation token">(</SPAN>where<SPAN class="operator token">=</SPAN><SPAN class="string token">"((hor=8 OR hor=9) AND ver=5) AND Category=1"</SPAN><SPAN class="punctuation token">,</SPAN> time<SPAN class="operator token">=</SPAN><SPAN class="punctuation token">[</SPAN>datetime<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2014</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN>datetime<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2014</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">12</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">31</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> lock_rasters<SPAN class="operator token">=</SPAN><SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">,</SPAN> clear_filters<SPAN class="operator token">=</SPAN><SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN>
resampled_layer <SPAN class="operator token">=</SPAN> copy_raster<SPAN class="punctuation token">(</SPAN>npp_layer<SPAN class="punctuation token">,</SPAN> output_cellsize<SPAN class="operator token">=</SPAN><SPAN class="number token">2000</SPAN><SPAN class="punctuation token">,</SPAN> resampling_method<SPAN class="operator token">=</SPAN><SPAN class="string token">'NEAREST'</SPAN><SPAN class="punctuation token">,</SPAN> output_name<SPAN class="operator token">=</SPAN><SPAN class="string token">'resampled_npp'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Then used above
arcgis<SPAN class="punctuation token">.</SPAN>raster<SPAN class="punctuation token">.</SPAN>analytics<SPAN class="punctuation token">.</SPAN>copy_raster<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
function to resample the selected tiles in the imagery layer and save them as new layer. But "set_filter" filtered and locked rasters are not identified by the "copy_raster" function, so the resampling is applied to all the tiles across all the years. It makes a spatially and temporally incorrect result.
I see a
arcgis<SPAN class="punctuation token">.</SPAN>raster<SPAN class="punctuation token">.</SPAN>functions<SPAN class="punctuation token">.</SPAN>resample<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>
function, but it does not have a "output_pixel_size" parameter, so it becomes useless in my case. I tried using "arcgis.raster.ImageryLayer.filter_by" and "arcgis.raster.ImageryLayer.mosaic_by" functions for filtering as well, but with no success.
Following is my complete code :
<SPAN class="keyword token">import</SPAN> arcgis
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>gis <SPAN class="keyword token">import</SPAN> GIS
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>raster <SPAN class="keyword token">import</SPAN> ImageryLayer
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>raster<SPAN class="punctuation token">.</SPAN>functions <SPAN class="keyword token">import</SPAN> <SPAN class="operator token">*</SPAN>
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>raster<SPAN class="punctuation token">.</SPAN>analytics <SPAN class="keyword token">import</SPAN> <SPAN class="operator token">*</SPAN>
<SPAN class="keyword token">from</SPAN> datetime <SPAN class="keyword token">import</SPAN> datetime
gis <SPAN class="operator token">=</SPAN> GIS<SPAN class="punctuation token">(</SPAN><SPAN class="string token"><SPAN>'</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Farcgis" target="_blank">https://arcgis</A><SPAN>.<domain>/portal'</SPAN></SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'<user_name>'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'password'</SPAN><SPAN class="punctuation token">)</SPAN>
img_svc_url <SPAN class="operator token">=</SPAN> <SPAN class="string token"><SPAN>'</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2Farcsrv-prd-02" target="_blank">https://arcsrv-prd-02</A><SPAN>.<domain>:6443/arcgis/rest/services/ANLN-ImageServices/annual_npp/ImageServer'</SPAN></SPAN>
npp_layer <SPAN class="operator token">=</SPAN> ImageryLayer<SPAN class="punctuation token">(</SPAN>img_svc_url<SPAN class="punctuation token">)</SPAN>
npp_layer<SPAN class="punctuation token">.</SPAN>set_filter<SPAN class="punctuation token">(</SPAN>where<SPAN class="operator token">=</SPAN><SPAN class="string token">"((hor=8 OR hor=9) AND ver=5) AND Category=1"</SPAN><SPAN class="punctuation token">,</SPAN> time<SPAN class="operator token">=</SPAN><SPAN class="punctuation token">[</SPAN>datetime<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2014</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN>datetime<SPAN class="punctuation token">(</SPAN><SPAN class="number token">2014</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">12</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="number token">31</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> lock_rasters<SPAN class="operator token">=</SPAN><SPAN class="token boolean">True</SPAN><SPAN class="punctuation token">,</SPAN> clear_filters<SPAN class="operator token">=</SPAN><SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">)</SPAN>
resampled_layer <SPAN class="operator token">=</SPAN> copy_raster<SPAN class="punctuation token">(</SPAN>npp_layer<SPAN class="punctuation token">,</SPAN> output_cellsize<SPAN class="operator token">=</SPAN><SPAN class="number token">2000</SPAN><SPAN class="punctuation token">,</SPAN> resampling_method<SPAN class="operator token">=</SPAN><SPAN class="string token">'NEAREST'</SPAN><SPAN class="punctuation token">,</SPAN> output_name<SPAN class="operator token">=</SPAN><SPAN class="string token">'resampled_npp'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>new_ras_layer<SPAN class="punctuation token">.</SPAN>properties<SPAN class="punctuation token">)</SPAN>
mymap <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>map<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Los Angeles, US"</SPAN><SPAN class="punctuation token">,</SPAN> zoomlevel<SPAN class="operator token">=</SPAN><SPAN class="number token">6</SPAN><SPAN class="punctuation token">)</SPAN>
mymap<SPAN class="punctuation token">.</SPAN>add_layer<SPAN class="punctuation token">(</SPAN>resampled_layer<SPAN class="punctuation token">)</SPAN>
mymap<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>
This filtering and resampling work fine with ArcGIS Pro with Image Server Raster Analysis, but I can't figure it out how to do it with Python API. I am using ArcGIS Server 10.5, ArcGIS Python API 1.2.4, ArcMap 10.5 and ArcGIS Pro products. I am new to ArcGIS Python API, appreciate any help to solve this problem.
Update: There are Imagery layer resampling issues even with ArcGIS Pro. I see that some resampling algorithms like "bilinear" and "nearest neighbor" work, but "average" and "majority" do not work.