How can I enumerate raster datasets in folder?

974
6
07-09-2019 08:06 AM
GKmieliauskas
Esri Regular Contributor

Hi,

I would like to enumerate raster datasets in folder where other process created them. Something like in ArcObjects:

pDatasets = pWorkspace.get_Datasets(esriDatasetType.esriDTRasterDataset);

I have found information about GetItems here:

https://github.com/Esri/arcgis-pro-sdk/wiki/ProConcepts-Content-and-Items#items-and-factories

But I do not know how to get starting item from my folder path, what factory and what item to use.

0 Kudos
6 Replies
RichRuh
Esri Regular Contributor

Hi Gintautas,

If you have a Geodatabase object, you can call Geodatabase.GetDefinitions<RasterDatasetDefinition>.  This will return a list of RasterDatasetDefinition objects.

I can tell you how to obtain a Geodatabase object if you tell me where you are starting from (e.g., FeatureLayer).

I hope this helps,

--Rich

0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi Rich,

I am starting from folder path on disk. ArcMap application creates rasters and I use ArcGIS Pro to visualize them.

I have tried to create a new FileSystemDatastore using the FileSystemConnectionPath, but compiler can’t cast FileSystemDatastore to Geodatabase.

I think that I must add my folder to Project first ant then get back from Project my folder as FolderConnectionProjectItem.

Then use GetItems from FolderConnectionProjectItem to get my rasters and etc.

I will try to do that.

0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi Rich,

I think I found solution, but I don't know if it is the best. The way of enumerating I described in previous reply. This is code of my solution:

// Add a folder to the Project

var folderToAdd = ItemFactory.Instance.Create(sResultsPath);

await QueuedTask.Run(() => Project.Current.AddItem(folderToAdd as IProjectItem));

// find the folder project item

FolderConnectionProjectItem folder = Project.Current.GetItems<FolderConnectionProjectItem>().FirstOrDefault(f => f.Path.Equals(sResultsPath, StringComparison.CurrentCultureIgnoreCase));

if (folder == null) return;

// do the search

IEnumerable<Item> folderFiles = null;

await QueuedTask.Run(() => folderFiles = folder.GetItems().Where(f => f.Type == "Raster Dataset"));

foreach (Item item in folderFiles)

{

System.Diagnostics.Debug.WriteLine(item.ToString());

}

RichRuh
Esri Regular Contributor

Go ahead and try it; it looks like it should work.

We are investigating adding the ability to iterate through datasets of a file system data store, but that would be Pro 2.5 at the absolute earliest.

--Rich

0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi Rich,

Thank you for information about the plans. My code works as I need for now.

0 Kudos
LesleyBross1
New Contributor III

Note that this also works for shapefiles when you supply "Shapefile" in the f.Type search string. I have read some posts saying that listing shapefiles in a file system data store is not supported. Developing on 2.6.3.

0 Kudos