Inverse of view definition for a hosted feature layer

03-23-2021 05:08 PM
New Contributor II

Hi there! 

Does anyone have any ideas on how to set the view definition for a hosted feature layer so that everything is visible EXCEPT a specific area defined by a polygon? From what I've read here it seems one can only define the visible area, not the inverse.

Thanks in advance for any ideas!


0 Kudos
2 Replies
MVP Esteemed Contributor

Do you want to define a definition query for filtering out one or more features (based on attribute value)?

You can Set View Definition > Define Features > Choose relationship method "IS NOT" or similar


Alternatively, you may also choose Filter tool 


However, if you want to inverse the Set Definition by drawing the extent, it might be currently unavailable.

0 Kudos
MVP Regular Contributor

If you look at the properties of the view layer in question, an area of interest definition looks like this:


"viewLayerDefinition": {
      "table": {
        "name": "1_Mile_Hex_Bins_0",
        "sourceServiceName": "1_Mile_Hex_Bins",
        "sourceLayerId": 0,
        "sourceId": 168,
        "filter": {
          "field": "Shape",
          "operator": "esriSpatialRelIntersects",
          "value": {
            "geometryType": "esriGeometryEnvelope",
            "geometry": {
              "xmin": -9852765.119535469,
              "ymin": 5091944.190591968,
              "xmax": -9833522.900104206,
              "ymax": 5110027.615063814,
              "spatialReference": {
                "wkid": 102100,
                "latestWkid": 3857
        "sourceLayerFields": [],
        "materialized": false


Note the operator. By default, this is intersects. I wish it were as simple as changing that to disjoint, but the REST API docs don't list that as an option.

Second thing to note is the value. Here, it's just an envelope, but that could just as easily be a polygon. Even a polygon that is essentially a global "donut", with the "donut hole" being the area we don't want.

This, I think, is the method we want. Let's give it a try. I have a layer of hex bins that cover my county. I have a view layer defined as shown above, being a subset of bins in the center.


Using the Python API, we'll access the FeatureLayerManager's update_definition() method, like so:

view_layer = gis.content.get('item-id').layers[0]

                        # Omitted for brevity


For that omitted portion, I used the polygon JSON of a donut feature which encompassed my entire dataset, the "donut hole" being the portion I wished to exclude. Mine was created from "surrounding counties", so it was more complex than yours would need to be.

Going back to my view layer after this, I now see the following features, along with the AOI:



To further refine this, you could also change the spatial relationship to "contains", to grab only those features fully contained within the donut polygon supplied.

It's a lot of work, but in short, it's definitely possible. 


- Josh Carlson
Kendall County GIS