I have a map service which contains a number of polygons. I am looking to get two different sets of results:
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?
Solved! Go to Solution.
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.
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.
There are multipart polygons in this map service, however all polygons within this particular extent are singlepart.
Correction, turns out there were multipart polygons in the extent.
Just a thought...is the projection the same between the feature class you're querying and the aoiExtent variable?