How do I check for the existence of a raster in the project geodatabase?

459
2
Jump to solution
10-01-2019 11:50 AM
SamRideout1
New Contributor III

I need to check for the existence of a raster in the project database.  Does anyone have the C# code for ArcGIS Pro?

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi Sam,

Try code below. FilePath is your raster path in geodatabase. Instead of creating layer you can do what you want

        private Task AddToMap()
        {
            return QueuedTask.Run(() =>
            {
                try
                {
                    // first we create an 'Item' using itemfactory
                    Item currentItem = ItemFactory.Instance.Create(FilePath);

                    // Finally add the feature service to the map
                    // if we have an item that can be turned into a layer
                    // add it to the map
                    if (LayerFactory.Instance.CanCreateLayerFrom(currentItem))
                        LayerFactory.Instance.CreateLayer(currentItem, MapView.Active.Map);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error while adding vector tile to map");
                }
            });
        }

View solution in original post

0 Kudos
2 Replies
GKmieliauskas
Esri Regular Contributor

Hi Sam,

Try code below. FilePath is your raster path in geodatabase. Instead of creating layer you can do what you want

        private Task AddToMap()
        {
            return QueuedTask.Run(() =>
            {
                try
                {
                    // first we create an 'Item' using itemfactory
                    Item currentItem = ItemFactory.Instance.Create(FilePath);

                    // Finally add the feature service to the map
                    // if we have an item that can be turned into a layer
                    // add it to the map
                    if (LayerFactory.Instance.CanCreateLayerFrom(currentItem))
                        LayerFactory.Instance.CreateLayer(currentItem, MapView.Active.Map);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error while adding vector tile to map");
                }
            });
        }

0 Kudos
SamRideout1
New Contributor III

Perfect!!!!   thanks Gintautas....  much appreciated.

0 Kudos