Skip To Content

Stretch raster function

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:esri="http://www.esri.com/2008/ags"
               pageTitle="Using stretch raster function with ArcGISImageServiceLayer">
    <!--
    Description:
    This sample demonstrates how to add an ArcGISImageServiceLayer and apply a rendering rule
    to dynamically modify the display of the raster dataset. Rendering rules are created
    using a pre-defined set of raster functions contained in the ArcGIS REST API.
    This specific sample shows how to work with the stretch raster function.

    Documentation:
    For more information, see the API documentation.
    https://developers.arcgis.com/en/flex/api-reference/com/esri/ags/layers/ArcGISImageServiceLayer.html#renderingRule
    https://developers.arcgis.com/en/flex/api-reference/com/esri/ags/layers/supportClasses/RasterFunction.html
    https://developers.arcgis.com/en/flex/api-reference/com/esri/ags/layers/supportClasses/RasterFunction.html#arguments
    https://developers.arcgis.com/en/flex/api-reference/com/esri/ags/layers/supportClasses/RasterFunction.html#functionName

    ArcGIS REST API documentation:
    http://resources.arcgis.com/en/help/rest/apiref/index.html?imageserver.html
    http://resources.arcgis.com/en/help/rest/apiref/index.html?israsterfunctions.html

    ArcGIS for Server documentation:
    http://resources.arcgis.com/en/help/main/10.1/index.html#/Key_concepts_for_image_services/0154000003v2000000/
    http://resources.arcgis.com/en/help/main/10.1/index.html#/Image_service_parameters/015400000524000000/
    http://resources.arcgis.com/en/help/main/10.1/index.html#/Server_side_processing_with_raster_functions/0154000003w6000000/
    -->

    <fx:Script>
        <![CDATA[
            import com.esri.ags.events.MapEvent;

            []private var rasterArgs:Object = {};

            protected function map_loadHandler(event:MapEvent):void
            {
                // Start with tiledLayer as the base layer to set the map's units and lods,
                // but we actually want the imageLayer on the bottom,
                // so we re-order once map is loaded :)
                map.reorderLayer(imageLayer.id, 0);
            }

            protected function apply_clickHandler(event:MouseEvent):void
            {
                const bandIds:Array = bIds.text.split(",");
                imageLayer.bandIds = bandIds.length < 1 ? null : bandIds;

                rasterArgs["StretchType"] = Number(stretchType.selectedValue);
                rasterArgs["NumberOfStandardDeviations"] = sd.text ? Number(sd.text) : 1;
                rasterArgs["Statistics"] = new Array(
                    [ 0.2, 222.46, 99.35, 1.64 ],
                    [ 5.56, 100.345, 45.4, 3.96 ],
                    [ 0, 352.37, 172.284, 2 ]);
                rasterArgs["Gamma"] = [ 1.25, 2, 3.95 ];

                imageLayer.renderingRule = rasterFunction;
            }
        ]]>
    </fx:Script>

    <fx:Declarations>
        <s:RadioButtonGroup id="stretchType"/>
        <esri:RasterFunction id="rasterFunction"
                             arguments="{rasterArgs}"
                             functionName="Stretch"/>
    </fx:Declarations>

    <s:controlBarContent>
        <s:RichText width="100%">
            This sample demonstrates how to add an ArcGISImageServiceLayer and apply a rendering rule
            to dynamically modify the display of the raster dataset. Rendering rules are created
            using a pre-defined set of raster functions contained in the ArcGIS REST API.
            This specific sample shows how to work with the stretch raster function.
            Define input properties for the stretch raster function. Click Apply to display the changes.
        </s:RichText>
    </s:controlBarContent>

    <esri:Map id="map" load="map_loadHandler(event)">
        <esri:extent>
            <esri:Extent xmin="-13483041" ymin="5707158" xmax="-13300798" ymax="5776035">
                <esri:SpatialReference wkid="102100"/>
            </esri:Extent>
        </esri:extent>
        <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/Reference/World_Transportation/MapServer"/>
        <esri:ArcGISImageServiceLayer id="imageLayer"
                                      imageFormat="png8"
                                      noData="0"
                                      url="http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Portland/CascadeLandsat/ImageServer"/>
    </esri:Map>

    <s:Panel width="240"
             right="20" top="20"
             backgroundColor="0xEEEEEE"
             title="Stretch Raster Properties">
        <s:layout>
            <s:VerticalLayout gap="10"
                              paddingBottom="7"
                              paddingLeft="10"
                              paddingRight="10"
                              paddingTop="7"/>
        </s:layout>
        <s:RadioButton groupName="stretchType"
                       label="None"
                       selected="true"
                       value="0"/>
        <s:RadioButton groupName="stretchType"
                       label="Standard Deviation"
                       value="3"/>
        <s:RadioButton width="150"
                       groupName="stretchType"
                       label="Histogram"
                       value="4"/>
        <s:RadioButton groupName="stretchType"
                       label="MinMax"
                       value="5"/>
        <s:HGroup paddingTop="5" verticalAlign="middle">
            <s:Label text="Standard Deviations"/>
            <s:TextInput id="sd"
                         width="20"
                         text="2"/>
        </s:HGroup>
        <s:HGroup verticalAlign="middle">
            <s:Label text="Band Ids"/>
            <s:TextInput id="bIds"
                         width="45"
                         text="3,1,2"/>
        </s:HGroup>
        <s:Button id="apply"
                  width="100%"
                  click="apply_clickHandler(event)"
                  label="Apply"/>
    </s:Panel>
</s:Application>