Select to view content in your preferred language

"Query map with buffer polygon" - Returns all points, not just those in buffer

969
6
08-13-2010 10:02 AM
BenStuder
Deactivated User
I'm finally able to play with the ArcGIS API for JavaScript! To get started, I am playing with deploying the functionality that similar to the sample for "Query Map with buffer polygon:"  http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/help/jssamples_start.htm

However, now that I think I have solved the proxy problem (Yikes, Jeremy et al., please include a link in the example of how to install the proxy!), I am finding that the buffer isn't limiting the result to the region inside the buffer.

Is this due to a configuration error on my part with the proxy server?

I always receive 500 results from the full extent of a several thousand point Layer file served VIA REST.

Here's my code snippet:
    dojo.require("esri.map");
    dojo.require("esri.tasks.query");
    dojo.require("esri.tasks.geometry");

    /*Initialize map, buffer, & query params*/
    function init(){
 var startExtent = new esri.geometry.Extent(-119, 40, -110, 50, new esri.SpatialReference({
     wkid: 4326
 }));
 var map = new esri.Map("mapDiv", {
     extent: startExtent
 });
 //listen for when map is loaded and then add query functionality
 dojo.connect(map, "onLoad", initFunctionality);

 var streetMap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer");
 map.addLayer(streetMap);
    }

    function initFunctionality(map){
 var queryTask = new esri.tasks.QueryTask("http://MYDOMAIN/gis/rest/services/develObservations2/MapServer/0/query");

 //identify proxy page to use if the toJson payload to the geometry service is greater than 2000 characters.
 //If this null or not available the buffer operation will not work.  Otherwise it will do a http post to the proxy.
 esriConfig.defaults.io.proxyUrl = "../server/proxy.ashx";
 esriConfig.defaults.io.alwaysUseProxy = true;

 // Query
 var query = new esri.tasks.Query();
 query.returnGeometry = true;
 query.outFields = ["MYOUTPUTFIELDS"];


 //Geometry Service Endpoint
 var gsvc = new esri.tasks.GeometryService("http://MYDOMAIN/gis/rest/services/Geometry/GeometryServer");


 // +++++Listen for map onClick event+++++
 dojo.connect(map, "onClick", function(evt){
     map.graphics.clear();
     var symbol = new esri.symbol.SimpleMarkerSymbol();
     var graphic = new esri.Graphic(evt.mapPoint, symbol);

     var params = new esri.tasks.BufferParameters();
     params.features = [graphic];

     // CASE [1]: if you want to buffer in linear units such as meters, km, miles etc.
     params.distances = [dojo.byId('bufferDistance').value];
     params.unit = esri.tasks.BufferParameters.UNIT_KILOMETER;
     params.bufferSpatialReference = new esri.SpatialReference({
  wkid: 4326
     });
     gsvc.buffer(params);
     dojo.byId('messages').innerHTML = "<b>Creating Buffer Using Geometry Service...</b>";
 });


 // +++++Listen for GeometryService onBufferComplete event+++++
 dojo.connect(gsvc, "onBufferComplete", function(graphics){
     var symbol = new esri.symbol.SimpleFillSymbol("none", new esri.symbol.SimpleLineSymbol("solid", new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25]));
     var graphic = new esri.Graphic(graphics[0].geometry, symbol);
     map.graphics.add(graphic);

     query.geometry = graphic.geometry;
     queryTask.execute(query);
     dojo.byId('messages').innerHTML = "<b>Executing Query with Result Buffer Geometry...</b>";
 });


 // +++++Listen for QueryTask executecomplete event+++++
 dojo.connect(queryTask, "onComplete", function(fset){
     //create symbol for selected features
     var symbol = new esri.symbol.SimpleMarkerSymbol();
     symbol.style = esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE;
     symbol.setSize(8);
     symbol.setColor(new dojo.Color([0, 255, 255, 0.5]));

    //THERE IS PROBABLY A BETTER WAY TO DO THIS, BUT I HAD ISSUES WITH LABELING POINTS AS A MULTIPOINT
     var resultFeatures = fset.features;
     for (var i = 0, il = resultFeatures.length; i < il; i++) {
  var thisx = resultFeatures.attributes.XMin;
  var thisy = resultFeatures.attributes.YMin;

  thisgeometry = new esri.Graphic(new esri.geometry.Point(thisx, thisy, new esri.SpatialReference({ wkid: 4326 })));
   infoTemplate = new esri.InfoTemplate("Observation of " + resultFeatures.attributes.SciName + " ID:" + resultFeatures.attributes.observationid, "Info: " + resultFeatures.attributes.Title);

   thisgeometry.setInfoTemplate(infoTemplate);
   thisgeometry.setSymbol(symbol);

  map.graphics.add(thisgeometry);
     }

     var totalObservations = resultFeatures.length;
     dojo.byId('messages').innerHTML = "<b>The total Observations within the buffer is <i>" + totalObservations + "</i>.</b>";
 });
    }

    dojo.addOnLoad(init);
0 Kudos
6 Replies
derekswingley1
Deactivated User
Can you verify that you're setting your query geometry correctly? Double-check that you're handling the result of the buffer properly.
0 Kudos
HaroldBostic
Frequent Contributor
Hello,

I believe that you have an error in your configuration but not in your proxy setup.  I think you need to increase the maximum records allowed within your config file for your mapservice.  The config file defaults to 500 so I'm assuming that is where you getting your returned count from.

Once you increase the value in the cfg file, be sure to restart your ArcSOM service (or reboot) as this is needed when making any changes to the cfg files.  Sorry I can't give you the path to the cfg file because I don't have access to my server right not but it's something like

ArcGIS install path\server\usr\config -----Don't quote me on that.....if you search for .cfg on your ArcGIS Server server the config file will have your map service as part of its name.
0 Kudos
BenStuder
Deactivated User
Hello,

I believe that you have an error in your configuration but not in your proxy setup.  I think you need to increase the maximum records allowed within your config file for your mapservice.  The config file defaults to 500 so I'm assuming that is where you getting your returned count from.

Once you increase the value in the cfg file, be sure to restart your ArcSOM service (or reboot) as this is needed when making any changes to the cfg files.  Sorry I can't give you the path to the cfg file because I don't have access to my server right not but it's something like

ArcGIS install path\server\usr\config -----Don't quote me on that.....if you search for .cfg on your ArcGIS Server server the config file will have your map service as part of its name.


Thanks for this answer! It made me realize I need to clarify a little, but its also a question I had going forward, so you beat me to the punch! I'll be using this configuration information in the very near future.

Sorry for not being clear.

The problem in the case I'm having is not that it's only returning 500 records... the data I am using and the buffer I'm using shouldn't be returning more than 50-100 records. The problem is that the points are not within the buffered point.
0 Kudos
HaroldBostic
Frequent Contributor
Ok, my apologies...glad it help in another way.....

Does the buffer graphic display as you expect it to?

What SR is the query map service in?
0 Kudos
BenStuder
Deactivated User
Can you verify that you're setting your query geometry correctly? Double-check that you're handling the result of the buffer properly.


Here is another piece to the puzzle. I verified that the geometry is correct.

What I found is that, the post is being encoded into html, and the (" - quotes) within the json to specify the buffer perimeter (around wkid, and ring for example) don't appear to be un-encoding back to quotes.

I'm not sure if this is caused from any of the following:

  • From the Proxy configuration

  • From the Setup in my JavaScript

  • or, from the Proxy debugger (Charles) I used to verify which parameters were being sent.


I'll look into this some more and do some more testing, but when I do a post to the rest query for this layer, it's happy so long as the parameters are not URL-encoded.
0 Kudos
BenStuder
Deactivated User
Ok, my apologies...glad it help in another way.....

Does the buffer graphic display as you expect it to?

What SR is the query map service in?


The buffer graphic displays correctly.

To simplify everything, I verified and am using 4326 (WGS84) for every thing.
0 Kudos