Select to view content in your preferred language

spatial filter for relationship query?

1811
9
Jump to solution
11-22-2013 06:46 AM
KaitlynnDavis
Regular Contributor
Is there a spatial filter property for relationship queries like there is for normal queries? I was not able to find one, but it seems strange that you wouldn't be able to specify the geometry for your relationship query...
0 Kudos
1 Solution

Accepted Solutions
JasonZou
Frequent Contributor
Try the below code. It should be much more efficient than loop through each geometry for reproject and intersect operations. If not working still, please point out which line failed.

documents.queryRelatedFeatures(queryRecPoint, function (relatedRecords) {     fset = relatedRecords[fsetObjectIDArrayPoint[0]];     params = new esri.tasks.ProjectParameters();     params.geometries = array.map(fset.features, function (aFeature) {         return aFeature.geometry;     });     params.outSR = map.spatialReference;     //gsvc is my geometry service     gsvc.project(params, function (geoms) {         gsvc.intersect(geoms, firstGraphic.geometry, function (intGeoms) {             var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 200, 200]), 1), new dojo.Color([0, 0, 200, 0.25]));             array.forEach(intGeoms, function (aGeom) {                 var intersectGraphic = new esri.Graphic(aGeom, symbol, null, infoTemplate);                 map.graphics.add(intersectGraphic);             });         });     }); });

View solution in original post

0 Kudos
9 Replies
RyanClancy
Frequent Contributor
Yes. Check out the Constants property on the query class.

Constant Description
SPATIAL_REL_CONTAINS Part or all of a feature from feature class 1 is contained within a feature from feature class 2.
SPATIAL_REL_CROSSES The feature from feature class 1 crosses a feature from feature class 2.
SPATIAL_REL_ENVELOPEINTERSECTS The envelope of feature class 1 intersects with the envelope of feature class 2.
SPATIAL_REL_INDEXINTERSECTS The envelope of the query feature class intersects the index entry for the target feature class.
SPATIAL_REL_INTERSECTS Part of a feature from feature class 1 is contained in a feature from feature class 2.
SPATIAL_REL_OVERLAPS Features from feature class 1 overlap features in feature class 2.
SPATIAL_REL_RELATION Allows specification of any relationship defined using the Shape Comparison Language.
SPATIAL_REL_TOUCHES The feature from feature class 1 touches the border of a feature from feature class 2.
SPATIAL_REL_WITHIN The feature from feature class 1 is completely enclosed by the feature from feature class 2

Lets assume the variable 'feature' is a graphic:
queryTask = new QueryTask(...url to your service...)
query = new Query();

query.geometry = feature.geometry;
query.spatialRelationship = Query.SPATIAL_REL_INTERSECTS;
query.returnGeometry = true;
query.outFields = ["myField", "myOtherField"];
...etc with the other query parameters...

queryTask.execute(query);


This will return any features from the queried service which intersect the geometry of 'feature'.
0 Kudos
RyanClancy
Frequent Contributor
....whoops. You were probably referring to RelationshipQuery. My bad.
0 Kudos
KaitlynnDavis
Regular Contributor
that would be correct, but it is a nice explanation regardless!

I guess that the only thing I can do is perform a normal query against my relationship query results in order to use a spatial filter...
0 Kudos
JasonZou
Frequent Contributor
Can you explain a bit more what you like to accomplish?
0 Kudos
KaitlynnDavis
Regular Contributor
When I execute my relationship query, instead of showing all related records, I only want those that intersect with a particular geometry (in this case, county boundaries). It does not appear though the following is a valid relationship query parameter;

myRelationshipQuery.spatialRelationship = esri.tasks.Query.SPATIAL_REL_INTERSECTS;


I don't know if there are any alternative approaches to refine my relationship query results to a particular spatial region
0 Kudos
JasonZou
Frequent Contributor
I see. Unfortunately, I don't see a direct way to do that. What you can do is to use geometryService.intersect(geometries,geometry,callback?,errback?) to filter the geometries returned from the relationship query.
0 Kudos
KaitlynnDavis
Regular Contributor
I tried your suggestion and it looks like I did not construct the intersect correctly...

I have to take an extra step after my relationship query completes and reproject my output. The reproject works fine but my intersect breaks before I'm even able to step into it, so it's not liking the parameters I'm providing. I first provide an array of my reprojected graphics' geometry, then the geometry of my "firstGraphic" with which to intersect, and a callback. I'm not sure where I'm going wrong with the intersect.

documents.queryRelatedFeatures(queryRecPoint, function(relatedRecords) {
 fset = relatedRecords[fsetObjectIDArrayPoint[0]];
 for(var i=0, il = fset.features.length; i < il; i++){
  thirdGraphics = fset.features;
  params = new esri.tasks.ProjectParameters();
  params.geometries = [thirdGraphics.geometry];
  params.outSR = map.spatialReference;
                //gsvc is my geometry service
  gsvc.project(params, function(features){
   newPoints = features[0];
   projectedGraphicPoint = new esri.Graphic(newPoints);
  });
  gsvc.intersect([projectedGraphicPoint.geometry], firstGraphic.geometry, function(intFeature){
   var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0,200,200]), 1), new dojo.Color([0,0,200,0.25]));
   var intersectGraphic = new esri.Graphic(intFeature);
   intersectGraphic.setSymbol(symbol);
   intersectGraphic.setInfoTemplate(infoTemplate);
   map.graphics.add(intersectGraphic);
  });
});
0 Kudos
JasonZou
Frequent Contributor
Try the below code. It should be much more efficient than loop through each geometry for reproject and intersect operations. If not working still, please point out which line failed.

documents.queryRelatedFeatures(queryRecPoint, function (relatedRecords) {     fset = relatedRecords[fsetObjectIDArrayPoint[0]];     params = new esri.tasks.ProjectParameters();     params.geometries = array.map(fset.features, function (aFeature) {         return aFeature.geometry;     });     params.outSR = map.spatialReference;     //gsvc is my geometry service     gsvc.project(params, function (geoms) {         gsvc.intersect(geoms, firstGraphic.geometry, function (intGeoms) {             var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 200, 200]), 1), new dojo.Color([0, 0, 200, 0.25]));             array.forEach(intGeoms, function (aGeom) {                 var intersectGraphic = new esri.Graphic(aGeom, symbol, null, infoTemplate);                 map.graphics.add(intersectGraphic);             });         });     }); });
0 Kudos
KaitlynnDavis
Regular Contributor
The intersect tool was just what I needed. Many thanks for the helpful code sample!
0 Kudos