<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: checking for array containment in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/checking-for-array-containment/m-p/1283261#M860</link>
    <description>&lt;P&gt;At 3.1, the FSByName geometry parameter is required to be set correctly, before that, I believe it was ignored or it did not matter for intersect, but it does now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is expensive performance wise to call count on a featureset and then loop over it.&amp;nbsp; Best to just loop over it and do nothing if there are no iterations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is better&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Get pipeline features from datastore
var pipelines = FeatureSetByName($datastore, "PipelineLine", ["*"], true);
    
// Get all intersecting pipeline features
var intersectingPipes = Intersects(pipelines, $feature);
var no_intersect = true
// Else, iterate over intersecting pipeline features
for (var pipe in intersectingPipes) {
    no_intersect = false
    // Get start and endpoint of intersected line feature
    var endPoint = Geometry(pipe).paths[-1][-1];
    var startPoint = Geometry(pipe).paths[0][0];

    // Check if the current feature intersects start or endpoint of line
    if (Intersects(endPoint, $feature)) {
        // If yes, allow edit process
        return true;
    } else if (Intersects(startPoint, $feature)) {
        // If yes, allow edit process
        return true; 
    }
}
// Else, hinder edit process
return no_intersect; 
}	&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Apr 2023 11:33:50 GMT</pubDate>
    <dc:creator>MikeMillerGIS</dc:creator>
    <dc:date>2023-04-27T11:33:50Z</dc:date>
    <item>
      <title>checking for array containment</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/checking-for-array-containment/m-p/1282748#M853</link>
      <description>&lt;P&gt;Hey Esri community!&lt;/P&gt;&lt;P&gt;I'm hoping someone can help me out with a little problem I'm having. I'm trying to create an attribute rule that only allows certain assets to be created if they're either at the start or end of a line, or not on a line at all.&lt;/P&gt;&lt;P&gt;To do this, I need to check an array of arrays to see if another freshly built array is contained within it. Is this even possible?&lt;/P&gt;&lt;P&gt;If anyone has any suggestions or solutions, I'd be really grateful! Thanks in advance for any help you can give.&lt;BR /&gt;&lt;BR /&gt;This is the code i currently have:&lt;/P&gt;&lt;P&gt;// Define target asset groups and types as touples&lt;BR /&gt;var tagt = [&lt;BR /&gt;[3, 957], // asset 1&lt;BR /&gt;[900, 901], // asset 2&lt;BR /&gt;[910, 911], // asset 3&lt;BR /&gt;[950, 951], // asset 4&lt;BR /&gt;[13, 710] // asset 5&lt;BR /&gt;];&lt;/P&gt;&lt;P&gt;// Create touple of feature asset group and type&lt;BR /&gt;var fagt = [$feature.assetgroup, $feature.assettype]&lt;/P&gt;&lt;P&gt;// Check if current feature triggers attribute rule&lt;BR /&gt;if (Includes(tagt, fagt)){&lt;/P&gt;&lt;P&gt;// Get pipeline features from datastore&lt;BR /&gt;var pipelines = FeatureSetByName($datastore, "PipelineLine", ["globalId"], false);&lt;/P&gt;&lt;P&gt;// Get all intersecting pipeline features&lt;BR /&gt;var intersectingPipes = Intersects(pipelines, $feature);&lt;/P&gt;&lt;P&gt;// If no line is intersected, allow edit process&lt;BR /&gt;if (isEmpty(intersectingPipes)){&lt;BR /&gt;return true;&lt;BR /&gt;} else {&lt;BR /&gt;// Else, iterate over inersecting pipeline features&lt;BR /&gt;for (var pipe in intersectingPipes) {&lt;BR /&gt;// Get start and endpoint of intersected line feature&lt;BR /&gt;var endPoint = Geometry(pipe).paths[-1][-1];&lt;BR /&gt;var startPoint = Geometry(pipe).paths[0][0];&lt;/P&gt;&lt;P&gt;// Check if the current feature intersects start or endpoint of line&lt;BR /&gt;if (Intersects(endPoint, $feature)) {&lt;BR /&gt;// If yes, allow edit process&lt;BR /&gt;return true;&lt;BR /&gt;} else if (Intersects(startPoint, $feature)) {&lt;BR /&gt;// If yes, allow edit process&lt;BR /&gt;return true;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;// Else, hinder edit process&lt;BR /&gt;return false;&lt;BR /&gt;}&lt;BR /&gt;} else {&lt;BR /&gt;return true;&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 11:55:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/checking-for-array-containment/m-p/1282748#M853</guid>
      <dc:creator>StefanAngerer</dc:creator>
      <dc:date>2023-04-26T11:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: checking for array containment</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/checking-for-array-containment/m-p/1282784#M854</link>
      <description>&lt;P&gt;To post code:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1677736512957.png" style="width: 546px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/64138iBB0E7839D9513E0F/image-size/large?v=v2&amp;amp;px=999" role="button" title="JohannesLindner_0-1677736512957.png" alt="JohannesLindner_0-1677736512957.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_1-1677736529803.png" style="width: 661px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/64139i1EE5AE3E3AEE8247/image-size/large?v=v2&amp;amp;px=999" role="button" title="JohannesLindner_1-1677736529803.png" alt="JohannesLindner_1-1677736529803.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function ArrayEquals(arr_1, arr_2) {
    if(Count(arr_1) != Count(arr_2)) { return false }
    arr_1 = Sort(arr_1)
    arr_2 = Sort(arr_2)
    for(var i in arr_1) {
        if(arr_1[i] != arr_2[i]) { return false }
    }
    return true
}
function IncludesArray(outer, inner) {
    for(var i in outer) {
        if(ArrayEquals(outer[i], inner)) { return true }
    }
    return false
}


if (IncludesArray(tagt, fagt)){
//...&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 26 Apr 2023 13:34:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/checking-for-array-containment/m-p/1282784#M854</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-04-26T13:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: checking for array containment</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/checking-for-array-containment/m-p/1282789#M855</link>
      <description>&lt;P&gt;It is hard to follow posted as text, but it looks pretty good.&amp;nbsp; The only change I see is that your FSByName is not returning geometry, which is probably why any downstream intersect fails&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;change:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;var pipelines = FeatureSetByName($datastore, "PipelineLine", ["globalId"], &lt;STRONG&gt;false&lt;/STRONG&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;to&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;var pipelines = FeatureSetByName($datastore, "PipelineLine", ["globalId"], &lt;STRONG&gt;true&lt;/STRONG&gt;);&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 13:45:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/checking-for-array-containment/m-p/1282789#M855</guid>
      <dc:creator>MikeMillerGIS</dc:creator>
      <dc:date>2023-04-26T13:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: checking for array containment</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/checking-for-array-containment/m-p/1282795#M856</link>
      <description>&lt;P&gt;Yes, the geometry has to be included in this case.&lt;/P&gt;&lt;P&gt;But Stefan's code didn't even get to that point, because the &lt;A href="https://developers.arcgis.com/arcade/function-reference/array_functions/#includes" target="_blank" rel="noopener"&gt;Includes&lt;/A&gt; function doesn't work for inner array:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1682517086698.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/69139i5A58BCED6C1DD1A3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1682517086698.png" alt="JohannesLindner_0-1682517086698.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 13:52:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/checking-for-array-containment/m-p/1282795#M856</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-04-26T13:52:13Z</dc:date>
    </item>
    <item>
      <title>Re: checking for array containment</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/checking-for-array-containment/m-p/1283189#M858</link>
      <description>&lt;P&gt;Thanks for the tip with inserting code &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/294341"&gt;@JohannesLindner&lt;/a&gt; ! And also thanks for mentioning the Geometry Bug &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/188597"&gt;@MikeMillerGIS&lt;/a&gt; . Is there any way to check the containment of inner arrays? or do i have to implement this myself?&lt;BR /&gt;&lt;BR /&gt;Greets&lt;BR /&gt;Stefan!&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 06:19:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/checking-for-array-containment/m-p/1283189#M858</guid>
      <dc:creator>StefanAngerer</dc:creator>
      <dc:date>2023-04-27T06:19:56Z</dc:date>
    </item>
    <item>
      <title>Re: checking for array containment</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/checking-for-array-containment/m-p/1283226#M859</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;in the end this code managed to do what i want.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Define target asset groups and types as touples
var tagt = [
			[3, 957],		
			[900, 901],		
			[910, 911],		
			[950, 951],		
			[13, 710]		
		];
		
// Create touple of feature asset group and type 
var fagt = [$feature.assetgroup, $feature.assettype]

// Function to check if an array is contained in an array of arrays
function arrayIsInArray(arrayToCheck, arrayContainingArrays)
{
	for(var i in arrayContainingArrays)
	{
		var currentArray = arrayContainingArrays[i]
		if(Count(currentArray) == Count(arrayToCheck))
		{
			var allValuesMatch = true; 
			for(var j in arrayToCheck)
			{
				if(currentArray[j] != arrayToCheck[j])
				{
					allValuesMatch = false; 
					break
				}
			}
			if(allValuesMatch)
            	{
               		return true;
            	}
		}
	}
	return false;
}

// Check if current feature triggers attribute rule
if (arrayIsInArray(fagt, tagt)){

	// Get pipeline features from datastore
	var pipelines = FeatureSetByName($datastore, "PipelineLine", ["*"], true);
		
	// Get all intersecting pipeline features
	var intersectingPipes = Intersects(pipelines, $feature);

	// If no line is intersected, allow edit process
	if (count(intersects(pipelines, geometry($feature))) == 0){
		return true;
	} else {
		// Else, iterate over intersecting pipeline features
		for (var pipe in intersectingPipes) {
			// Get start and endpoint of intersected line feature
			var endPoint = Geometry(pipe).paths[-1][-1];
			var startPoint = Geometry(pipe).paths[0][0];

			// Check if the current feature intersects start or endpoint of line
			if (Intersects(endPoint, $feature)) {
				// If yes, allow edit process
				return true;
			} else if (Intersects(startPoint, $feature)) {
				// If yes, allow edit process
				return true; 
			}
		}
		// Else, hinder edit process
		return false; 
	}	
} else {
	return true; 
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some rather interessting remarks:&lt;/P&gt;&lt;P&gt;-it seems like that the geometry parameter at featuresetbyname hasnt any impact if intersections are possible to detect or not. i tried it with false and with true, both times it worked just fine.&lt;/P&gt;&lt;P&gt;-the only way to actually detect an intersect was with line 50. all other methods with e.g. (if(Intersects(pipelines, $feature))) wouldnt work for whatever reason&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS: has anybody a idea where to console messages actually go to? I cant find any terminal in arcpro which makes debugging a real pain.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 08:38:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/checking-for-array-containment/m-p/1283226#M859</guid>
      <dc:creator>StefanAngerer</dc:creator>
      <dc:date>2023-04-27T08:38:20Z</dc:date>
    </item>
    <item>
      <title>Re: checking for array containment</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/checking-for-array-containment/m-p/1283261#M860</link>
      <description>&lt;P&gt;At 3.1, the FSByName geometry parameter is required to be set correctly, before that, I believe it was ignored or it did not matter for intersect, but it does now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is expensive performance wise to call count on a featureset and then loop over it.&amp;nbsp; Best to just loop over it and do nothing if there are no iterations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is better&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Get pipeline features from datastore
var pipelines = FeatureSetByName($datastore, "PipelineLine", ["*"], true);
    
// Get all intersecting pipeline features
var intersectingPipes = Intersects(pipelines, $feature);
var no_intersect = true
// Else, iterate over intersecting pipeline features
for (var pipe in intersectingPipes) {
    no_intersect = false
    // Get start and endpoint of intersected line feature
    var endPoint = Geometry(pipe).paths[-1][-1];
    var startPoint = Geometry(pipe).paths[0][0];

    // Check if the current feature intersects start or endpoint of line
    if (Intersects(endPoint, $feature)) {
        // If yes, allow edit process
        return true;
    } else if (Intersects(startPoint, $feature)) {
        // If yes, allow edit process
        return true; 
    }
}
// Else, hinder edit process
return no_intersect; 
}	&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 11:33:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/checking-for-array-containment/m-p/1283261#M860</guid>
      <dc:creator>MikeMillerGIS</dc:creator>
      <dc:date>2023-04-27T11:33:50Z</dc:date>
    </item>
  </channel>
</rss>

