Disjoint Query

286
9
Jump to solution
04-03-2019 05:00 AM
TylerWaring1
New Contributor III

Greetings, 

I'm trying to write a disjoint query to get an indication of which features are outside of the mapView's extent. I've structured the query but it appears that the spatial relationship "disjoint" produces the same results as using "intersect". 

var deleteQuery = fl.createQuery();
deleteQuery.geometry = webMercatorUtils.webMercatorToGeographic(mapExtent);

deleteQuery.spatialRelationship = "disjoint"; // this is the default
deleteQuery.returnGeometry = false;
deleteQuery.outFields = [ "OBJECTID" ];
fl.queryFeatures().then(function(disjointResults){
fl.applyEdits({deleteFeatures:disjointResults.features})
.then(function(delResults) {
fl.queryFeatureCount().then(function(count){
console.log('AFTER delete fl feature Count: ' + count)
})
})
})‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

 Not sure what I am doing wrong. Does anyone see any glaring mistakes? 

I logged my query to JSON and thought the '"where":"1=1"' part looked odd since I didn't specify a where property. 

{"geometry":{"spatialReference":{"wkid":4326},"xmin":-78.78690645507774,"ymin":35.78811526137758,"xmax":-78.77317354491959,"ymax":35.79110471050848},"outFields":["OBJECTID"],"returnGeometry":false,"spatialRel":"disjoint","where":"1=1"}

Any ideas will be greatly appreciated. 


Thanks, Tyler 

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

No it is more likely that disjoint in not supported on local FeatureLayers. What you can do is do a query for ObectIds of the features that intersect and then when you get that array of OIDs then use a Query.where = "NOT OBJECTID IN (" + your array of OIDS +")";

View solution in original post

9 Replies
RobertScheitlin__GISP
MVP Esteemed Contributor

Tyler,

   What is the spatial reference of the layer you are querying? You are getting a where 1=1 because you are using 

var deleteQuery = fl.createQuery();

and the default is where 1=1.

TylerWaring1
New Contributor III

The WKID of my feature layer is also 4326 . The feature layer is a client side feature layer rather than one created with a URL. 

Also, the map spatialReference is {"latestWkid":3857,"wkid":102100} . 

Do all of the spatial references need to match for the disjoint to work?

Is the default '"where 1=1"' a problem? Is there a better way to create the query rather than fl.createQuery?

Thanks, Tyler 

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Tyler,

   I am not real sure what the issue is. But this is what I would try.

  1. do return the geometry.
  2. return all fields
  3. set the query.where to null
TylerWaring1
New Contributor III

I made the suggested changes but it appears that 'disjoint' is still performing an intersect. 

var deleteQuery = fl.createQuery();
deleteQuery.geometry = webMercatorUtils.webMercatorToGeographic(mapExtent);
deleteQuery.spatialRelationship = "disjoint"; // this is the default
deleteQuery.returnGeometry = true;
deleteQuery.outFields = [ "*" ];
deleteQuery = null
fl.queryFeatures().then(function(disjointResults){
fl.applyEdits({deleteFeatures:disjointResults.features})
.then(function(delResults) {
fl.queryFeatureCount().then(function(count){
console.log('AFTER delete fl feature Count: ' + count)
})
})
})

Are there any other means you can think of to delete features outside of the map extent?

The need for this is that I am querying a map service for some json based on the mapView extent. I'm then querying our Salesforce instance to get additional attribute information. Once I have the map service and Salesforce data I perform a join and add the features to a client side featureLayer. Each time the map extent changes I query our feature service and Salesforce instance again. For speed and to housekeep the feature layer, I want to only add features that are not currently in the feature layer and delete features that are no longer in the map extent.

I suppose I could just delete all the features before I add them and be done with it. However, if there are multiple layers with complex geometries I want to be as efficient as possible. 

Thanks, Tyler  

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

Tyler,

   I did not notice this earlier. You are never using the deleteQuery.

fl.queryFeatures().then(function(disjointResults){

it should be

fl.queryFeatures(deleteQuery).then(function(disjointResults){
TylerWaring1
New Contributor III

Ha. Thanks for catching that. I am applying the query correctly to the feature layer now. However the query is now erring out with a spatial relationship of 'disjoint'

My catch statement is erring with this message: 


[feature-store:unsupported-query]: Unsupported query spatial relationship

However, when I use 'intersect', 'contains', 'crosses', 'envelope-intersects', 'overlaps', 'touches' or 'within', the query executes properly. 

My JavaScript API version is 4.10. Could it be that 'disjoint' has just been added to version 4.11? I am unable to find a link to the 4.10 documentation. 

Thanks a ton for your help, 

Tyler 

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

No it is more likely that disjoint in not supported on local FeatureLayers. What you can do is do a query for ObectIds of the features that intersect and then when you get that array of OIDs then use a Query.where = "NOT OBJECTID IN (" + your array of OIDS +")";

View solution in original post

TylerWaring1
New Contributor III

Cool. Thank you.  I'm going to try this tomorrow. Unfortunately I'm going to be in meeting for the rest of the day.

I'll let you know how it goes. 

0 Kudos
TylerWaring1
New Contributor III

Hi Robert,

I forgot I had to do one little thing to my query. 

I had to throw a join in to concatenate the array into a string:

query.where = "OBJECTID IN ('"+array.join("','")+"')"

Then everything was good to go. 

Thanks, Tyler 

0 Kudos