Creating a Filtered FeatureSet using Intersect and/or Contains/Within

326
9
02-19-2025 03:07 AM
DNMCSCADA
Occasional Contributor

Hi Community Members,

I'm trying to create a FeatureSet by intersecting it with another FeatureClass, but having problems. BTW the Portal Version is 11.3. The Scenario is fairly simple and I've read the documentation for intersects / Contains / WithIn.

  • for Intersects it is :
    • Intersects(features, inputGeometry) -> FeatureSet‎
  • For Contains it is:
    • Contains(containerGeometry, insideFeatures) -> FeatureSet‎
  • and for Within it is:
    • ‎Within(innerGeometry, outerFeatures) -> FeatureSet‎

Now as per my understanding, all these functions work with Features i.e FeatureSets against a Geometry, which could be a feature.

Here is what I've done so far:

 

var MyPortal = Portal("https://xyz.com/portal/");

var tempfs = FeatureSetByPortalItem(
  MyPortal,
  "5cab64be2ea5448aa5b5e220adf7bf05",
  0,
  ["*"],
  true
);

var fsRoads = 
  FeatureSetByPortalItem(
    MyPortal,
    "f4dfa29e2c0947cda6c7b9f2378253fd",
    0,
    ["*"],
    true
  )

 

Two featureSets, One Contains dissolved buffered Roads i.e. a single Feature and the other FeatureSet contains point Features. I'm trying to get a featureSet by:

 

var myfs = Intersects(tempfs, First(fsRoads))
return (myfs)

 

or 

 

var myfs = Within(first(fsRoads), tempfs)
return (myfs)

 

 or

 

var myfs = Contains(first(fsRoads), tempfs)
returns (myfs)

 

but all these do not seem to work, no matter what I do. I've checked the SRIDs of both FEatureSets, they are the same. Counted individual FeatureSets, Counts are Ok. but there is no result. Trying to generate a FeatureSet that could be used for other Items in a Dashboard.

This is the Error I get whenever I test it

 

Test execution error: Unknown Error. Verify test data.

 

Could anyone point me to the correct solution as I don't want to do it using a for loop, which BTW takes forever to work.

Thanks in advance for all the help.

0 Kudos
9 Replies
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

Try removing the First(<feature>) and simply use the layer. The issue with using first is that it pulls the first record in the table which may not intersect with the other layer. If the layers intersect, then you can then use the first function to get that specific record.

0 Kudos
DNMCSCADA
Occasional Contributor

Hi RPGIS,

I've tried this already. I used First() in the first place because, in the Arcade document, it is written that there should be one Geometry or a feature and not features. 

Anyway, the result is the same even if I try it without First().

0 Kudos
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

Just out of curiosity, have you tried testing this locally to see if any of the features overlap at all. If nothing overlaps, then regardless of the direction, there won't be any results.

Also, what kind of geometries are you using. If it is points and lines, then that might be the challenge since it would be very difficult to identify whether the points or lines intersect in the first place, but there are ways to identify which is the closest point to a line.

0 Kudos
DNMCSCADA
Occasional Contributor

Hi RPGIS,

Thanks for your reply, yes fsTemp is a point feature Class and fsRoads is basically a Dissolved buffer of certain road Classes resulting in a single feature. and yes in pro I can select using spatial operations and there are 1.5K point features that are inside this buffer.

The reason I want to do this for the time being is that I have no way of doing this in Pro that can be automatically updated. and creating a view and accessing it after publishing is too slow for the front-end.

I am also open to suggestions if it can be done in any other way.

Thanks in advance for any help.

0 Kudos
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

Hi @DNMCSCADA,

That helps a lot with that information that you provided. So try one of these options below to see which one gets you in the right information that you are looking for.

 

 

function FindNull( InputArray ){
    var NonEmptyValues = []
    for( var i = 0; i< Count( InputArray ) ; i++ ){
        if( !IsEmpty( InputArray[ i ] ) ){
            Console( InputArray[ i ] , ' is not empty' )
            Push( NonEmptyValues , InputArray[ i ] ) }
    return NonEmptyValues
    }

var A = Intersects( Geometry( tempfs ) , fsRoads )
if( Count( A ) > 0 ){ A = First( A ) }

var B = Intersects( fsRoads , Geometry( tempfs ) )
if( Count( B ) > 0 ){ B = First( B ) }

var C = Intersects( Geometry( fsRoads ) , tempfs )
if( Count( C ) > 0 ){ C = First( C ) }

var D = Intersects( tempfs , Geometry( fsRoads ) )
if( Count( D ) > 0 ){ D = First( D ) }

var Check = FindNull( [ A , B , C , D ] )
Console( Check )

return Console( Check )

 

 

I often get confused at times when it comes to the geometry vs the attributes of the features I am trying to get.

The other thing is the permissions to the layer that you are trying to create which might be keeping you from creating the layer in the first place. That is another potential possibility to consider.

0 Kudos
DNMCSCADA
Occasional Contributor

Hi RPGIS,

Thanks for the reply and the code. I will look into the suggestions mentioned in the code you provided and report back with the results. IDK, maybe the ESRI documentation is sometimes confusing, and I am kind of new in JS/Python/Arcade and get confused easily due to the new array and Dict types.

anyway thank for the help.

0 Kudos
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

It isn't always straight forward and it does confuse some people, especially if you program in several languages, and simply getting the syntax just right is confusing by itself.

DNMCSCADA
Occasional Contributor

Hi RPGIS,

BTW where did you get myfs from in the code:

 

 

if( Count( myfs ) > 0 ){ A = First( A ) }

 

is it from my Code?

0 Kudos
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

Yes and I forgot to change it to the different letters. I was preoccupied with something and I failed to see that. I will have the code that I sent you updated.

0 Kudos