SPATIAL_REL_INTERSECTS

832
4
Jump to solution
07-31-2018 02:40 PM
LefterisKoumis
Occasional Contributor III

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;
                    var graphic = new esri.Graphic(results.features[i].geometry, inter_symbol);
                    bufferGraphicsLayer.add(graphic);
                  }
                })
              }
            

              this.map.addLayer(bufferGraphicsLayer);
           
            },‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

   It makes perfect sense that they are different depending on which layer is specified as the source layer. You are doing a QueryTask which is just giving you the features that intersect (meaning Part of a feature from feature class 1 is contained in a feature from feature class 2). You are not doing a GeometryService Intersect operation where the geometry returned is the intersecting portions of the two geometries. The QueryTask will just return the full features that intersects the other feature.

View solution in original post

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

   It makes perfect sense that they are different depending on which layer is specified as the source layer. You are doing a QueryTask which is just giving you the features that intersect (meaning Part of a feature from feature class 1 is contained in a feature from feature class 2). You are not doing a GeometryService Intersect operation where the geometry returned is the intersecting portions of the two geometries. The QueryTask will just return the full features that intersects the other feature.

0 Kudos
LefterisKoumis
Occasional Contributor III

Got it. Your response: "The QueryTask will just return the full features that intersects the other feature." should be included in ESRI docs.

One more question. Do you know what the  Arcmap analysis tools/overlay/intersect tool is running on? I am trying to create a tool to use in wab where you don't specify a source layer. Thanks.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Lefteris,

   What ArcMap does is based on ArcObjects on the desktop machine and NOT applicable to a Server environment. The only option you have is to use GeometryService.intersect or GeometryEngine.intersect.

0 Kudos
LefterisKoumis
Occasional Contributor III

ok. Thank you.

0 Kudos