How to select polygons using a feature set of points?

4280
4
Jump to solution
07-13-2015 01:41 PM
JaniceBaird
Occasional Contributor II

I have a list of id's that I use to select points with matching id's. I then want to use the selected points to select all of the polygons which contain them. I am using a querytask with a where clause to select the points. Now I am not sure how to go about selecting the polygons. Do I need to step through the set of points and use each point geometry individually to select the polygon which contains it?

Any ideas welcome!

0 Kudos
1 Solution

Accepted Solutions
ChrisSmith7
Frequent Contributor

Janice,

I'm not sure if you want to use this yet (it's in Beta in v3.13), but there's a way to process this client-side:

esri/geometry/geometryEngineAsync | API Reference | ArcGIS API for JavaScript

Specifically, contains() would probably help you:

esri/geometry/geometryEngineAsync | API Reference | ArcGIS API for JavaScript

I haven't worked with the client-side geoprocessing yet... I would need to set-up some test apps to see what we can do with it. Perusing the API, though, it seems you would need to step over your points. There's also a way to do this synchronously:

esri/geometry/geometryEngine | API Reference | ArcGIS API for JavaScript

Here's the difference:

A client-side asynchronous geometry engine. The difference between the geometryEngineAsync and geometryEngine modules is the async functions return a Promise that are resolved with the same argument as is returned by the sync functions. See the union method for a code sample.

You could also union your points then run an intersect - that should probably work... Although, now that I think about it, intersect would give you points on the border, too. I'm not sure what the cluster tolerance would be in the API.

View solution in original post

4 Replies
ChrisSmith7
Frequent Contributor

Janice,

I'm not sure if you want to use this yet (it's in Beta in v3.13), but there's a way to process this client-side:

esri/geometry/geometryEngineAsync | API Reference | ArcGIS API for JavaScript

Specifically, contains() would probably help you:

esri/geometry/geometryEngineAsync | API Reference | ArcGIS API for JavaScript

I haven't worked with the client-side geoprocessing yet... I would need to set-up some test apps to see what we can do with it. Perusing the API, though, it seems you would need to step over your points. There's also a way to do this synchronously:

esri/geometry/geometryEngine | API Reference | ArcGIS API for JavaScript

Here's the difference:

A client-side asynchronous geometry engine. The difference between the geometryEngineAsync and geometryEngine modules is the async functions return a Promise that are resolved with the same argument as is returned by the sync functions. See the union method for a code sample.

You could also union your points then run an intersect - that should probably work... Although, now that I think about it, intersect would give you points on the border, too. I'm not sure what the cluster tolerance would be in the API.

thejuskambi
Occasional Contributor III

you can use geomertyEngine.union to combine all the points into single geometry and then use that in you queryTask.

check out this post Re: Multiple query tasks

RobertScheitlin__GISP
MVP Emeritus

Janice,

   If it is not important to know which point intersects which polygon, then I would create a Multipoint from your point geometries and use that in a single spatial Query by setting the Query object geometry property to that created Multipoint.

JaniceBaird
Occasional Contributor II

You all nailed it! I went ahead and used union and used the resulting multipoint to query the polygons. I suppose I could have just created a multipoint from my points as suggested by Robert but was well into my union code before reading his response.

If you are interested, here is the code:

    require(["dojo/_base/array","esri/tasks/query","esri/geometry/geometryEngine", "esri/SpatialReference"],

        function (array, Query, GeometryEngine, SpatialReference) {

            var urlParcelMap = dataLink + "/Assessor/PropertyMap/MapServer/";

            var arrayOutFields = ["PNUMBER"];

            initQueryTask(urlParcelMap, 4, arrayOutFields);

            query.where = "PNUMBER IN (" + searchString + ")";

            var pnums = queryTask.execute(query);

            pnums.then(function (fset) {

                var pts = array.map(fset.features, function (feature) {

                    return feature.geometry;

                });

                var union = esriConfig.defaults.geometryService.union(pts);

                union.then(function (results) {

                    arrayOutFields = ["PARCELID"];

                    initQueryTask(urlParcelMap, 5, arrayOutFields);

                    query.spatialRelationship = Query.SPATIAL_REL_INTERSECTS;

                    query.geometry = results;

                    queryTask.execute(query, showCompQueryResults);

                });

            });

        });

0 Kudos