how to get desired map through query

699
23
07-10-2017 03:32 AM
FaryalSafdar
New Contributor

is there any way to get a soil map through query. i have populate area in comobox . now i want to populate combobox with the soil map of the selected area. as my soil has legend of different soil. i.e category option of Arcgis .

esriRequest({
url: "http://localhost:6080/arcgis/rest/services/....../query?where=Area_Name ='" + id.toString() + "'&outFields=Soil&returnGeometry=false&orderByFields=Soil&returnDistinctValues=true&f=json",
content:{
f:'json'
},
handleAs:'json',
callbackParamName:'callback',
timeout:15000
})

now the problem is as it has three soil types so combox populate three name and does not display geometry. i want to display whole soil map of the selected area

Tags (1)
0 Kudos
23 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Faryal,

   Your question is pretty confusing. Probably because your workflow is not very clear. If you want to limit a map service or service layer to only show features that qualify based on a query then you set the layers setdefinitionexpression.

FaryalSafdar
New Contributor

my problem is forexample when in arcgis when we select feature through attributes we use dinstict values it select all values of same name. i want to do this here. i have feature layer which categrorized as mention in the picture. i have added a column map and it has same value like soil map. when i select feature through attributes it has selected all features. but when i did this with arcgis query it returns all values of same name.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Faryal,

   Here is a complete sample that shows how to populate dojo combobox with unique values from a query and once selected it does a second query for unique counties from the selected state and on each choice the only drawn graphic is that one the user selects.

<!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>Drop Down Test</title>
  <link rel="stylesheet" href="http://js.arcgis.com/3.21/dijit/themes/claro/claro.css">
  <link rel="stylesheet" href="http://js.arcgis.com/3.21/dojo/resources/dojo.css">
  <link rel="stylesheet" href="http://js.arcgis.com/3.21/esri/css/esri.css">
  <script src="http://js.arcgis.com/3.21/"></script>
  <style>
    html,
    body,
    #mainWindow {
      height: 100%;
      width: 100%;
      margin: 0;
      padding: 0;
    }
    body {
      background-color: #FFF;
      overflow: hidden;
      font-family: "Trebuchet MS";
    }
    #header {
      height: 3%;
      overflow: auto;
    }
  </style>

  <script>
    var map;
    require([
      "esri/map",
      "dojo/on",
      "esri/tasks/query",
      "esri/layers/FeatureLayer",
      "dojo/store/Memory",
      "dojo/_base/array",
      "dojo/_base/lang",
      "esri/request",
      "dojo/json",
      "dojo/parser",
      "dijit/layout/BorderContainer",
      "dijit/layout/ContentPane",
      "dijit/form/Button",
      "dijit/form/ComboBox",
      "dojo/domReady!"
    ], function(
      Map, on, Query, FeatureLayer, Memory, array, lang, esriRequest, json, parser
    ) {
      parser.parse();
      map = new Map("map", {
        basemap: "topo",
        center: [-98.1883, 37.0868],
        zoom: 5
      });

      esriRequest({
        url: 'http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3/query?where=1%3D1&outF...',
        content:{
          f:'json'
        },
        handleAs:'json',
        callbackParamName:'callback',
        timeout:15000
      }).then(lang.hitch(this,function(response){
        var store2 = new Memory({data:[]});
        dijit.byId("stateSelect").set('store',store2);
        var data = array.map(response.features,lang.hitch(this,function(feat, index){
          var name = feat.attributes.STATE_NAME;
          var value = feat.attributes.STATE_NAME;
          var dataItem = {
            id:index,
            name:name,
            value:value
          };
          return dataItem;
        }));
        store2 = new Memory({data:data});
        dijit.byId("stateSelect").set('store',store2);
      }));

      var States = new FeatureLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3", {
        mode: FeatureLayer.MODE_SELECTION,
        outFields: ["*"]
      });

      var Counties = new FeatureLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/2", {
        mode: FeatureLayer.MODE_SELECTION,
        outFields: ["*"]
      });

      map.addLayers([States,Counties]);

      app = {
        zoomRow: function(id, which){
          States.clearSelection();
          Counties.clearSelection();
          var query = new Query();
          var thePoly, theExtent;
          if(which == "State"){
            query.where = "STATE_NAME='" + (id).toString() + "'";
            console.info(query.where);
            query.returnGeometry = true;
            States.selectFeatures(query, FeatureLayer.SELECTION_NEW, function (features) {
              thePoly = features[0].geometry;
              theExtent = thePoly.getExtent().expand(2); //Zoom out slightly from the polygon's extent
              map.setExtent(theExtent);
            });
            esriRequest({
              url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/2/query?where=STATE_NAME...'" + id.toString() + "'&outFields=NAME&returnGeometry=false&orderByFields=NAME&returnDistinctValues=true&f=json",
              content:{
                f:'json'
              },
              handleAs:'json',
              callbackParamName:'callback',
              timeout:15000
            }).then(lang.hitch(this,function(response){
              var store2 = new Memory({data:[]});
              dijit.byId("countySelect").set('store',store2);
              var data = array.map(response.features,lang.hitch(this,function(feat, index){
                var name = feat.attributes.NAME;
                var dataItem = {
                  id:index,
                  name:name
                };
                return dataItem;
              }));
              store2 = new Memory({data:data});
              dijit.byId("countySelect").set('store',store2);
              document.getElementById('countySelect').value = "Select County";
            }));
          }else if(which == "County"){
            var county = (id).toString();
            county = county.replace(" County", "");
            query.where = "NAME='" + county + "'";
            console.info(query.where);
            query.returnGeometry = true;
            Counties.selectFeatures(query, FeatureLayer.SELECTION_NEW, function (features) {
              thePoly = features[0].geometry;
              theExtent = thePoly.getExtent().expand(2); //Zoom out slightly from the polygon's extent
              map.setExtent(theExtent);
            });
          }
        }
      };

    });
  </script>
</head>

<body class="claro">
  <div id="mainWindow" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline', gutters:false" style="padding:0px;margin:0px;">
    <div id="header" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'top'" style="overflow:hidden;border:none;border-bottom: 3px solid #CC9900;font-family: Windows;font-size:14pt; color: #FFFFFF;background: #000000; "> Select a State/County and zoom to it on the map:
      <input id="stateSelect" data-dojo-type="dijit/form/ComboBox" value="Select State" onchange="app.zoomRow(document.getElementById('stateSelect').value, 'State');" data-dojo-props="maxHeight: 200" />
      <input id="countySelect" data-dojo-type="dijit/form/ComboBox" value="Select County" onchange="app.zoomRow(document.getElementById('countySelect').value, 'County');" />
      <input type="hidden" name="stateabbr" id="stateabbr" />
    </div>
    <div id="map" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'left'" style="width:100%;height:95%;border:none;padding:0px;margin:0px;"></div>
  </div>
</body>

</html>
FaryalSafdar
New Contributor

Thanks Robert for your response. here is my code 

esriRequest({
url: "http://localhost:6080/arcgis/rest/services/........./query?where=R_Name ='" + id.toString() + "'&outFields=STE&returnGeometry=false&orderByFields=Soil&returnDistinctValues= true&f=json",
content:{
f:'json'
},
handleAs:'json',
callbackParamName:'callback',
timeout:15000
}).then(lang.hitch(this,function(response){
var store2 = new Memory({data:[]});
dijit.byId("RSoil").set('store',store2);
var data = array.map(response.features,lang.hitch(this,function(feat, index){
var name = feat.attributes.Soil;
var dataItem = {
id:index,
name:name
};
return dataItem;
}));
store2 = new Memory({data:data});

dijit.byId("RSoil").set('store',store2);

document.getElementById('RSoil').value = "Soil";
}));
}
else if(which == "RS"){
var rs = (id).toString();
rs = rs.replace("RS", "");
query.where = "Soil='" + rs + "'";
console.info(query.where);
query.returnGeometry = true;

S_layer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function (features) {
if(features[0]){
thePoly = features[0].geometry;
theExtent = thePoly.getExtent().expand(1.8); //Zoom out slightly from the polygon's extent
map.setExtent(theExtent);
}
});

0 Kudos
FaryalSafdar
New Contributor

the query result is like the image. although i have used distinct values = true . but it returns all values. kindly guide me how to solve this problem. it should return only one value.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Faryal,

  Provide your complete code you are using for further assistance.

0 Kudos
FaryalSafdar
New Contributor

i have provided my code . kindly review it.

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Faryal,

   What version of ArcGIS Server are you using? Why do you have outFields=STE when you are only seeming to use the Soil field?

0 Kudos
FaryalSafdar
New Contributor

i am using Arcserver 10.2. i have mistakenly write STE it is Soil. 

0 Kudos