AnsweredAssumed Answered

Query by distance

Question asked by margaraiz on Sep 30, 2016
Latest reply on Oct 5, 2016 by margaraiz



I am trying to query by distance 2 layer (points and lines), I mean I have an initial point and I want to find the closest lines that are within 10 meters.

Afther doing some research in this forum this is my try:


First I query the point layer looking for the source point and I create a graphic symbol:

      var resultFeatures = results.features;
      symbol = new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255, 0, 0]), 3);
      var point= new esri.Graphic(resultFeatures[0].geometry, symbol);


I create a new query with this parameters:

 var query = new Query();
       queryTask = new QueryTask(lines_layer.url);               
       query.geometry = [point.geometry];
       query.distance = [10];
       query.units = esri.tasks.GeometryService.UNIT_METER;
       query.returnGeometry = true;
       query.outSpatialReference = new SpatialReference({ wkid: 102100 }); //ETRS89
       query.spatialRelationship = Query.SPATIAL_REL_CONTAINS;



I launch the query:


queryTask.execute(query).then(function (qResults) {
         //  Here goes the code for looping qResults of the lines elements

         //  that are close than 10 meters from the initial point.

Is this the correct approach to launch a query by distance (similar to the one that arcmap haves)?