0

I am using the ArcGIS JavaScript API and Geoprocessing Services to get population. The service takes an input circle and returns the population inside.

Some times, a circle can cover cover more than one country (for example Spain and Portugal) but I need to get the population of a single country using a filter.

I am using this function to get the area using Google Maps:

function getPop()
myFunctions.ftn_findpop1(selectedShape.center.lat(),selectedShape.center.lng(),selectedShape.getRadius());
}
Then...
function findPop(ring) {
        var gp = new esri.tasks.Geoprocessor("https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/GPServer/PopulationSummary");
...
6
  • What precisely have you tried so far? Are you doing this using ArcObjects, ArcPy or another part of the Geoprocessing Framework?
    – PolyGeo
    Commented Jan 18, 2019 at 21:25
  • Cross-posted as stackoverflow.com/q/54238580/820534
    – PolyGeo
    Commented Jan 19, 2019 at 12:18
  • Thank you very much for your answers. Let me be more clear: I am getting an area with this : function ... () { ....(selectedShape.center.lat(),selectedShape.center.lng(),selectedShape.getRadius()} And then... { var gp = new esri.tasks.Geoprocessor("sampleserver1.arcgisonline.com/ArcGIS/rest/services/…); ... to get the total population. The problem is that some times, the circle can cover more than one country and I need to get the results by country. Does it make sense? Thank you very much! Commented Jan 22, 2019 at 12:21
  • I can't add an answer as the question is currently locked, but I'll caution a couple things. 1) This is a sample service, I wouldn't take it as being authoritative. 2) The data in this service is probably 5+ years old 3) Population counts have been interpolated to a raster dataset. I think that raster had a cell size of 250, perhaps even 1000km. It's very, very coarse. Clipping population size to actual country boundaries isn't going to be very accurate. If you're "ok" with what I'd call rough population estimates, this service would be ok to use.
    – KHibma
    Commented Jan 22, 2019 at 13:46
  • Actually you can see the source data in a map service here: https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/MapServer -- the cell size looks to be about 4km x 4km. So it might not be as bad as I thought
    – KHibma
    Commented Jan 22, 2019 at 13:50

1 Answer 1

0

I'm excluding the part where you're referencing Google Maps. I'm not entirely sure how that comes into play with this question.

Essentially you need to find the geometry of a country, with that you can pass that geometry into the geoprocessing service and have it use that instead of a "circle". Luckily there is a lot of data to be found on ArcGIS.com, including country boundaries.

The below code is very close to what you want to do. (It might actually work, but sampleserver1 is giving me CORS Cross domain issues and I'm not in a position to setup a proxy to make a good request. (My issue is beyond the scope of your initial question.) Below you can see that a button press starts everything. Pressing the button sets a definition express for Country = Spain. (there are many different ways to perform a query). The selected featurelayer with the definition is sent as input to the geoprocessing service. You'll get back a response and the app is responsible for popping up a text box with the output.

Remember, the code below will probably not just run, but it shows the pattern you need to undertake.

Note - pieced together from GP Zonal Stats and other feature layer samples.

<!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">
  <link rel="stylesheet" href="https://js.arcgis.com/3.27/dijit/themes/claro/claro.css">
  <link rel="stylesheet" href="https://js.arcgis.com/3.27/esri/css/esri.css" />
  <script src="https://js.arcgis.com/3.27/"></script>
  <script>
    var map;

    require([
      "esri/map",
      "esri/layers/FeatureLayer",
      "esri/symbols/SimpleFillSymbol",
      "esri/symbols/SimpleLineSymbol",
      "esri/tasks/Geoprocessor",
      "dojo/dom",
      "dojo/on",
      "dojo/parser",
      "dojo/string",
      "esri/Color",
      "dijit/registry",
      "dijit/form/Button",
      "dojo/domReady!"
    ],
      function (Map, FeatureLayer, SimpleFillSymbol, SimpleLineSymbol, 
        Geoprocessor, dom, on, parser, string, Color, registry
      ) {

        parser.parse();

        var featureLayer, map;

        map = new Map("map", {
          basemap: "streets",
          center: [0, 0],
          zoom: 3
        });
        gp = new Geoprocessor("https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/GPServer/PopulationSummary");
        gp.setOutputSpatialReference({wkid:102100}); 
        gp.on("execute-complete", displayResults);


        var fieldsSelectionSymbol =
          new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
            new SimpleLineSymbol(SimpleLineSymbol.STYLE_DASHDOT,
          new Color([255, 0, 0]), 2), new Color([255, 255, 0, 0.5]));
        // country boundary polygons
        featureLayer = new FeatureLayer("http://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/World_Countries_(Generalized)/FeatureServer/0",
          {
            mode: FeatureLayer.MODE_ONDEMAND,
            outFields: ["*"]
          });
        featureLayer.setSelectionSymbol(fieldsSelectionSymbol);
        map.addLayer(featureLayer);     

      function computeZonalStats() {      
       featureLayer.setDefinitionExpression("Country ='Spain'");
       var params = { "inputPoly":featureLayer };
        gp.execute(params);
      }

      function displayResults(evtObj) {
        console.log(evtObj);
        var results = evtObj.results;
        var content = string.substitute("<h4>The population in the user defined polygon is ${number:dojo.number.format}.</h4>",{number:results[0].value.features[0].attributes.SUM});

        registry.byId("dialog1").setContent(content);
        registry.byId("dialog1").show();
      }
          app = {
        computeZonalStats: computeZonalStats
      };

      });
  </script>
</head>

<body class="claro">
  <button id="querySpainButton" data-dojo-type="dijit/form/Button" onclick="app.computeZonalStats()">Query Spain</button>
  <div id="map" style="position: relative; width:700px; height:500px; border:1px solid #000;"></div>
   <div data-dojo-type="dijit.Dialog" id="dialog1" title="Population Summary"></div>
</body>
</html>
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.