Hide Table of Contents
View Analysis - Create watersheds sample in sandbox
Analysis - Create watersheds

Description

Create Watersheds determines the watershed, or catchment areas, for each point in your input layer. A points watershed includes all areas upstream that contribute to the flow of water to that point.

Since not all points are located within drainages, the resulting watersheds may be very small when the exact location of the input points are used in the calculation. If this is the case with your input points, you can make your analysis more meaningful by setting a search distance. This will adjust the location of each point so they intersect the nearest drainage within the specified search distance. Using this option does not modify the actual locations of your input points.

The generated result is a group layer containing two layers: a polygon layer representing watersheds and a point layer with the adjusted points used in computation.

Each watershed feature will contain all the attributes of its corresponding point input.

Create Watersheds is part of the Analysis service in ArcGIS Online.Analysisis a subscription-based service available through ArcGIS Online. Log-in credentials are always required when executing an Analysis task. Please supply your own credentials to use this sample.

Code

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>createWaterSheds</title>
<link rel="stylesheet" href="https://js.arcgis.com/3.29/dijit/themes/claro/claro.css" />
<link rel="stylesheet" href="https://js.arcgis.com/3.29/esri/css/esri.css" />
<style>
  html, body, #border-container
  {
    height: 100%;
    margin: 0;
  }
  /* Don't display the analysis widget's close icon*/
  .esriAnalysis .esriAnalysisCloseIcon
  {
    display: none;
  }
</style>
<script src="https://js.arcgis.com/3.29/"></script>
<script>
    require([
        "dojo/ready",
        "dojo/parser",
        "esri/urlUtils",
        "esri/map",
        "esri/layers/FeatureLayer",
        "esri/dijit/analysis/CreateWatersheds",
        "esri/InfoTemplate",
        "dijit/layout/BorderContainer",
        "dijit/layout/ContentPane"
    ], function (
        ready,
        parser,
        urlUtils,
        Map,
        FeatureLayer,
        CreateWatersheds,
        InfoTemplate
    ) {
        ready(function () {
            parser.parse();

            urlUtils.addProxyRule({
                urlPrefix: "elevation.arcgis.com",
                proxyUrl: "/sproxy/"
            });

            var map = new Map("map", {
                basemap: "topo",
                center: [-117.202097,34.067219],
                zoom: 12
            });

            var featureLayer = new FeatureLayer("https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/origins/FeatureServer/0");
            map.addLayers([featureLayer]);

            var analysisTool;
            map.on("layers-add-result", function () {

                analysisTool = new CreateWatersheds({
                    inputLayers: [ featureLayer ],
                    searchUnits: "Feet",
                    portalUrl: "https://www.arcgis.com",
                    map: map,
                    returnFeatureCollection: true
                }, "toolPane");
                analysisTool.startup();
                analysisTool.on("job-result", function (result) {
                    analysisTool.set("disableRunAnalysis", false);
                    var resultLayer = new FeatureLayer(result.value.url || result.value, {
                        outFields: ['*'],
                        infoTemplate: new InfoTemplate()
                    });
                    map.addLayer(resultLayer);
                });
            });
        });
    });
</script>
</head>
<body class="claro">
  <div id="border-container" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline',gutters:false">
    <div id="map" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'" style="padding: 0;"></div>
    <div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'left'" style="width: 300px;">
      <div id="toolPane"></div>
    </div>
  </div>
</body>
</html>
 
          
Show Modal