Select to view content in your preferred language

Resampling an imagery layer with locked rasters

1461
2
Jump to solution
12-12-2017 11:07 AM
UdayaJayawardhana
Occasional Contributor

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.raster.ImageryLayer.set_filter()‍‍‍‍‍

function to filter out and lock the necessary tiles as follows.

npp_layer.set_filter(where="((hor=8 OR hor=9) AND ver=5) AND Category=1", time=[datetime(2014,1,1),datetime(2014,12,31)], lock_rasters=True, clear_filters=False)

resampled_layer = copy_raster(npp_layer, output_cellsize=2000, resampling_method='NEAREST', output_name='resampled_npp')‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Then used above 

arcgis.raster.analytics.copy_raster()‍‍‍‍‍

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.raster.functions.resample()‍‍‍‍

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 : 

import arcgis
from arcgis.gis import GIS
from arcgis.raster import ImageryLayer
from arcgis.raster.functions import *
from arcgis.raster.analytics import *
from datetime import datetime

gis = GIS('https://arcgis.<domain>/portal', '<user_name>', 'password')

img_svc_url = 'https://arcsrv-prd-02.<domain>:6443/arcgis/rest/services/ANLN-ImageServices/annual_npp/ImageServer'
npp_layer = ImageryLayer(img_svc_url)

npp_layer.set_filter(where="((hor=8 OR hor=9) AND ver=5) AND Category=1", time=[datetime(2014,1,1),datetime(2014,12,31)], lock_rasters=True, clear_filters=False)

resampled_layer = copy_raster(npp_layer, output_cellsize=2000, resampling_method='NEAREST', output_name='resampled_npp')‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

print(new_ras_layer.properties)

mymap = gis.map("Los Angeles, US", zoomlevel=6)
mymap.add_layer(resampled_layer)
mymap‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

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.

0 Kudos
1 Solution

Accepted Solutions
UdayaJayawardhana
Occasional Contributor

I had a support ticket for this with Esri. This is the summary of what we discovered at the end.

1. Resampling raster function does not offer an "output pixel size" parameter. It is usability issue, so Esri support team will add a usability bug for this. Whenever resampling function is going to have that parameter, resampling with filtered (and locked) rasters will work.

BUG-000110653: Incorporate functionality to allow a user to specify output cell size with the resample raster function in the Python API.

2. Since copy_raster is not a raster function (not included in arcgis.raster.functions), filtered and locked rasters are not honored when copy_raster is executed. So copy_raster is not useful in this case.

3. There is no workaround for this at the moment using ArcGIS Python API. One can use ArcGIS Pro "resample" raster function for this. But please note that "average", "majority" and some other resampling types produce some erroneous results, "bilinear" and "nearest neighbor" work perfectly well.

View solution in original post

0 Kudos
2 Replies
UdayaJayawardhana
Occasional Contributor

Now I'm going to run it as a raster function as shown in the ArcGIS REST API.

{
  "rasterFunction" : "Resample",
  "rasterFunctionArguments" : {
    "ResamplingType" : <ResamplingType>, //0=NearestNeighbor,1=Bilinear,2=Cubic,3=Majority,
                      4=BilinearInterpolationPlus,5=BilinearGaussBlur, 6=BilinearGaussBlurPlus
                      7=Average, 8=Minimum, 9=Maximum,10=VectorAverage(require two bands)
    "InputCellsize" : <InputCellsize>, //point that defines cellsize in source spatial reference
    },
  "outputPixelType" : "<outputPixelType>",//optional
  "variableName" : "Raster"
}‍‍‍‍‍‍‍‍‍‍‍

But I already got another issue while running this same thing through ArcGIS Pro. Even if this is going to work to some extent, I still need to solve the other problem to get this solved meaningfully.

Imagery Layer Resampling Issues 

0 Kudos
UdayaJayawardhana
Occasional Contributor

I had a support ticket for this with Esri. This is the summary of what we discovered at the end.

1. Resampling raster function does not offer an "output pixel size" parameter. It is usability issue, so Esri support team will add a usability bug for this. Whenever resampling function is going to have that parameter, resampling with filtered (and locked) rasters will work.

BUG-000110653: Incorporate functionality to allow a user to specify output cell size with the resample raster function in the Python API.

2. Since copy_raster is not a raster function (not included in arcgis.raster.functions), filtered and locked rasters are not honored when copy_raster is executed. So copy_raster is not useful in this case.

3. There is no workaround for this at the moment using ArcGIS Python API. One can use ArcGIS Pro "resample" raster function for this. But please note that "average", "majority" and some other resampling types produce some erroneous results, "bilinear" and "nearest neighbor" work perfectly well.

0 Kudos