<?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: Summarize length for pipelines segments with the same ID in ArcGIS Online Developers Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-developers-questions/summarize-length-for-pipelines-segments-with-the/m-p/1185421#M1139</link>
    <description>&lt;P&gt;Thank you Johannes!&lt;/P&gt;&lt;P&gt;Now it works!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 23 Jun 2022 11:30:34 GMT</pubDate>
    <dc:creator>Adrian_Negulescu</dc:creator>
    <dc:date>2022-06-23T11:30:34Z</dc:date>
    <item>
      <title>Summarize length for pipelines segments with the same ID</title>
      <link>https://community.esri.com/t5/arcgis-online-developers-questions/summarize-length-for-pipelines-segments-with-the/m-p/1185403#M1137</link>
      <description>&lt;P&gt;For a PipelineLeaks feature, I tried to summarize the length field from Intersected pipeline.&lt;/P&gt;&lt;P&gt;A pipeline can have many segments, but all have the same GIS_PIPE_ID. I tried to: intersect and find the GIS_PIPE_ID from intersected segment, then filter the pipeline feature by this ID and summarize the PIPE_LENGTH field&amp;nbsp;&lt;/P&gt;&lt;P&gt;This&amp;nbsp; expression have an error:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Adrian_Negulescu_0-1655975900102.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/44122i56EDD0AD5762737F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Adrian_Negulescu_0-1655975900102.png" alt="Adrian_Negulescu_0-1655975900102.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// This rule will populate the edited features field LENGTH with a sum of PIPE_LENGTH from selected pipelines with same GIS_PIPE_ID&lt;BR /&gt;// Value to copy from the intersected feature&lt;BR /&gt;var intersecting_field = "GIS_PIPE_ID"&lt;BR /&gt;//Field rule is assigned to in the Attribute Rule&lt;BR /&gt;var feature_field = "LENGTH"&lt;BR /&gt;// Create feature set to the intersecting class&lt;BR /&gt;var PipeToIntersect = FeatureSetByName($datastore, "Pipelines")&lt;BR /&gt;// Intersect the edited feature with the feature set and retrieve the first feature&lt;BR /&gt;var search_feature = buffer($feature,0.5,"meter")&lt;BR /&gt;var IntersectedPipe = First(Intersects(PipeToIntersect, search_feature))&lt;BR /&gt;//select pipelines by GIS_PIPE_ID&lt;BR /&gt;var ID = IntersectedPipe[intersecting_field]&lt;BR /&gt;var PipelinesFilteredByID = FeatureSetByName($datastore, "Pipelines",["GIS_PIPE_ID","LENGTH"],true)&lt;BR /&gt;var SelectAllSegmentsSameID = filter(PipelinesFilteredByID,ID)&lt;BR /&gt;// If this pipeline have many segments, return a sum of PIPE_LENGTH&lt;BR /&gt;var PipelineSegmentsNumber = Count(SelectAllSegmentsSameID)&lt;BR /&gt;if (PipelineSegmentsNumber &amp;gt; 1)&lt;BR /&gt;{&lt;BR /&gt;feature_field = Sum(SelectAllSegmentsSameID, "PIPE_LENGTH");&lt;BR /&gt;}&lt;BR /&gt;feature_field = round(IntersectedPipe["PIPE_LENGTH"],2)&lt;BR /&gt;return feature_field&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 09:55:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-developers-questions/summarize-length-for-pipelines-segments-with-the/m-p/1185403#M1137</guid>
      <dc:creator>Adrian_Negulescu</dc:creator>
      <dc:date>2022-06-23T09:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: Summarize length for pipelines segments with the same ID</title>
      <link>https://community.esri.com/t5/arcgis-online-developers-questions/summarize-length-for-pipelines-segments-with-the/m-p/1185418#M1138</link>
      <description>&lt;P&gt;Reason for your error: The second argument of &lt;A href="https://developers.arcgis.com/arcade/function-reference/data_functions/#filter" target="_blank" rel="noopener"&gt;Filter&lt;/A&gt; is a SQL where clause, you only supply a value, not the where clause.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Other things:&lt;/P&gt;&lt;P&gt;You don't have to load the pipelines a second time.&lt;/P&gt;&lt;P&gt;Even if PipelineSegmentsNumber is 1, you can still just call Sum on that feature set. That makes the code easier (and your code would not give the correct result for multiple pipeline segments).&lt;/P&gt;&lt;P&gt;You load LENGTH but you want to get the sum of PIPE_LENGTH.&lt;/P&gt;&lt;P&gt;After you intersect the leak feature with the pipelines, you're gonna need a null check to make sure you got an intersecting pipeline.&lt;/P&gt;&lt;P&gt;The variable feature_field isn't used in your script.&lt;/P&gt;&lt;P&gt;The variable intersecting_field is used, but you type out GIS_PIPE_ID multiple times, so you could do it one more time...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// This rule will populate the edited features field LENGTH with a sum of PIPE_LENGTH from selected pipelines with same GIS_PIPE_ID

// Create feature set to the intersecting class
var Pipelines = FeatureSetByName($datastore, "Pipelines", ["GIS_PIPE_ID", "PIPE_LENGTH"], true)
// Intersect the edited feature with the feature set and retrieve the first feature
var search_feature = Buffer($feature, 0.5, "meter")
var IntersectedPipe = First(Intersects(Pipelines, search_feature))
// Return null if no pipeline was intersected
if(IntersectedPipe == null) {
    return null
    // or return an error message:
    //return {"errorMessage": "No pipeline was intersected"}
}
//select pipelines by GIS_PIPE_ID
var ID = IntersectedPipe.GIS_PIPE_ID
var SqlWhere = "GIS_PIPE_ID = &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/354972"&gt;@ID&lt;/a&gt;"
var SelectAllSegmentsSameID = Filter(Pipelines, SqlWhere)
// return the sum of PIPE_LENGTH
return Round(Sum(SelectAllSegmentsSameID, "PIPE_LENGTH"), 2)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 11:10:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-developers-questions/summarize-length-for-pipelines-segments-with-the/m-p/1185418#M1138</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-06-23T11:10:42Z</dc:date>
    </item>
    <item>
      <title>Re: Summarize length for pipelines segments with the same ID</title>
      <link>https://community.esri.com/t5/arcgis-online-developers-questions/summarize-length-for-pipelines-segments-with-the/m-p/1185421#M1139</link>
      <description>&lt;P&gt;Thank you Johannes!&lt;/P&gt;&lt;P&gt;Now it works!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 11:30:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-developers-questions/summarize-length-for-pipelines-segments-with-the/m-p/1185421#M1139</guid>
      <dc:creator>Adrian_Negulescu</dc:creator>
      <dc:date>2022-06-23T11:30:34Z</dc:date>
    </item>
  </channel>
</rss>

