Select to view content in your preferred language

Open a feature class

862
2
Jump to solution
09-08-2022 06:55 PM
JeromeHaaland
Regular Contributor

The GetBoundary() method below returns the string path to a feature class.

How is the string path to the feature class used instead of the code on lines 25 and 26?

protected override async void OnClick()
        {
            string extent = await Extent();
            MessageBox.Show(extent);

            static async Task<string> Extent()
            {
                string results = "";

                static string GetBoundary()
                {
                    OpenItemDialog item = new OpenItemDialog();
                    item.Title = "Select the Boundary";
                    item.MultiSelect = false;
                    item.ShowDialog();
                    return item.Items.First().Path;
                }

                await QueuedTask.Run(() =>
                {
                    // Want to use this path name to create a feature class
                    string boundary = GetBoundary();

                    // This is fine... except how are the 2 lines below made to run from an OpenItemDialog
                    Geodatabase gdb = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri("C:\\Temp\\Learn.gdb")));
                    using (FeatureClass fc = gdb.OpenDataset<FeatureClass>("CSS_1_BoundaryBuffer"))
                    {
                        string xMax = fc.GetExtent().XMax.ToString();
                        string xMin = fc.GetExtent().XMin.ToString();
                        string yMax = fc.GetExtent().YMax.ToString();
                        string yMin = fc.GetExtent().YMin.ToString();

                        results = $"{xMin} {yMin} {xMax} {yMax}";
                    }
                });
                return results;
            }
        }

 

0 Kudos
1 Solution

Accepted Solutions
JeromeHaaland
Regular Contributor

Excellent Reply... Worked well.

FYI for others, the Path.GetDirectoryName() needs the "using System.IO;" statement

 

View solution in original post

0 Kudos
2 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

Your code structure isn't correct. You need to separate UI and work tasks first. I would do it like that:

        static string GetBoundary()
        {
            OpenItemDialog item = new OpenItemDialog();
            item.Title = "Select the Boundary";
            item.MultiSelect = false;
            item.ShowDialog();
            return item.Items.First().Path;
        }

        static async Task<string> Extent(string fcPath)
        {
            string results = "";

            await QueuedTask.Run(() =>
            {
                // Want to use this path name to create a feature class
                string boundary = GetBoundary();

                // This is fine... except how are the 2 lines below made to run from an OpenItemDialog
                Geodatabase gdb = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(Path.GetDirectoryName(fcPath))));
                using (FeatureClass fc = gdb.OpenDataset<FeatureClass>(Path.GetFileName(fcPath)))
                {
                    string xMax = fc.GetExtent().XMax.ToString();
                    string xMin = fc.GetExtent().XMin.ToString();
                    string yMax = fc.GetExtent().YMax.ToString();
                    string yMin = fc.GetExtent().YMin.ToString();

                    results = $"{xMin} {yMin} {xMax} {yMax}";
                }
            });
            return results;
        }

        protected override async void OnClick()
        {
            string fcPath = GetBoundary();
            string extent = await Extent(fcPath);
            MessageBox.Show(extent);
        }

I have added fcPath parameter for your Extent method. fcPath parameter value separated by Path methods to Directory and File name.

I would recommend to use FeatureClass filter in your GetBoundary method.

https://github.com/Esri/arcgis-pro-sdk/wiki/ProSnippets-Browse-Dialog-Filters 

JeromeHaaland
Regular Contributor

Excellent Reply... Worked well.

FYI for others, the Path.GetDirectoryName() needs the "using System.IO;" statement

 

0 Kudos