Get values after query

2874
7
10-14-2015 07:14 AM
ADITYAKUMAR1
Occasional Contributor III

Hi Users,

I am using an existing example to perform a query when I am drawing a polygon and it will give me the count of all the features inside it.

Mentioned below is the code.

function initSelectToolbar (event) {

          selectionToolbar = new Draw(event.map);

          var selectQuery = new Query();

          on(selectionToolbar, "DrawEnd", function (geometry) {

            selectionToolbar.deactivate();

            selectQuery.geometry = geometry;

            DREAM_2D .selectFeatures(selectQuery,

              FeatureLayer.SELECTION_NEW);

          });

        }

  

         

function sumGasProduction (event) {

      var  countOfFeatures = 0;

          arrayUtil.forEach(event.features, function (feature) {

            countOfFeatures++;

          });

          dom.byId('messages').innerHTML = "<b>Number of points selected: " +

                                            countOfFeatures + " wells. </b>";

        }

But after getting the count I need to get the details of each and every point which got selected during the query.

Can someone please help me to resolve it.

Thanks

Tags (1)
0 Kudos
7 Replies
TracySchloss
Frequent Contributor

You have each feature getting returned in the arrayUtil.forEach, you just need more code in that loop to take advantage of them.  What do you want to do with them, populate a list or grid? 

ChrisSmith7
Frequent Contributor

Aditya,

Here's a visual representation of this:

Some info on the attributes from the selection:

Is this the kind of info you need?

ADITYAKUMAR1
Occasional Contributor III

Thanks..

0 Kudos
ADITYAKUMAR1
Occasional Contributor III

Thanks for the reply.I want to take the data and transfer the data in one .net application through ajax.

0 Kudos
ChrisSmith7
Frequent Contributor

FYI, you can also just hit the service directly, outside of your mapping app, if that's ever useful to you:

http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSPetro/MapServer/1/query?text=...{

"xmin" : -10857096.337411141, "ymin" : 4514682.962763, "xmax" : -10852204.367600897, "ymax" : 4510020.30403761,

"spatialReference" : {"wkid" : 102100}

}

&geometryType=esriGeometryEnvelope&inSR=102100&spatialRel=esriSpatialRelContains&relationParam=&objectIds=&where=&time=&returnIdsOnly=false&returnGeometry=true&maxAllowableOffset=&outSR=&outFields=ACTIVEPROD,APPROXACRE,AVGDEPTH,FIELD_NAME,FIELD_TYPE,PROD_GAS,PROD_OIL,STATUS&f=json

Copy this and paste in browser, you'll get a response back, e.g.:

{"displayFieldName":"FIELD_NAME","fieldAliases":{"ACTIVEPROD":"Active Production","APPROXACRE":"Approximate Acre","AVGDEPTH":"Average Depth","FIELD_NAME":"Field Name","FIELD_TYPE":"Field Type","PROD_GAS":"Production Gas","PROD_OIL":"Production Oil","STATUS":"Status"},"geometryType":"esriGeometryPolygon","spatialReference":{"wkid":4267},"fields":[{"name":"ACTIVEPROD","type":"esriFieldTypeString","alias":"Active Production","length":10},{"name":"APPROXACRE","type":"esriFieldTypeDouble","alias":"Approximate Acre"},{"name":"AVGDEPTH","type":"esriFieldTypeDouble","alias":"Average Depth"},{"name":"FIELD_NAME","type":"esriFieldTypeString","alias":"Field Name","length":150},{"name":"FIELD_TYPE","type":"esriFieldTypeString","alias":"Field Type","length":5},{"name":"PROD_GAS","type":"esriFieldTypeString","alias":"Production Gas","length":3},{"name":"PROD_OIL","type":"esriFieldTypeString","alias":"Production Oil","length":3},{"name":"STATUS","type":"esriFieldTypeString","alias":"Status","length":50}],"features":[{"attributes":{"ACTIVEPROD":"GAS","APPROXACRE":158,"AVGDEPTH":0,"FIELD_NAME":"CLEARWATER NORTHEAST","FIELD_TYPE":"GAS","PROD_GAS":"Yes","PROD_OIL":"No","STATUS":"Active"},"geometry":{"rings":[[[-97.511999713999955,37.518708764000053],[-97.51425102099995,37.51864921400005],[-97.514269636999984,37.520450063000055],[-97.514288417999978,37.522267735000071],[-97.514289758999951,37.52239806800003],[-97.514307389999942,37.524102785000025],[-97.514326532999974,37.525954743000057],[-97.512054895999938,37.525979914000061],[-97.509767392999947,37.526005203000068],[-97.507485631999941,37.526030415000037],[-97.505202250999957,37.526055596000049],[-97.50520000299997,37.52424086700006],[-97.505197783999961,37.52244902700005],[-97.505195574999959,37.520663002000049],[-97.505193388999942,37.518888600000025],[-97.505300545999944,37.518885769000065],[-97.50747073499997,37.518828447000033],[-97.509739700999944,37.518768474000069],[-97.509800642999949,37.518766893000077],[-97.511999713999955,37.518708764000053]]]}}]}

In the above, I asked for it to filter on an envelope (map extent) for fields contained by said extent. I asked for the service to give me the geometry rings as well as several field values. You can make the requests right through AJAX, or as an http response in .NET. Of course, you'd need the extent ahead of time! But, you can send in any geometry object - polygons, polylines, points, etc, and set your spatial relation in the request URL. You can also send queries as well, say by attribute, for instance.

TracySchloss
Frequent Contributor

Each feature has attributes and if  you create a JSON formatted object you should be able to pass it to .NET.

I don't think you need countOfFeatures++.   The number of features returned is available without it.

Typically when you have a function that's the result handler of a query, it's more common to call the output results, not event.

function sumGasProduction (results) {

     var countOfFeatures = results.features.length;

myData = arrayUtil.map(results.features, function(feature){

        return {

          'id': feature.attributes.OBJECTID,  

          'ActiveProduct':feature.attributes.ACTIVEPROD,   

          'Average_Depth':feature.attributes.AVGDEPTH,

         'Status':feature.attributes.STATUS

        };

      });

dom.byId('messages').innerHTML = "<b>Number of points selected: " +

           countOfFeatures + " wells. </b>";

         }

}

Then myData could be passed to the .NET application.

ADITYAKUMAR1
Occasional Contributor III

Thanks a  lot Tracy, it really helped.

0 Kudos