Inverse of view definition for a hosted feature layer

666
2
03-23-2021 05:08 PM
lavpizzo
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 herehttps://doc.arcgis.com/en/arcgis-online/manage-data/set-view-definition.htmit seems one can only define the visible area, not the inverse.

Thanks in advance for any ideas!

0Kudos
2 Replies
JayantaPoddar
MVP Esteemed Contributor

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

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

Jayanta_Poddar_0-1616545787838.png

Alternatively, you may also choose Filter tool

Jayanta_Poddar_1-1616546022306.png

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



Think Location
0Kudos
jcarlson
MVP Esteemed 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 theoperator. By default, this isintersects. I wish it were as simple as changing that todisjoint, but the REST API docs don't list that as an option.

Second thing to note is thevalue. 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.

jcarlson_0-1616553086404.png

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

view_layer = gis.content.get('item-id').layers[0] view_layer.manager.update_definition( {"viewLayerDefinition":{ "filter":{ "operator":"esriSpatialRelIntersects", "value":{ "geometryType":"esriGeometryPolygon", "geometry":{ "rings":[ # Omitted for brevity ], "spatialReference":{"wkid":102100,"latestWkid":3857} } } } } })

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.

回去后我的视图层this, I now see the following features, along with the AOI:

jcarlson_0-1616559197028.png

Perfect!

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