Creating Custom Layers using ArcGIS Pro SDK for .NET?Custom Layer not drawing using ArcObjects?How to get...

Why are special aircraft used for the carriers in the United States Navy?

Why do phishing e-mails use faked e-mail addresses instead of the real one?

Was it really inappropriate to write a pull request for the company I interviewed with?

Is being socially reclusive okay for a graduate student?

What is the meaning of option 'by' in TikZ Intersections

Does the in-code argument passing conventions used on PDP-11's have a name?

What is better: yes / no radio, or simple checkbox?

What's the best tool for cutting holes into duct work?

ESPP--any reason not to go all in?

In the world of The Matrix, what is "popping"?

If nine coins are tossed, what is the probability that the number of heads is even?

What is the oldest European royal house?

Iron deposits mined from under the city

PTIJ: Mouthful of Mitzvos

How spaceships determine each other's mass in space?

How can friction do no work in case of pure rolling?

“I had a flat in the centre of town, but I didn’t like living there, so …”

Is divide-by-zero a security vulnerability?

Are angels creatures (Mark 16:15) and can they repent (Rev 2:5 and Rom 8:21)

Convert an array of objects to array of the objects' values

Under what conditions would I NOT add my Proficiency Bonus to a Spell Attack Roll (or Saving Throw DC)?

Is "cogitate" an appropriate word for this?

The need of reserving one's ability in job interviews

Create chunks from an array



Creating Custom Layers using ArcGIS Pro SDK for .NET?


Custom Layer not drawing using ArcObjects?How to get ArcObjects SDK for .NET?Rotate the map to GPS heading / direction in ArcGIS using ArcObjects SDK 10 for .NETWhich ArcGIS SDK to use ArcSDE SDK, ArcGis Runtime SDK, ArcObjects SDK?Adding new map to current project using ArcGIS Pro .NET SDK?Programmatically fetching current Add-In version using ArcGIS Pro SDKWhich operations must be performed using the Geoprocessing API in ArcGIS Pro?Are Layer extensions supported in ArcGIS Pro?ArcGIS and .Net compatibility (Extending ArcObjects)Tutorial on migrating Add-ins from ArcGIS 10.x (ArcObjects) to ArcGIS Pro for Microsoft VB.NET?Using WinForms with ArcGIS Pro SDK?













2















We have a Custom Extension developed for ArcMap, which includes the Creation of a Custom Layer. The Code for the Layer is similar to what you see in this Answer to Custom Layer not drawing using ArcObjects?. This has been developed in ArcObjects & C#.



I'm now evaluating migrating the Extension to ArcGIS Pro, but can't find any documentation for a Custom Layer in ArcGIS Pro. The Only thing I find is an ArcGIS Idea for Custom Layer in ArcGIS Pro.



Can we create Custom Layers using the ArcGIS Pro SDK for .NET ?










share|improve this question

























  • Have you posted this question on geonet, would have thought you would get a better answer from ESRI themselves?

    – Hornbydd
    Nov 22 '17 at 15:03
















2















We have a Custom Extension developed for ArcMap, which includes the Creation of a Custom Layer. The Code for the Layer is similar to what you see in this Answer to Custom Layer not drawing using ArcObjects?. This has been developed in ArcObjects & C#.



I'm now evaluating migrating the Extension to ArcGIS Pro, but can't find any documentation for a Custom Layer in ArcGIS Pro. The Only thing I find is an ArcGIS Idea for Custom Layer in ArcGIS Pro.



Can we create Custom Layers using the ArcGIS Pro SDK for .NET ?










share|improve this question

























  • Have you posted this question on geonet, would have thought you would get a better answer from ESRI themselves?

    – Hornbydd
    Nov 22 '17 at 15:03














2












2








2








We have a Custom Extension developed for ArcMap, which includes the Creation of a Custom Layer. The Code for the Layer is similar to what you see in this Answer to Custom Layer not drawing using ArcObjects?. This has been developed in ArcObjects & C#.



I'm now evaluating migrating the Extension to ArcGIS Pro, but can't find any documentation for a Custom Layer in ArcGIS Pro. The Only thing I find is an ArcGIS Idea for Custom Layer in ArcGIS Pro.



Can we create Custom Layers using the ArcGIS Pro SDK for .NET ?










share|improve this question
















We have a Custom Extension developed for ArcMap, which includes the Creation of a Custom Layer. The Code for the Layer is similar to what you see in this Answer to Custom Layer not drawing using ArcObjects?. This has been developed in ArcObjects & C#.



I'm now evaluating migrating the Extension to ArcGIS Pro, but can't find any documentation for a Custom Layer in ArcGIS Pro. The Only thing I find is an ArcGIS Idea for Custom Layer in ArcGIS Pro.



Can we create Custom Layers using the ArcGIS Pro SDK for .NET ?







arcobjects migration arcgis-pro-sdk






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 5 '18 at 22:16









PolyGeo

53.6k1781242




53.6k1781242










asked Nov 22 '17 at 4:26









Devdatta TengsheDevdatta Tengshe

30.8k21108212




30.8k21108212













  • Have you posted this question on geonet, would have thought you would get a better answer from ESRI themselves?

    – Hornbydd
    Nov 22 '17 at 15:03



















  • Have you posted this question on geonet, would have thought you would get a better answer from ESRI themselves?

    – Hornbydd
    Nov 22 '17 at 15:03

















Have you posted this question on geonet, would have thought you would get a better answer from ESRI themselves?

– Hornbydd
Nov 22 '17 at 15:03





Have you posted this question on geonet, would have thought you would get a better answer from ESRI themselves?

– Hornbydd
Nov 22 '17 at 15:03










2 Answers
2






active

oldest

votes


















1














There is no custom layer option in ArcGIS Pro :-(






share|improve this answer































    0














    This is an awful situation that must be fixed by ESRI. While they hide behind the philosophy that the ArcGIS Pro SDK is a DML (Data Manipulation Language) and shouldn't change any schema properties the raw truth is that most AddIns are there to produce output in the form of tables and featureclasses.



    The only way to create a table is to:
    1. Create the bare-bones table using the ArcToolbox tool.
    2. Add each field individually using the ArcToolbox tool.



    It takes ages to run (about 3 sec to add each field) and each field addition causes the whole map to redraw!



    Trying to map the inputs to what the Toolbox tool accepts is a nightmare.



    The code below works but I'm not proud of it.



        public static async Task<string> CreateFeatureClass(string sFGDB, string sFCName, 
    string sGeomType, SpatialReference pProjection)
    {
    // Create a Feature Class in sFGDB. This must be done by calling the Create FeatureClass GP tool
    // and then calling the Add Field GP Tool mulitple times. Geez!
    // Create featureclass requires:
    // ******** CREATE ********
    // Workspace
    // FC Name
    // Geometry Type; E.G. "Polygon"
    // Template FC (Can be null)
    // Has M (Yes/No)
    // Has Z (Yes/No)
    // Projection SpatialReference object
    // Alias Name
    //
    string sError = "";
    string sToolPath;
    string sTablePath = sFGDB + "\" + sFCName;
    string sProjectionString = "";

    try
    {
    sToolPath = "management.CreateFeatureClass";
    sProjectionString = pProjection.Wkt;
    var args = Geoprocessing.MakeValueArray(sFGDB, sFCName, sGeomType, null, "No", "No",
    sProjectionString);
    IGPResult result = await Geoprocessing.ExecuteToolAsync(sToolPath, args, null, null, null,
    GPExecuteToolFlags.None);

    if (result.IsFailed == true)
    {
    StringBuilder sErr = new StringBuilder();
    string sSep = "";
    foreach (IGPMessage pErr in result.ErrorMessages)
    {
    sErr.Append(sSep + pErr.Text);
    sSep = "rn";
    }
    sError = "Error: Create Table Failedrn" + sErr.ToString();
    return sError;
    }

    return sError;
    }
    catch (Exception ex)
    {
    System.Diagnostics.StackTrace pStack = new System.Diagnostics.StackTrace(ex, true);
    System.Diagnostics.StackFrame pFrame = pStack.GetFrame(pStack.FrameCount - 1);
    int iLineNo = pFrame.GetFileLineNumber();
    sError = "Error: CreateFeatureClass; Line: " + iLineNo + "rn" + ex.Message;
    return sError;
    }
    }

    public static async Task<string> addFields(string sGDB, string sFCorTable,
    List<clsConfig.tFieldDetails> sFields)
    {
    string sError = "";
    string sToolPath;
    string sTablePath = sGDB + "\" + sFCorTable;
    string sFieldName;
    string sFieldType;
    string sFieldLength;

    try
    {
    await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(async () =>
    {
    using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(sGDB))))
    using (FeatureClass pFC = geodatabase.OpenDataset<FeatureClass>(sFCorTable))
    {
    // Add the fields
    sToolPath = "management.AddField";
    // ******* FIELDS ********
    // Input Table or FC as FeatureClass or Table
    // Field Name
    // Field Type "TEXT", "LONG", "DOUBLE" etc
    // Field Length (Text fields only)
    // Precision (null for FGDB)
    // Field Alias
    int iFldNo = 0;
    foreach (clsConfig.tFieldDetails pFld in sFields)
    {
    sFieldName = pFld.sFldName;
    sFieldType = pFld.sFldType;
    var args = Geoprocessing.MakeValueArray(pFC, sFieldName, "DOUBLE", 6);
    if (sFieldType == "TEXT")
    {
    args = Geoprocessing.MakeValueArray(pFC, sFieldName, "TEXT", 30);
    }

    IGPResult result = await Geoprocessing.ExecuteToolAsync(sToolPath, args, null);

    if (result.IsFailed == true)
    {
    sError = "addFields: Add field failedrn" + sTablePath + "rn" + sFieldName + "r" +
    "Field No " + iFldNo.ToString() + "rn";
    StringBuilder sErr = new StringBuilder();
    string sSep = "";
    foreach (IGPMessage pEr in result.ErrorMessages)
    {
    sErr.Append(sSep + pEr.ErrorCode + " " + pEr.Text);
    sSep = "rn";
    }

    sError += sErr.ToString();
    break;
    }
    iFldNo++;
    }
    }
    });


    return sError;
    }
    catch (Exception ex)
    {
    System.Diagnostics.StackTrace pStack = new System.Diagnostics.StackTrace(ex, true);
    System.Diagnostics.StackFrame pFrame = pStack.GetFrame(pStack.FrameCount - 1);
    int iLineNo = pFrame.GetFileLineNumber();
    sError = "Error: addFields; Line: " + iLineNo + "rn" + ex.Message;
    return sError;
    }

    }





    share|improve this answer























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "79"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f262643%2fcreating-custom-layers-using-arcgis-pro-sdk-for-net%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      There is no custom layer option in ArcGIS Pro :-(






      share|improve this answer




























        1














        There is no custom layer option in ArcGIS Pro :-(






        share|improve this answer


























          1












          1








          1







          There is no custom layer option in ArcGIS Pro :-(






          share|improve this answer













          There is no custom layer option in ArcGIS Pro :-(







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 20 '18 at 6:39









          berttbertt

          1562




          1562

























              0














              This is an awful situation that must be fixed by ESRI. While they hide behind the philosophy that the ArcGIS Pro SDK is a DML (Data Manipulation Language) and shouldn't change any schema properties the raw truth is that most AddIns are there to produce output in the form of tables and featureclasses.



              The only way to create a table is to:
              1. Create the bare-bones table using the ArcToolbox tool.
              2. Add each field individually using the ArcToolbox tool.



              It takes ages to run (about 3 sec to add each field) and each field addition causes the whole map to redraw!



              Trying to map the inputs to what the Toolbox tool accepts is a nightmare.



              The code below works but I'm not proud of it.



                  public static async Task<string> CreateFeatureClass(string sFGDB, string sFCName, 
              string sGeomType, SpatialReference pProjection)
              {
              // Create a Feature Class in sFGDB. This must be done by calling the Create FeatureClass GP tool
              // and then calling the Add Field GP Tool mulitple times. Geez!
              // Create featureclass requires:
              // ******** CREATE ********
              // Workspace
              // FC Name
              // Geometry Type; E.G. "Polygon"
              // Template FC (Can be null)
              // Has M (Yes/No)
              // Has Z (Yes/No)
              // Projection SpatialReference object
              // Alias Name
              //
              string sError = "";
              string sToolPath;
              string sTablePath = sFGDB + "\" + sFCName;
              string sProjectionString = "";

              try
              {
              sToolPath = "management.CreateFeatureClass";
              sProjectionString = pProjection.Wkt;
              var args = Geoprocessing.MakeValueArray(sFGDB, sFCName, sGeomType, null, "No", "No",
              sProjectionString);
              IGPResult result = await Geoprocessing.ExecuteToolAsync(sToolPath, args, null, null, null,
              GPExecuteToolFlags.None);

              if (result.IsFailed == true)
              {
              StringBuilder sErr = new StringBuilder();
              string sSep = "";
              foreach (IGPMessage pErr in result.ErrorMessages)
              {
              sErr.Append(sSep + pErr.Text);
              sSep = "rn";
              }
              sError = "Error: Create Table Failedrn" + sErr.ToString();
              return sError;
              }

              return sError;
              }
              catch (Exception ex)
              {
              System.Diagnostics.StackTrace pStack = new System.Diagnostics.StackTrace(ex, true);
              System.Diagnostics.StackFrame pFrame = pStack.GetFrame(pStack.FrameCount - 1);
              int iLineNo = pFrame.GetFileLineNumber();
              sError = "Error: CreateFeatureClass; Line: " + iLineNo + "rn" + ex.Message;
              return sError;
              }
              }

              public static async Task<string> addFields(string sGDB, string sFCorTable,
              List<clsConfig.tFieldDetails> sFields)
              {
              string sError = "";
              string sToolPath;
              string sTablePath = sGDB + "\" + sFCorTable;
              string sFieldName;
              string sFieldType;
              string sFieldLength;

              try
              {
              await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(async () =>
              {
              using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(sGDB))))
              using (FeatureClass pFC = geodatabase.OpenDataset<FeatureClass>(sFCorTable))
              {
              // Add the fields
              sToolPath = "management.AddField";
              // ******* FIELDS ********
              // Input Table or FC as FeatureClass or Table
              // Field Name
              // Field Type "TEXT", "LONG", "DOUBLE" etc
              // Field Length (Text fields only)
              // Precision (null for FGDB)
              // Field Alias
              int iFldNo = 0;
              foreach (clsConfig.tFieldDetails pFld in sFields)
              {
              sFieldName = pFld.sFldName;
              sFieldType = pFld.sFldType;
              var args = Geoprocessing.MakeValueArray(pFC, sFieldName, "DOUBLE", 6);
              if (sFieldType == "TEXT")
              {
              args = Geoprocessing.MakeValueArray(pFC, sFieldName, "TEXT", 30);
              }

              IGPResult result = await Geoprocessing.ExecuteToolAsync(sToolPath, args, null);

              if (result.IsFailed == true)
              {
              sError = "addFields: Add field failedrn" + sTablePath + "rn" + sFieldName + "r" +
              "Field No " + iFldNo.ToString() + "rn";
              StringBuilder sErr = new StringBuilder();
              string sSep = "";
              foreach (IGPMessage pEr in result.ErrorMessages)
              {
              sErr.Append(sSep + pEr.ErrorCode + " " + pEr.Text);
              sSep = "rn";
              }

              sError += sErr.ToString();
              break;
              }
              iFldNo++;
              }
              }
              });


              return sError;
              }
              catch (Exception ex)
              {
              System.Diagnostics.StackTrace pStack = new System.Diagnostics.StackTrace(ex, true);
              System.Diagnostics.StackFrame pFrame = pStack.GetFrame(pStack.FrameCount - 1);
              int iLineNo = pFrame.GetFileLineNumber();
              sError = "Error: addFields; Line: " + iLineNo + "rn" + ex.Message;
              return sError;
              }

              }





              share|improve this answer




























                0














                This is an awful situation that must be fixed by ESRI. While they hide behind the philosophy that the ArcGIS Pro SDK is a DML (Data Manipulation Language) and shouldn't change any schema properties the raw truth is that most AddIns are there to produce output in the form of tables and featureclasses.



                The only way to create a table is to:
                1. Create the bare-bones table using the ArcToolbox tool.
                2. Add each field individually using the ArcToolbox tool.



                It takes ages to run (about 3 sec to add each field) and each field addition causes the whole map to redraw!



                Trying to map the inputs to what the Toolbox tool accepts is a nightmare.



                The code below works but I'm not proud of it.



                    public static async Task<string> CreateFeatureClass(string sFGDB, string sFCName, 
                string sGeomType, SpatialReference pProjection)
                {
                // Create a Feature Class in sFGDB. This must be done by calling the Create FeatureClass GP tool
                // and then calling the Add Field GP Tool mulitple times. Geez!
                // Create featureclass requires:
                // ******** CREATE ********
                // Workspace
                // FC Name
                // Geometry Type; E.G. "Polygon"
                // Template FC (Can be null)
                // Has M (Yes/No)
                // Has Z (Yes/No)
                // Projection SpatialReference object
                // Alias Name
                //
                string sError = "";
                string sToolPath;
                string sTablePath = sFGDB + "\" + sFCName;
                string sProjectionString = "";

                try
                {
                sToolPath = "management.CreateFeatureClass";
                sProjectionString = pProjection.Wkt;
                var args = Geoprocessing.MakeValueArray(sFGDB, sFCName, sGeomType, null, "No", "No",
                sProjectionString);
                IGPResult result = await Geoprocessing.ExecuteToolAsync(sToolPath, args, null, null, null,
                GPExecuteToolFlags.None);

                if (result.IsFailed == true)
                {
                StringBuilder sErr = new StringBuilder();
                string sSep = "";
                foreach (IGPMessage pErr in result.ErrorMessages)
                {
                sErr.Append(sSep + pErr.Text);
                sSep = "rn";
                }
                sError = "Error: Create Table Failedrn" + sErr.ToString();
                return sError;
                }

                return sError;
                }
                catch (Exception ex)
                {
                System.Diagnostics.StackTrace pStack = new System.Diagnostics.StackTrace(ex, true);
                System.Diagnostics.StackFrame pFrame = pStack.GetFrame(pStack.FrameCount - 1);
                int iLineNo = pFrame.GetFileLineNumber();
                sError = "Error: CreateFeatureClass; Line: " + iLineNo + "rn" + ex.Message;
                return sError;
                }
                }

                public static async Task<string> addFields(string sGDB, string sFCorTable,
                List<clsConfig.tFieldDetails> sFields)
                {
                string sError = "";
                string sToolPath;
                string sTablePath = sGDB + "\" + sFCorTable;
                string sFieldName;
                string sFieldType;
                string sFieldLength;

                try
                {
                await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(async () =>
                {
                using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(sGDB))))
                using (FeatureClass pFC = geodatabase.OpenDataset<FeatureClass>(sFCorTable))
                {
                // Add the fields
                sToolPath = "management.AddField";
                // ******* FIELDS ********
                // Input Table or FC as FeatureClass or Table
                // Field Name
                // Field Type "TEXT", "LONG", "DOUBLE" etc
                // Field Length (Text fields only)
                // Precision (null for FGDB)
                // Field Alias
                int iFldNo = 0;
                foreach (clsConfig.tFieldDetails pFld in sFields)
                {
                sFieldName = pFld.sFldName;
                sFieldType = pFld.sFldType;
                var args = Geoprocessing.MakeValueArray(pFC, sFieldName, "DOUBLE", 6);
                if (sFieldType == "TEXT")
                {
                args = Geoprocessing.MakeValueArray(pFC, sFieldName, "TEXT", 30);
                }

                IGPResult result = await Geoprocessing.ExecuteToolAsync(sToolPath, args, null);

                if (result.IsFailed == true)
                {
                sError = "addFields: Add field failedrn" + sTablePath + "rn" + sFieldName + "r" +
                "Field No " + iFldNo.ToString() + "rn";
                StringBuilder sErr = new StringBuilder();
                string sSep = "";
                foreach (IGPMessage pEr in result.ErrorMessages)
                {
                sErr.Append(sSep + pEr.ErrorCode + " " + pEr.Text);
                sSep = "rn";
                }

                sError += sErr.ToString();
                break;
                }
                iFldNo++;
                }
                }
                });


                return sError;
                }
                catch (Exception ex)
                {
                System.Diagnostics.StackTrace pStack = new System.Diagnostics.StackTrace(ex, true);
                System.Diagnostics.StackFrame pFrame = pStack.GetFrame(pStack.FrameCount - 1);
                int iLineNo = pFrame.GetFileLineNumber();
                sError = "Error: addFields; Line: " + iLineNo + "rn" + ex.Message;
                return sError;
                }

                }





                share|improve this answer


























                  0












                  0








                  0







                  This is an awful situation that must be fixed by ESRI. While they hide behind the philosophy that the ArcGIS Pro SDK is a DML (Data Manipulation Language) and shouldn't change any schema properties the raw truth is that most AddIns are there to produce output in the form of tables and featureclasses.



                  The only way to create a table is to:
                  1. Create the bare-bones table using the ArcToolbox tool.
                  2. Add each field individually using the ArcToolbox tool.



                  It takes ages to run (about 3 sec to add each field) and each field addition causes the whole map to redraw!



                  Trying to map the inputs to what the Toolbox tool accepts is a nightmare.



                  The code below works but I'm not proud of it.



                      public static async Task<string> CreateFeatureClass(string sFGDB, string sFCName, 
                  string sGeomType, SpatialReference pProjection)
                  {
                  // Create a Feature Class in sFGDB. This must be done by calling the Create FeatureClass GP tool
                  // and then calling the Add Field GP Tool mulitple times. Geez!
                  // Create featureclass requires:
                  // ******** CREATE ********
                  // Workspace
                  // FC Name
                  // Geometry Type; E.G. "Polygon"
                  // Template FC (Can be null)
                  // Has M (Yes/No)
                  // Has Z (Yes/No)
                  // Projection SpatialReference object
                  // Alias Name
                  //
                  string sError = "";
                  string sToolPath;
                  string sTablePath = sFGDB + "\" + sFCName;
                  string sProjectionString = "";

                  try
                  {
                  sToolPath = "management.CreateFeatureClass";
                  sProjectionString = pProjection.Wkt;
                  var args = Geoprocessing.MakeValueArray(sFGDB, sFCName, sGeomType, null, "No", "No",
                  sProjectionString);
                  IGPResult result = await Geoprocessing.ExecuteToolAsync(sToolPath, args, null, null, null,
                  GPExecuteToolFlags.None);

                  if (result.IsFailed == true)
                  {
                  StringBuilder sErr = new StringBuilder();
                  string sSep = "";
                  foreach (IGPMessage pErr in result.ErrorMessages)
                  {
                  sErr.Append(sSep + pErr.Text);
                  sSep = "rn";
                  }
                  sError = "Error: Create Table Failedrn" + sErr.ToString();
                  return sError;
                  }

                  return sError;
                  }
                  catch (Exception ex)
                  {
                  System.Diagnostics.StackTrace pStack = new System.Diagnostics.StackTrace(ex, true);
                  System.Diagnostics.StackFrame pFrame = pStack.GetFrame(pStack.FrameCount - 1);
                  int iLineNo = pFrame.GetFileLineNumber();
                  sError = "Error: CreateFeatureClass; Line: " + iLineNo + "rn" + ex.Message;
                  return sError;
                  }
                  }

                  public static async Task<string> addFields(string sGDB, string sFCorTable,
                  List<clsConfig.tFieldDetails> sFields)
                  {
                  string sError = "";
                  string sToolPath;
                  string sTablePath = sGDB + "\" + sFCorTable;
                  string sFieldName;
                  string sFieldType;
                  string sFieldLength;

                  try
                  {
                  await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(async () =>
                  {
                  using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(sGDB))))
                  using (FeatureClass pFC = geodatabase.OpenDataset<FeatureClass>(sFCorTable))
                  {
                  // Add the fields
                  sToolPath = "management.AddField";
                  // ******* FIELDS ********
                  // Input Table or FC as FeatureClass or Table
                  // Field Name
                  // Field Type "TEXT", "LONG", "DOUBLE" etc
                  // Field Length (Text fields only)
                  // Precision (null for FGDB)
                  // Field Alias
                  int iFldNo = 0;
                  foreach (clsConfig.tFieldDetails pFld in sFields)
                  {
                  sFieldName = pFld.sFldName;
                  sFieldType = pFld.sFldType;
                  var args = Geoprocessing.MakeValueArray(pFC, sFieldName, "DOUBLE", 6);
                  if (sFieldType == "TEXT")
                  {
                  args = Geoprocessing.MakeValueArray(pFC, sFieldName, "TEXT", 30);
                  }

                  IGPResult result = await Geoprocessing.ExecuteToolAsync(sToolPath, args, null);

                  if (result.IsFailed == true)
                  {
                  sError = "addFields: Add field failedrn" + sTablePath + "rn" + sFieldName + "r" +
                  "Field No " + iFldNo.ToString() + "rn";
                  StringBuilder sErr = new StringBuilder();
                  string sSep = "";
                  foreach (IGPMessage pEr in result.ErrorMessages)
                  {
                  sErr.Append(sSep + pEr.ErrorCode + " " + pEr.Text);
                  sSep = "rn";
                  }

                  sError += sErr.ToString();
                  break;
                  }
                  iFldNo++;
                  }
                  }
                  });


                  return sError;
                  }
                  catch (Exception ex)
                  {
                  System.Diagnostics.StackTrace pStack = new System.Diagnostics.StackTrace(ex, true);
                  System.Diagnostics.StackFrame pFrame = pStack.GetFrame(pStack.FrameCount - 1);
                  int iLineNo = pFrame.GetFileLineNumber();
                  sError = "Error: addFields; Line: " + iLineNo + "rn" + ex.Message;
                  return sError;
                  }

                  }





                  share|improve this answer













                  This is an awful situation that must be fixed by ESRI. While they hide behind the philosophy that the ArcGIS Pro SDK is a DML (Data Manipulation Language) and shouldn't change any schema properties the raw truth is that most AddIns are there to produce output in the form of tables and featureclasses.



                  The only way to create a table is to:
                  1. Create the bare-bones table using the ArcToolbox tool.
                  2. Add each field individually using the ArcToolbox tool.



                  It takes ages to run (about 3 sec to add each field) and each field addition causes the whole map to redraw!



                  Trying to map the inputs to what the Toolbox tool accepts is a nightmare.



                  The code below works but I'm not proud of it.



                      public static async Task<string> CreateFeatureClass(string sFGDB, string sFCName, 
                  string sGeomType, SpatialReference pProjection)
                  {
                  // Create a Feature Class in sFGDB. This must be done by calling the Create FeatureClass GP tool
                  // and then calling the Add Field GP Tool mulitple times. Geez!
                  // Create featureclass requires:
                  // ******** CREATE ********
                  // Workspace
                  // FC Name
                  // Geometry Type; E.G. "Polygon"
                  // Template FC (Can be null)
                  // Has M (Yes/No)
                  // Has Z (Yes/No)
                  // Projection SpatialReference object
                  // Alias Name
                  //
                  string sError = "";
                  string sToolPath;
                  string sTablePath = sFGDB + "\" + sFCName;
                  string sProjectionString = "";

                  try
                  {
                  sToolPath = "management.CreateFeatureClass";
                  sProjectionString = pProjection.Wkt;
                  var args = Geoprocessing.MakeValueArray(sFGDB, sFCName, sGeomType, null, "No", "No",
                  sProjectionString);
                  IGPResult result = await Geoprocessing.ExecuteToolAsync(sToolPath, args, null, null, null,
                  GPExecuteToolFlags.None);

                  if (result.IsFailed == true)
                  {
                  StringBuilder sErr = new StringBuilder();
                  string sSep = "";
                  foreach (IGPMessage pErr in result.ErrorMessages)
                  {
                  sErr.Append(sSep + pErr.Text);
                  sSep = "rn";
                  }
                  sError = "Error: Create Table Failedrn" + sErr.ToString();
                  return sError;
                  }

                  return sError;
                  }
                  catch (Exception ex)
                  {
                  System.Diagnostics.StackTrace pStack = new System.Diagnostics.StackTrace(ex, true);
                  System.Diagnostics.StackFrame pFrame = pStack.GetFrame(pStack.FrameCount - 1);
                  int iLineNo = pFrame.GetFileLineNumber();
                  sError = "Error: CreateFeatureClass; Line: " + iLineNo + "rn" + ex.Message;
                  return sError;
                  }
                  }

                  public static async Task<string> addFields(string sGDB, string sFCorTable,
                  List<clsConfig.tFieldDetails> sFields)
                  {
                  string sError = "";
                  string sToolPath;
                  string sTablePath = sGDB + "\" + sFCorTable;
                  string sFieldName;
                  string sFieldType;
                  string sFieldLength;

                  try
                  {
                  await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(async () =>
                  {
                  using (Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(sGDB))))
                  using (FeatureClass pFC = geodatabase.OpenDataset<FeatureClass>(sFCorTable))
                  {
                  // Add the fields
                  sToolPath = "management.AddField";
                  // ******* FIELDS ********
                  // Input Table or FC as FeatureClass or Table
                  // Field Name
                  // Field Type "TEXT", "LONG", "DOUBLE" etc
                  // Field Length (Text fields only)
                  // Precision (null for FGDB)
                  // Field Alias
                  int iFldNo = 0;
                  foreach (clsConfig.tFieldDetails pFld in sFields)
                  {
                  sFieldName = pFld.sFldName;
                  sFieldType = pFld.sFldType;
                  var args = Geoprocessing.MakeValueArray(pFC, sFieldName, "DOUBLE", 6);
                  if (sFieldType == "TEXT")
                  {
                  args = Geoprocessing.MakeValueArray(pFC, sFieldName, "TEXT", 30);
                  }

                  IGPResult result = await Geoprocessing.ExecuteToolAsync(sToolPath, args, null);

                  if (result.IsFailed == true)
                  {
                  sError = "addFields: Add field failedrn" + sTablePath + "rn" + sFieldName + "r" +
                  "Field No " + iFldNo.ToString() + "rn";
                  StringBuilder sErr = new StringBuilder();
                  string sSep = "";
                  foreach (IGPMessage pEr in result.ErrorMessages)
                  {
                  sErr.Append(sSep + pEr.ErrorCode + " " + pEr.Text);
                  sSep = "rn";
                  }

                  sError += sErr.ToString();
                  break;
                  }
                  iFldNo++;
                  }
                  }
                  });


                  return sError;
                  }
                  catch (Exception ex)
                  {
                  System.Diagnostics.StackTrace pStack = new System.Diagnostics.StackTrace(ex, true);
                  System.Diagnostics.StackFrame pFrame = pStack.GetFrame(pStack.FrameCount - 1);
                  int iLineNo = pFrame.GetFileLineNumber();
                  sError = "Error: addFields; Line: " + iLineNo + "rn" + ex.Message;
                  return sError;
                  }

                  }






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 11 mins ago









                  John MJohn M

                  161




                  161






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f262643%2fcreating-custom-layers-using-arcgis-pro-sdk-for-net%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Щит и меч (фильм) Содержание Названия серий | Сюжет |...

                      Венесуэла на летних Олимпийских играх 2000 Содержание Состав...

                      Meter-Bus Содержание Параметры шины | Стандартизация |...