Select to view content in your preferred language

Find intersecting features

460
2
Jump to solution
04-24-2023 09:55 PM
Aeseir
by
Occasional Contributor

I have a scenario where there are multiple FeatureLayers with static features lets call them F1,F2,F3, and F4.

I also have a FeatureLayer called DF that has dynamic features (because the user goes out and makes changes depending on landscape).

I am trying to figure out if it is possible to compare all features in DF against all features in F1,F2,F3, and F4 and return set of intersecting features or geometries.

Idea is then to create a FeatureLayer with these intersecting points so that the user can see all the intersecting points.

 

Any advice as to how to approach this?

0 Kudos
1 Solution

Accepted Solutions
Sage_Wall
Esri Contributor

Hi @Aeseir, This should be possible with a combination of queries and geometryEngine.intersects().

  • Use the queryFeatures() method of the Dynamic FeatureLayer (DF) to retrieve all the features. This method returns a FeatureSet object.

  • For each of the static FeatureLayers (F1, F2, F3, and F4), use the queryFeatures() method to retrieve all the features.

  • Iterate through each feature in the FeatureSet of the Dynamic FeatureLayer (DF), and for each feature, loop through all the features in the FeatureSets of the static FeatureLayers (F1, F2, F3, and F4).

  • For each pair of features (one from DF and one from a static FeatureLayer), use the intersects() method in the geometryEngine  or geometryEngineAsync or  to determine if they intersect. If they do intersect, add the intersecting feature or geometry to a new array of intersecting features.

  • Add the intersecting features to a new FeatureLayer as the source property.  There is a sample here on creating a feature layer with client-side graphics: https://developers.arcgis.com/javascript/latest/sample-code/layers-featurelayer-collection/

 

Maybe something like this at a really high level, there may be typos below.

 

 

 

 

 

const intersectingFeatures = [];

df.queryFeatures().then((dfFeatureSet) => {
    
    // Loop through each feature in the Dynamic FeatureLayer (DF)
    dfFeatureSet.features.forEach((dfFeature) => {
      
      // Loop through all features in the static FeatureLayers (F1, F2, F3, and F4)
      [f1, f2, f3, f4].forEach((staticFeatureLayer) => {
        
        // Query all features from the static FeatureLayer
        staticFeatureLayer.queryFeatures().then((staticFeatureSet) => {
          
          // Loop through all features in the static FeatureLayer
          staticFeatureSet.features.forEach((staticFeature) => {
            
            // Determine if the features intersect
            if (geometryEngine.intersects(dfFeature.geometry, staticFeature.geometry)) {
              
              // Add intersecting feature or geometry to an array of intersecting features
              intersectingFeatures.push(new Graphic({
                 geometry: dfFeature.geometry,
                 // additional graphic properties
               }));
              
            }
          });
        });
      });
    });
  // Add the intersecting features to the map as a new feature layer
  const newFeatureLayer = new FeatureLayer({
    source: intersectingFeatures,
    // additional properties
  });
});
 

 

 

 

 

 

 

View solution in original post

0 Kudos
2 Replies
Sage_Wall
Esri Contributor

Hi @Aeseir, This should be possible with a combination of queries and geometryEngine.intersects().

  • Use the queryFeatures() method of the Dynamic FeatureLayer (DF) to retrieve all the features. This method returns a FeatureSet object.

  • For each of the static FeatureLayers (F1, F2, F3, and F4), use the queryFeatures() method to retrieve all the features.

  • Iterate through each feature in the FeatureSet of the Dynamic FeatureLayer (DF), and for each feature, loop through all the features in the FeatureSets of the static FeatureLayers (F1, F2, F3, and F4).

  • For each pair of features (one from DF and one from a static FeatureLayer), use the intersects() method in the geometryEngine  or geometryEngineAsync or  to determine if they intersect. If they do intersect, add the intersecting feature or geometry to a new array of intersecting features.

  • Add the intersecting features to a new FeatureLayer as the source property.  There is a sample here on creating a feature layer with client-side graphics: https://developers.arcgis.com/javascript/latest/sample-code/layers-featurelayer-collection/

 

Maybe something like this at a really high level, there may be typos below.

 

 

 

 

 

const intersectingFeatures = [];

df.queryFeatures().then((dfFeatureSet) => {
    
    // Loop through each feature in the Dynamic FeatureLayer (DF)
    dfFeatureSet.features.forEach((dfFeature) => {
      
      // Loop through all features in the static FeatureLayers (F1, F2, F3, and F4)
      [f1, f2, f3, f4].forEach((staticFeatureLayer) => {
        
        // Query all features from the static FeatureLayer
        staticFeatureLayer.queryFeatures().then((staticFeatureSet) => {
          
          // Loop through all features in the static FeatureLayer
          staticFeatureSet.features.forEach((staticFeature) => {
            
            // Determine if the features intersect
            if (geometryEngine.intersects(dfFeature.geometry, staticFeature.geometry)) {
              
              // Add intersecting feature or geometry to an array of intersecting features
              intersectingFeatures.push(new Graphic({
                 geometry: dfFeature.geometry,
                 // additional graphic properties
               }));
              
            }
          });
        });
      });
    });
  // Add the intersecting features to the map as a new feature layer
  const newFeatureLayer = new FeatureLayer({
    source: intersectingFeatures,
    // additional properties
  });
});
 

 

 

 

 

 

 

0 Kudos
JohnGrayson
Esri Regular Contributor

Another option would be to let the service perform the intersection test by passing in the dynamic feature geometry into the query; something similar to this but with all the appropriate Query parameters:

const staticQuery = staticFeatureLayer.createQuery();
staticQuery.geometry = dfFeature.geometry;
staticFeatureLayer.queryFeatures(staticQuery).then((staticFeatureSet) => {