Select to view content in your preferred language

Intersection of point, polyline & polygon with Arcade

3208
3
Jump to solution
02-26-2020 06:13 PM
haleygray
New Contributor

I'm having trouble finding the 3-way intersection of a point, polyline, and polygon. I have 3 feature layers with each containing one of the geometries. When a polygon is selected, I'm trying count the intersection of the point with polylines that are in the polygon boundaries.

I can find the intersection of polygon with point and polygon with polyline, but can't seem to figure out how to then find the point/polyline intersection. 

My thought process has been:

- Create 2 feature sets from the point feature layer and polyline feature layer

- Find intersection of those feature sets with the polygon

- Loop through the point feature set, explicitly make a point geometry from the feature, add buffer to the geometry,  test for intersection with the polyline feature set, and increment a counter if intersects returns true

Initially, I wasn't explicitly creating a point geometry from the feature as from my understanding of the arcade documentation, the intersects function should take a feature or geometry as a parameter along with a feature set. However, since that wasn't working, I tried to create the point geometry to see if that would resolve the problem.

This isn't yielding any results, and I'm at loss now. I also tried doing this the reverse way of looping through the polyline feature set and checking for intersection with the point feature set though that also wasn't working (and didn't make as much sense).

Any help would be very much appreciated!

Arcade Script:

//create feature sets from 2 layers

var accidentFeatureSet = FeatureSetByName($map,"Bicycle Accidents 2012 - 2018");
var bikewayFeatureSet = FeatureSetByName($map, "Bikeways");

//accidents feature set that intersects with the polygon ($feature)

var accidents = Intersects(
$feature,
accidentFeatureSet
);

//bikeway features set that intersects with the polygon ($feature)
var bikeways = Intersects(
$feature,
bikewayFeatureSet
);

var accidentOnBikewayCount = 0;

//loop through accidents feature set

//create point geometry for each accident feature and add buffer

//perform intersection of the accident geometry with bikeway feature set 

//if intersects == true, increase count


for(var feature in accidents){

   var geom = Point(Geometry(feature));


   var buffer = BufferGeodetic(geom, 10, 'feet');

   if(Intersects(bikeways,buffer) == true)

      accidentOnBikewayCount ++;
}

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi haley gray ,

See the code below:

//create feature sets from 2 layers
var accidentFeatureSet = FeatureSetByName($map,"Bicycle Accidents 2012 - 2018");
var bikewayFeatureSet = FeatureSetByName($map, "Bikeways");

//accidents feature set that intersects with the polygon ($feature)
// first parameter: Geometry / Feature / FeatureSet
// second parameter: Geometry / Feature (Note: no FeatureSet!)
var accidents = Intersects(accidentFeatureSet, $feature);

//bikeway features set that intersects with the polygon ($feature)
var bikeways = Intersects(bikewayFeatureSet, $feature);

//loop through accidents feature set
//create point geometry for each accident feature and add buffer
//perform intersection of the accident geometry with bikeway feature set 
//if intersects == true, increase count
// Don't use "feature" and/or "buffer", since thse are a reserved words in Arcade
var accidentOnBikewayCount = 0;
for(var f in accidents){
    var buf = BufferGeodetic(f, 10, 'feet');
    if(Count(Intersects(bikeways, buf)) > 0) {
        // bikeway near accident point (<= 10 feet)
        accidentOnBikewayCount ++;
    }
}

return accidentOnBikewayCount;

A couple of comments on your expression:

  • The Intersects function does not take a FeatureSet as second argument. The Featureset should be specified as first argument (see lines 8 and 11)
  • Don't use "feature" and "buffer" as variable names since these are reserved names in Arcade (see line 19, 20 and 21)
  • return the result at the end of the expression

View solution in original post

3 Replies
XanderBakker
Esri Esteemed Contributor

Hi haley gray ,

See the code below:

//create feature sets from 2 layers
var accidentFeatureSet = FeatureSetByName($map,"Bicycle Accidents 2012 - 2018");
var bikewayFeatureSet = FeatureSetByName($map, "Bikeways");

//accidents feature set that intersects with the polygon ($feature)
// first parameter: Geometry / Feature / FeatureSet
// second parameter: Geometry / Feature (Note: no FeatureSet!)
var accidents = Intersects(accidentFeatureSet, $feature);

//bikeway features set that intersects with the polygon ($feature)
var bikeways = Intersects(bikewayFeatureSet, $feature);

//loop through accidents feature set
//create point geometry for each accident feature and add buffer
//perform intersection of the accident geometry with bikeway feature set 
//if intersects == true, increase count
// Don't use "feature" and/or "buffer", since thse are a reserved words in Arcade
var accidentOnBikewayCount = 0;
for(var f in accidents){
    var buf = BufferGeodetic(f, 10, 'feet');
    if(Count(Intersects(bikeways, buf)) > 0) {
        // bikeway near accident point (<= 10 feet)
        accidentOnBikewayCount ++;
    }
}

return accidentOnBikewayCount;

A couple of comments on your expression:

  • The Intersects function does not take a FeatureSet as second argument. The Featureset should be specified as first argument (see lines 8 and 11)
  • Don't use "feature" and "buffer" as variable names since these are reserved names in Arcade (see line 19, 20 and 21)
  • return the result at the end of the expression
haleygray
New Contributor

Beautiful. Thank you very much!

XanderBakker
Esri Esteemed Contributor

Hi Fallling ,

You're welcome, I'm glad it works!

0 Kudos