Monday 20 August 2018

Reduce extent of raster processing in ArcPy or ArcGIS Desktop?


I need to reduce the processing extent of my raster by some sort of automatic procedure in python. Currently the borders of the dataset I've been using has anomalies (due to the classification of the landsat scanning lines).


ScanLines Classified


I would like to reduce the extent of the raster processing so that when I retrieve the information above by a SetNull function the borders are not processed. Something like Area


Now this can easily be done with an extract by mask function (i.e. figure2) although that would require manual selection of the masking region. Is there a menthod I can utilize to calculate the extent region (ignoring nodata values) minus the border width in the x and y direction of each row/column and then utilize the arcpy.env.extent in Python?



Answer



This workflow deals first with the junk floating around the edges and then solves the problem.





  1. Create a binary indicator of the "border" area, which I take to include all surrounding NoData cells. It is convenient to use any value to indicate the border and NoData for the rest, as in SetNull(Not(IsNull('X')), 1):


    Border




  2. Regiongroup the result and select the border component. (This can usually be automated by selecting the component with the largest value of [Count].) The image will look almost the same; only a few stray pixels in the center are excluded here--but they must be excluded for the next step to work.


    (An alternative approach is to use morphological operations first to shrink the border and then re-expand it: this erases the isolated bits in the middle.)




  3. Compute the Euclidean distance grid to the border component.


    Distances





  4. Mask out all small distances in the original image, as in SetNull(([Distance to Border component] < 30),X):


    Result




(The final image shows the original border in green overlaid, for reference, on the result.)


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...