Select to view content in your preferred language

Spatial definition query

16745
44
04-26-2010 04:36 AM
Status: Under Consideration
Labels (1)
HenkZwols
Regular Contributor

I would like to be able to apply a spatial definition query to a layer.

I.e. Select features from this pointlayer that are within a feature from buildingpolygons.

Defining a query must be as easy as it can be done in the Select By Location dialog.

The result of the query is updated when features that are involved are modified.

44 Comments
by Anonymous User

Working with large eGIS datasets, I often find myself working with only a subset of the data in a feature class, generally in a specific part of the province. Harvest data is tied spatially to clients in "districts" and, depending on the task, I either export/clip the subset of harvest data into a new layer or run a layer query to narrow my search and reduce how much is displayed on the map. The former is an extra step and increases the number of intermediate layers to manage (which I try to keep to a minimum), while the latter is limited to tabular queries based on attribute data. 90% of the time, I use both together because I need to query the data over a specific area (clip) and over a specific time period (layer query).

I would LOVE if we could have both steps incorporated into one, i.e. by having "Select by Location" built into Layer Queries, combining spatial and tabular queries together. That is the idea I am suggesting.

TanuHoque
Status changed to: Needs Clarification

@Anonymous User 

I have two questions for you:

1. is your data stored in an enterprise database or file gdb?

2. >> Harvest data is tied spatially to clients in "districts" <<
   are these district polygons coming from a separate Feature Layer?

by Anonymous User

Hello!

1. The Harvest data can come from either a gdb or enterprise database, usually eGIS.

2. Yes, the polygons are in a separate enterprise database layer.

In retrospect, I realize that I could easily create a model and ultimately my own tool for this; it is but one of many different scenarios where I have wished that ArcGIS would enable spatial and tabular queries. Sometimes I need to conduct multiple spatial and tabular queries on 2 or more eGIS/gdb layers before I can narrow down my search and begin working. This scenario is the simplest I could think of to describe my idea.

Thanks,

Ellie


TanuHoque

hi @Anonymous User,

As you see, after @KoryKramer merged your post here, we don't have any out of the box capability at this point.

For now, I can give you a workaround and it will ONLY work if:

  1. if both of your layers are coming from the same enterprise database (doesn't need to geodatabase).
    • won't work for file geodatabase
  2. both of them are in the same projection (on the fly projection won't work)

 

Steps to filter out features from layerA using feature(s) from layerB

  • First get the source FeatureClass name for layerA
    • do the same for layerB
      • let's assume they are named DS-A and DS-B respectively
  • Open layerA's Proeprty page
  • Switch to Definition Query page
  • Create a new one
  • Switch to SQL mode by clicking the SQL toggle button from the upper right corner
  • Paste one of the following two sql clauses.
    • even though the send one looks pretty straight forward, I found it didn't perform well in my quick test.
      • I'm not a SQL guru, therefore I can't explain why 😞
  • Click OK

 

The syntax provided below are for SQL Server. The STIntersects() function syntax will be different on PostgreSQL or Oracle or other databases.
SQL#1

objectid in (select DS-A.objectid from DS-A
inner join
(select shape from DS-B
where aField = 'aString_Value' ) a
on a.shape.STIntersects(DS-A.shape) = 1)


SQL#2

exists (select 1 from DS-B a where aField = 'aString_Value' and a.shape.STIntersects(DS-A.shape) = 1)

 

Here is animation showing how I did that on my side:

spatial_def_query.gif

by Anonymous User
Thank you! I will give it a try at the next available opportunity.


Boyang_Wang

I have a quick question regarding this:

I am trying to display this feature layer in ArcGIS Online Map Viewer. I only want to show the points in a certain county. As the data does not contain a county field, is there any way to do it in definition query other than typing the IDs of individual features?

https://idpgis.ncep.noaa.gov/arcgis/rest/services/NWS_Observations/ahps_riv_gauges/MapServer/0

Thanks,

Boyang

KoryKramer

Hi @Boyang_Wang It sounds like your question is about how to accomplish that working in the ArcGIS Online map viewer.  I would recommend posting a question to https://community.esri.com/t5/arcgis-online-questions/bd-p/arcgis-online-questions 

Boyang_Wang

@KoryKramer Sorry I did not realize this was a Pro forum. I do want to ask this question in Pro as well. For a map service with query enabled but export disabled, how do I display a subset of features in a given geographical area?

Thanks!

TanuHoque

@Boyang_Wang 

Unfortunately this is the supported at this point. Please up vote this idea as it appears important use case for you.

Bud
by

@JeffThomasILM 

Regarding your comment about caching:

I understand performance is a problem, but would it be possible to cache the selection set? E.g., You open the map and the layer with the spatial query grabs an up-to-date snapshot and caches it (or a portion of it, like Feature Cache in ArcMap) and remains static for the rest of the session or until the user chooses to manually refresh. This wouldn't work for constantly changing data, but it seems like it would work fine if the data only needs to be refreshed daily or weekly, and it's being used as a reference more than for active editing. Maybe that's too big of a caveat to bother explaining or implementing, but I think it would be worthwhile.

I have a related idea here: Control caching settings for better performance in event layers & query layers


Alternatively, running a scheduled job to precompute a field or a related table might work in some cases: What levels of the ArcGIS Enterprise stack support scheduled jobs?