Excluding Intersected Area/Points

578
2
08-06-2019 09:22 PM
HenryKo2
Occasional Contributor

I have a map service which are points. I have a polygon shape which intersects with the points. How do I find the points that are outside (i.e. excluded / differentiated ) the polygon shape? So this is essentially the opposite of "intersect", kind of like cutting a whole in the points with the polygon.

I know with intersect, I can do the following:

var queryParams = new Query();
queryParams.geometry = geometry; // This is the polygon shape.
queryParams.spatialRelationship = Query.SPATIAL_REL_INTERSECTS; // Optional as it is the default.

// ... QueryTask will execute with the above QueryParams to find intersected points on a layer. //

Is there something like:

var queryParams = new Query();
queryParams.geometry = geometry; // This is the polygon shape.
queryParams.spatialRelationship = Query.SPATIAL_REL_DIFFERENCE; // Or something like that.

// QueryTask will execute with the QueryParams to find the difference between the points and polygon. //

I have tried to use "SPATIAL_REL_RELATION" but no luck:

var queryParams = new Query();
queryParams.geometry = geometry; // This is the polygon shape.
queryParams.spatialRelationship = Query.SPATIAL_REL_RELATION;
queryParams.relationParam = "G1 NOT INTERSECT G2";

I have a huge number of points to deal with, so it is not practical to get all points, then find the intersected points, then subtract.

I am using ArcGIS API for JavaScript version 3.22.

0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus

Henry,


  The way that I would do this is to query for ids of the point that intersect and then use those ids in the returned array to formulate your query.where = “NOT OBJECTID IN (“ + oidarray.join(“,”) +”)”;

0 Kudos
HenryKo2
Occasional Contributor

Robert Scheitlin, GISP One promising way to do this, although I haven't tested fully, is to use the underlying database SDE spatial functions as the where-clause. We are using Oracle SDE ST_Geometry type, so in the database I can run plain SQL statement to find intersected points and an input polygon, like this:

SELECT POINT_ID
FROM MY_POINTS
WHERE SDE.ST_INTERSECTS(SHAPE, SDE.ST_GEOMETRY('POLYGON ((9689836.255 4420129.191, 9690576.399 4420184.417 , 9690295.144 4419703.323, 9689836.255 4420129.191))', 3308)) = 1 AND SHAPE IS NOT NULL

Here, I am using the SDE functions to do the intersect, with the input polygon given as a plain WKT string (spatial reference is 3308).

Now, I am able to use the above where clause on the map service to do the same. First I need to convert the input polygon into WKT string, then basically run the above query with a "not in" to find points outside of the intersected polygon:

var queryParams = new Query();
queryParams.where = 'POINT_ID NOT IN (SELECT POINT_ID FROM MY_POINTS WHERE SDE.ST_INTERSECTS(SHAPE, SDE.ST_GEOMETRY('POLYGON ((9689836.255 4420129.191, 9690576.399 4420184.417 , 9690295.144 4419703.323, 9689836.255 4420129.191))', 3308)) = 1 AND SHAPE IS NOT NULL)';

Still need to test for performance, write the actual JavaScript code, test what if the WKT string is too long... etc, but looks promising so far (e.g. I can dump that where-clause into the map service query REST end-point and it works).

0 Kudos