<?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: SchemaBuilder Error in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/schemabuilder-error/m-p/1305990#M10017</link>
    <description>&lt;P&gt;Thanks Wolf for your help. I tried your method, and it has the same result. For some reason, the feature layer is not showing on the map.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 06 Jul 2023 00:19:39 GMT</pubDate>
    <dc:creator>tzz_12</dc:creator>
    <dc:date>2023-07-06T00:19:39Z</dc:date>
    <item>
      <title>SchemaBuilder Error</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/schemabuilder-error/m-p/1305980#M10015</link>
      <description>&lt;P&gt;Hi Everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to use a feature layer description to create an identical new feature class with different fields. I know there are several ways to do this. I tried doing it on DLL. The feature class and fields I want is created correctly, but when I import it into the map, the feature layer does not show, because the shape area, length and polygon fields were not transferred to the new feature class. How can I fix this?&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt; QueuedTask.Run(() =&amp;gt;
            {
                var LayerDef = Layer.GetFeatureClass().GetDefinition();
                using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(gdb))))
                {
                    // Creating the attribute fields
                    FieldDescription objectIDFieldDescription = FieldDescription.CreateObjectIDField();
                    FieldDescription field1 = new FieldDescription("field1", FieldType.Double);
                    FieldDescription field2 = new FieldDescription("field2", FieldType.Double);
                    List&amp;lt;FieldDescription&amp;gt; fieldDescriptions = new List&amp;lt;FieldDescription&amp;gt;()
                    {objectIDFieldDescription, field1, field2
                    };
                    ShapeDescription shapeDescription = new ShapeDescription(IntersectSort.GetFeatureClass().GetDefinition());
                    FeatureClassDescription LayerDescription = new FeatureClassDescription("Layer_Name", fieldDescriptions, shapeDescription);
                    SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
                    schemaBuilder.Create(LayerDescription);
                    bool success = schemaBuilder.Build();
});
             
                  &lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 05 Jul 2023 22:59:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/schemabuilder-error/m-p/1305980#M10015</guid>
      <dc:creator>tzz_12</dc:creator>
      <dc:date>2023-07-05T22:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: SchemaBuilder Error</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/schemabuilder-error/m-p/1305983#M10016</link>
      <description>&lt;P&gt;i haven't tried this but i think these lines have an issue:&lt;/P&gt;&lt;P&gt;ShapeDescription shapeDescription = new ShapeDescription(IntersectSort.GetFeatureClass().GetDefinition());FeatureClassDescription LayerDescription = new FeatureClassDescription("Layer_Name", fieldDescriptions, shapeDescription);&lt;/P&gt;&lt;P&gt;maybe try this instead:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;FeatureClassDefinition originalFeatureClassDefinition = IntersectSort.GetFeatureClass().GetDefinition();
FeatureClassDescription originalFeatureClassDescription = new FeatureClassDescription(originalFeatureClassDefinition);
FeatureClassDescription LayerDescription = new FeatureClassDescription("Layer_Name", fieldDescriptions, originalFeatureClassDescription.ShapeDescription);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2023 23:41:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/schemabuilder-error/m-p/1305983#M10016</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2023-07-05T23:41:51Z</dc:date>
    </item>
    <item>
      <title>Re: SchemaBuilder Error</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/schemabuilder-error/m-p/1305990#M10017</link>
      <description>&lt;P&gt;Thanks Wolf for your help. I tried your method, and it has the same result. For some reason, the feature layer is not showing on the map.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2023 00:19:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/schemabuilder-error/m-p/1305990#M10017</guid>
      <dc:creator>tzz_12</dc:creator>
      <dc:date>2023-07-06T00:19:39Z</dc:date>
    </item>
    <item>
      <title>Re: SchemaBuilder Error</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/schemabuilder-error/m-p/1305997#M10018</link>
      <description>&lt;P&gt;It is working for me.&amp;nbsp; The following snippet will create a new FeatureClass class "NewLayer" from an existing "TestPolygons" feature layer using the same shape definition but with two new fields.&amp;nbsp; Then it adds the new FeatureClass to the map as "New: NewLayer" and finally copies all existing features from "TestPolygons" to "New: NewLayer".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Wolf_0-1688658084610.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/74920i1222C42F6CBC685C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Wolf_0-1688658084610.png" alt="Wolf_0-1688658084610.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;LI-CODE lang="csharp"&gt;protected override async void OnClick()
    {
      var originalLayerName = "TestPolygons";
      var newLayerName = "NewLayer";
      var originalLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().Where(fl =&amp;gt; fl.Name.Contains(originalLayerName)).FirstOrDefault();
      var isOk = await QueuedTask.Run&amp;lt;bool&amp;gt;(() =&amp;gt;
      {
        var LayerDef = originalLayer.GetFeatureClass().GetDefinition();
        using Geodatabase geodatabase = new(new FileGeodatabaseConnectionPath(new Uri(Project.Current.DefaultGeodatabasePath)));
        // Creating the attribute fields
        FieldDescription objectIDFieldDescription = FieldDescription.CreateObjectIDField();
        FieldDescription field1 = new("field1", FieldType.Double);
        FieldDescription field2 = new("field2", FieldType.Double);
        List&amp;lt;FieldDescription&amp;gt; fieldDescriptions = new()
        {
          objectIDFieldDescription, field1, field2
        };
        FeatureClassDefinition originalFeatureClassDefinition = originalLayer.GetFeatureClass().GetDefinition();
        FeatureClassDescription originalFeatureClassDescription = new(originalFeatureClassDefinition);
        FeatureClassDescription LayerDescription = new(newLayerName, fieldDescriptions, originalFeatureClassDescription.ShapeDescription);
        SchemaBuilder schemaBuilder = new(geodatabase);
        schemaBuilder.Create(LayerDescription);
        bool success = schemaBuilder.Build();
        return success;
      });
      if (!isOk)
      {
        MessageBox.Show($@"Failed to create {newLayerName}");
        return;
      }
      // add the new FeatureClass to the map
      var newLyr = await QueuedTask.Run(() =&amp;gt;
      {
        using Geodatabase geodatabase = new(new FileGeodatabaseConnectionPath(new Uri(Project.Current.DefaultGeodatabasePath)));
        var newFc = geodatabase.OpenDataset&amp;lt;FeatureClass&amp;gt;(newLayerName);
        return LayerFactory.Instance.CreateLayer&amp;lt;FeatureLayer&amp;gt;(new FeatureLayerCreationParams(newFc) { Name = $@"New: {newLayerName}" }, MapView.Active.Map);
      });

      // 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;();
            newAttributes.Add("field1", 1.0);
            newAttributes.Add("field2", 2.0);
            copyOperation.Create(newLyr, geom, newAttributes);
          }
        }
        // execute the operation
        if (!copyOperation.Execute())
        {
          MessageBox.Show($@"Copy operation failed {copyOperation.ErrorMessage}");
          return;
        }
      });
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2023 15:42:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/schemabuilder-error/m-p/1305997#M10018</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2023-07-06T15:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: SchemaBuilder Error</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/schemabuilder-error/m-p/1306419#M10022</link>
      <description>&lt;P&gt;It works after some minor modification to the code, but when I kept the newAttributes in "copyOperation.Create(newLyr, geom, newAttributes)," it would show this error message, "Cannot convert from System.Collection.Generic.Dictionary&amp;lt;string,object&amp;gt; to System.Action&amp;lt;long&amp;gt;".&amp;nbsp; It works fine if I delete the newAttributes from the line tho. On a related note, how do I save the edits operations within the script to avoid doing it manually after the script runs? Thanks for your help Wolf!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2023 15:22:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/schemabuilder-error/m-p/1306419#M10022</guid>
      <dc:creator>tzz_12</dc:creator>
      <dc:date>2023-07-07T15:22:02Z</dc:date>
    </item>
    <item>
      <title>Re: SchemaBuilder Error</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/schemabuilder-error/m-p/1310811#M10062</link>
      <description>&lt;P&gt;My sample code above is for release 3.0 and newer, if you are using ArcGIS Pro 2.x then the API is bit different.&amp;nbsp; &amp;nbsp;Below is the snippet that works with 2.9, note the change in the copyOperation.Create line required by the 2.x API (the parameters are different):&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;protected override async void OnClick()
{
    var originalLayerName = "TestPolygons";
    var newLayerName = "NewLayer";
    var originalLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType&amp;lt;FeatureLayer&amp;gt;().Where(fl =&amp;gt; fl.Name.Contains(originalLayerName)).FirstOrDefault();
    var isOk = await QueuedTask.Run&amp;lt;bool&amp;gt;(() =&amp;gt;
    {
        var LayerDef = originalLayer.GetFeatureClass().GetDefinition();
        bool success = false;
        using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(Project.Current.DefaultGeodatabasePath))))
        {
            // Creating the attribute fields
            ArcGIS.Core.Data.DDL.FieldDescription objectIDFieldDescription = ArcGIS.Core.Data.DDL.FieldDescription.CreateObjectIDField();
            ArcGIS.Core.Data.DDL.FieldDescription field1 = new ArcGIS.Core.Data.DDL.FieldDescription("field1", FieldType.Double);
            ArcGIS.Core.Data.DDL.FieldDescription field2 = new ArcGIS.Core.Data.DDL.FieldDescription("field2", FieldType.Double);
            List&amp;lt;ArcGIS.Core.Data.DDL.FieldDescription&amp;gt; fieldDescriptions = new List&amp;lt;ArcGIS.Core.Data.DDL.FieldDescription&amp;gt;()
            {
                objectIDFieldDescription,
                field1,
                field2
            };
            FeatureClassDefinition originalFeatureClassDefinition = originalLayer.GetFeatureClass().GetDefinition();
            FeatureClassDescription originalFeatureClassDescription = new FeatureClassDescription(originalFeatureClassDefinition);
            FeatureClassDescription LayerDescription = new FeatureClassDescription(newLayerName, fieldDescriptions, originalFeatureClassDescription.ShapeDescription);
            SchemaBuilder schemaBuilder = new SchemaBuilder(geodatabase);
            schemaBuilder.Create(LayerDescription);
            success = schemaBuilder.Build();
        }

        return success;
    });
    if (!isOk)
    {
        MessageBox.Show($@"Failed to create {newLayerName}");
        return;
    }
    // add the new FeatureClass to the map
    var newLyr = await QueuedTask.Run(() =&amp;gt;
    {
        using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(Project.Current.DefaultGeodatabasePath))))
        {
            var newFc = geodatabase.OpenDataset&amp;lt;FeatureClass&amp;gt;(newLayerName);
            return LayerFactory.Instance.CreateLayer&amp;lt;FeatureLayer&amp;gt;(new FeatureLayerCreationParams(newFc) { Name = $@"New: {newLayerName}" }, MapView.Active.Map);
        }
    });

    // 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;
                    {
                        { newLyr.GetFeatureClass().GetDefinition().GetShapeField(), geom },
                        { "field1", 1.0 },
                        { "field2", 2.0 }
                    };
                    copyOperation.Create(newLyr, newAttributes);
                }
            }
        }

        // execute the operation
        if (!copyOperation.Execute())
        {
            MessageBox.Show($@"Copy operation failed {copyOperation.ErrorMessage}");
            return;
        }
    });
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In order to save all edits you can use:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;_ = Project.Current.SaveEditsAsync();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Jul 2023 15:25:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/schemabuilder-error/m-p/1310811#M10062</guid>
      <dc:creator>Wolf</dc:creator>
      <dc:date>2023-07-23T15:25:08Z</dc:date>
    </item>
  </channel>
</rss>

