Query with SPATIAL_REL_WITHIN does not return any results

3806
4
Jump to solution
11-16-2015 07:28 AM
VygintasCesnauskas
New Contributor III

I have a map service which contains a number of polygons. I am looking to get two different sets of results:

  • All polygons which are fully contained within an extent
  • All polygons which are intersected by an extent.

To achieve this I am using following code:

var containedProjQuery = new Query();
var containedProjQueryTask = new QueryTask(configuration.documentParams.ProjectMapService);
containedProjQuery.spatialRelationship = Query.SPATIAL_REL_WITHIN;
containedProjQuery.returnGeometry = true;
containedProjQuery.outFields = ["PROJ_NAME"];
containedProjQuery.geometry = aoiExtent;
var containedProjects = containedProjQueryTask.execute(containedProjQuery);

var intersectingProjQuery = new Query();
var intersectingProjQueryTask = new QueryTask(configuration.documentParams.ProjectMapService);
intersectingProjQuery.spatialRelationship = Query.SPATIAL_REL_INTERSECTS;
intersectingProjQuery.returnGeometry = true;
intersectingProjQuery.outFields = ["PROJ_NAME"];
intersectingProjQuery.geometry = aoiExtent;
var intersectingProjects = intersectingProjQueryTask.execute(intersectingProjQuery);

var promises = All([containedProjects, intersectingProjects]);
promises.then(returnResults);

The issue I'm running into is that the SPATIAL_REL_WITHIN query always returns 0 results, while SPATIAL_REL_INTERSECTS appears to work correctly. Is there something I'm missing?

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

Are you dealing with multipart polygons?  If you have multipart polygons and one or more of the parts are not wholly within another polygon, the spatial selection will not return the multipart polygon.

View solution in original post

0 Kudos
4 Replies
JoshuaBixby
MVP Esteemed Contributor

Are you dealing with multipart polygons?  If you have multipart polygons and one or more of the parts are not wholly within another polygon, the spatial selection will not return the multipart polygon.

0 Kudos
VygintasCesnauskas
New Contributor III

There are multipart polygons in this map service, however all polygons within this particular extent are singlepart.

0 Kudos
VygintasCesnauskas
New Contributor III

Correction, turns out there were multipart polygons in the extent.

0 Kudos
by Anonymous User
Not applicable

Just a thought...is the projection the same between the feature class you're querying and the aoiExtent variable?

0 Kudos