Apply a filter to intersection query in ArcGIS Online

726
2
Jump to solution
05-30-2023 06:43 AM
Labels (1)
DaveBoyer
New Contributor II

I created a Web Application and I'm looking to enhance some of the user interactions.

I want any filters applied to a layer to hold when running an intersection query.

For example, filter a polygon "Layer X" by a name. Then use the intersection query to use "Layer X" to pull a list of features on "Layer Y" intersected by only the filtered data.

Right now, with either a filter on or off, the intersection query returns all intersections between both layers.

When a filter is on, there is a warning triangle in the query box (see image). But, the results are the same as with no filter activated.

 

0 Kudos
1 Solution

Accepted Solutions
DaveBoyer
New Contributor II

I figured out a couple of workarounds.

One way is to build a query and have it create a temporary layer that can be selected and used in the intersection query. This is the simplest method without having to interact with the map directly.

Another way requires the layer you want filtered to be turned on the map. Then when running the intersection query, the user clicks the black box next to the layer name to select features on the map. The intersection query can then be applied. 

Both methods are working, but it would be nice to be able to add the initial query (or a filter) directly to the intersection query widget.

View solution in original post

0 Kudos
2 Replies
DaveBoyer
New Contributor II

I figured out a couple of workarounds.

One way is to build a query and have it create a temporary layer that can be selected and used in the intersection query. This is the simplest method without having to interact with the map directly.

Another way requires the layer you want filtered to be turned on the map. Then when running the intersection query, the user clicks the black box next to the layer name to select features on the map. The intersection query can then be applied. 

Both methods are working, but it would be nice to be able to add the initial query (or a filter) directly to the intersection query widget.

0 Kudos
DaltonSilhan
New Contributor

You could also store the definition expression in a useState variable and supply said variable into a "where" condition within an intersection query. This variable could be updated every time a filter selection is changed and on any view change in a useEffect. From the sound of your issue my example isn't formatted for exactly what you want but the process should be similar. Ex: 

const [propertyDefinitionExpression, setPropertyDefinitionExpression] = useState('');

const applyPropertyLayerFilters = () => {
    if (mapDiv.current && view != null) {
      let terms = [];
      if (propertyTypeExpression) {
        terms.push(propertyTypeExpression);
      }

      let propertyLayer = view.map.findLayerById('Property');

      const definitionExpression = terms.map(term => `(${term})`).join(" AND ");

      if (propertyLayer) {
        propertyLayer.definitionExpression = definitionExpression;
      }

      setPropertyDefinitionExpression(definitionExpression);
    }
  }

  useEffect(applyPropertyLayerFilters,
    [mapDiv, propertyTypeExpression, view]
  );

function queryFeatures(polygon, count) {

propertyLayer
          .queryFeatures({
            geometry: polygon,
            where: propertyDefinitionExpression,
            // distance and units will be null if basic query selected
            distance: distance,
            units: units,
            spatialRelationship: "intersects",
            returnGeometry: false,
            returnQueryGeometry: true,
            outFields: ["*"],
            maxRecordCountFactor: 5
          })
          .then((featureSet) => {})
}

 

0 Kudos