<?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: Insert data in an existing layer from a table without deleting in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/insert-data-in-an-existing-layer-from-a-table/m-p/1319780#M10201</link>
    <description>&lt;P&gt;I attached a sample that creates a feature class, adds that feature class as a layer to the map, and then copies some data.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen2.png" style="width: 767px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/78390iD9D379EC40FD0DE6/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen2.png" alt="Screen2.png" /&gt;&lt;/span&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To delete the content of a whole table or feature class you can use the&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic14080.html" target="_self"&gt;DeleteRows&lt;/A&gt;&amp;nbsp; method for the Table or FeatureClass.&lt;/P&gt;</description>
    <pubDate>Thu, 17 Aug 2023 18:20:18 GMT</pubDate>
    <dc:creator>Wolf</dc:creator>
    <dc:date>2023-08-17T18:20:18Z</dc:date>
    <item>
      <title>Insert data in an existing layer from a table without deleting</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/insert-data-in-an-existing-layer-from-a-table/m-p/1319747#M10200</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;First time I am creating and inserting a data in table. Then creating and adding a layer based on that table in the active map using the following method&lt;/P&gt;&lt;PRE&gt;CreateLayer&amp;lt;T&amp;gt;( 
   &lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic26485.html" target="_blank" rel="noopener"&gt;LayerCreationParams&lt;/A&gt; &lt;I&gt;layerParams&lt;/I&gt;,
   &lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic11299.html" target="_blank" rel="noopener"&gt;ILayerContainerEdit&lt;/A&gt; &lt;I&gt;container&lt;/I&gt;
)&lt;/PRE&gt;&lt;P&gt;Now from second time onwards I have to delete the data from that table as well as layer and insert new data in the same table as well in the same existing layer. Again if I will use the above method it will create one more layer with the same name which I don’t want.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am able to delete the data from the table and I will have a table with the new data. But how to insert data in that existing layer in the active map without deleting it?&lt;/P&gt;&lt;P&gt;I saw one option but that is using editing and also at row/feature level. Also in this way I have to again create a dict to fill it with new column value. But since I have a ready whole table with new data, any other option to convert/fill that data directly in the existing layer present in active map view.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;public&lt;/SPAN&gt; &lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic19317.html" target="_blank" rel="noopener"&gt;RowToken&lt;/A&gt; Create( 
   &lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic11757.html" target="_blank" rel="noopener"&gt;Layer&lt;/A&gt; &lt;I&gt;layer&lt;/I&gt;,
   &lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic8158.html" target="_blank" rel="noopener"&gt;Geometry&lt;/A&gt; &lt;I&gt;geometry&lt;/I&gt;,
   &lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic76067.html#" target="_blank" rel="noopener"&gt;Dictionary&amp;lt;string,object&amp;gt;&lt;/A&gt; &lt;I&gt;values&lt;/I&gt;
)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/12882"&gt;@Wolf&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/145101"&gt;@CharlesMacleod&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/42133"&gt;@GKmieliauskas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 17:41:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/insert-data-in-an-existing-layer-from-a-table/m-p/1319747#M10200</guid>
      <dc:creator>GISNewbieDev</dc:creator>
      <dc:date>2023-08-17T17:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: Insert data in an existing layer from a table without deleting</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/insert-data-in-an-existing-layer-from-a-table/m-p/1319780#M10201</link>
      <description>&lt;P&gt;I attached a sample that creates a feature class, adds that feature class as a layer to the map, and then copies some data.&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen2.png" style="width: 767px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/78390iD9D379EC40FD0DE6/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen2.png" alt="Screen2.png" /&gt;&lt;/span&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To delete the content of a whole table or feature class you can use the&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/sdk/api-reference/topic14080.html" target="_self"&gt;DeleteRows&lt;/A&gt;&amp;nbsp; method for the Table or FeatureClass.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 18:20:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/insert-data-in-an-existing-layer-from-a-table/m-p/1319780#M10201</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2023-08-17T18:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: Insert data in an existing layer from a table without deleting</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/insert-data-in-an-existing-layer-from-a-table/m-p/1319815#M10202</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/12882"&gt;@Wolf&lt;/a&gt;&amp;nbsp;But I think you are creating new layer by the name of&amp;nbsp;New_{originalLayer.Name} &amp;nbsp;and then first creating the table structure from the original layer and editing the new layer with the new data but I want to delete the old data from the existing layer and then insert the new data in that same existing layer.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Aug 2023 19:25:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/insert-data-in-an-existing-layer-from-a-table/m-p/1319815#M10202</guid>
      <dc:creator>GISNewbieDev</dc:creator>
      <dc:date>2023-08-17T19:25:10Z</dc:date>
    </item>
    <item>
      <title>Re: Insert data in an existing layer from a table without deleting</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/insert-data-in-an-existing-layer-from-a-table/m-p/1319830#M10203</link>
      <description>&lt;P&gt;You can use this snippet to delete all data from a layer:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;        var theFeatureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().FirstOrDefault();
        if (theFeatureLayer == null)
        {
          MessageBox.Show("Unable to find a FeatureLayer in the Table of Content");
          return;
        }
        QueuedTask.Run(() =&amp;gt;
        {
        theFeatureLayer.GetTable().DeleteRows(new QueryFilter () );
        });&lt;/LI-CODE&gt;&lt;P&gt;and the code to copy data from one layer to another is included in the code above.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;// copy some data
await QueuedTask.Run(() =&amp;gt;
{
  // create an edit operation
  EditOperation copyOperation = new EditOperation()
  {
    Name = "Copy Data",
    ProgressMessage = "Working...",
    CancelMessage = "Operation canceled.",
    ErrorMessage = "Error copying polygons",
    SelectModifiedFeatures = false,
    SelectNewFeatures = false
  };
  using var rowCursor = originalLayer.Search();
  while (rowCursor.MoveNext())
  {
    using (var row = rowCursor.Current as Feature)
    {
      var geom = row.GetShape().Clone();
      if (geom == null)
        continue;
      var newAttributes = new Dictionary&amp;lt;string, object&amp;gt;
      {
        { "field1", 1.0 },
        { "field2", 2.0 }
      };
      copyOperation.Create(newLyr, geom, newAttributes);
    }
  }
  // execute the operation onoy if changes where made
  if (!copyOperation.IsEmpty
      &amp;amp;&amp;amp; !copyOperation.Execute())
  {
    MessageBox.Show($@"Copy operation failed {copyOperation.ErrorMessage}");
    return;
  }
});
// check for edits
if (Project.Current.HasEdits)
{
  var saveEdits = MessageBox.Show("Save edits?",
                "Save Edits?", System.Windows.MessageBoxButton.YesNoCancel);
  if (saveEdits == System.Windows.MessageBoxResult.Cancel)
    return;
  else if (saveEdits == System.Windows.MessageBoxResult.No)
    _ = Project.Current.DiscardEditsAsync();
  else
  {
    _ = Project.Current.SaveEditsAsync();
  }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 17 Aug 2023 19:56:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/insert-data-in-an-existing-layer-from-a-table/m-p/1319830#M10203</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2023-08-17T19:56:16Z</dc:date>
    </item>
  </channel>
</rss>

