AnsweredAssumed Answered

SPATIAL_REL_INTERSECTS

Question asked by lkoumis on Jul 31, 2018
Latest reply on Aug 1, 2018 by lkoumis

I want to replicate the behavior of Arcmap analysis tools/overlay/intersect tool by using SPATIAL_REL_INTERSECTS.

In that tool, when you specified two polygon classes, it doesn't matter the order, the area of intersection is the same.

 

I want the users to be able to use any two polygon classes to run the intersect tool to get the intersected area.

 

I am using the script below. If I switch the first layer with the second the results are different. Why? The intersected area should be the same regardless which layer is specified as first or second. Thanks.

var firstgraphics = [];
            var features = [];
            array.forEach(firstlayer.graphics, function (feature) {
              firstgraphics.push(feature.geometry)
            })

            var secondgraphics = [];
            array.forEach(secondlayer.graphics, function (feature1) {
              secondgraphics.push(feature1.geometry)
            })
          

            var queryTask = new esri.tasks.QueryTask(firstlayer.url);
            queryTask.on("error", this.queryTaskErrorHandler);
            for (j = 0; j < secondgraphics.length; j++) {
              query = new esri.tasks.Query();
              query.geometry = secondgraphics[j];
              query.returnGeometry = true;
              query.where = "1=1";
              query.maxAllowableOffset=0;
              query.distance=0;
              query.outFields = ["*"];
              query.outSpatialReference = this.map.spatialReference;
              query.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;
              queryTask.execute(query, function (results) {
                  for (i = 0; i < results.features.length; i++) {
                    console.log(results.features[i].attributes);
                   // thefeatureSet =  results.results[i];
                    var graphic = new esri.Graphic(results.features[i].geometry, inter_symbol);
                    bufferGraphicsLayer.add(graphic);
                  }
                })
              }
           

              this.map.addLayer(bufferGraphicsLayer);
          
            },

 

Outcomes