Listing data


In this topic


About listing data

One of the tasks in a batch processing program is cataloging the available data so it can iterate through the data during processing. The geoprocessor has a number of methods built specifically for creating such lists.
These methods work with all different types of data and provide flexibility for restricting a search by name or data category. The following table shows a list of these methods and syntax:
Methods and syntax
Description
ListDatasets
(string Wild Card, string Dataset Type)
Returns an enumeration of datasets in the current workspace based on a query string and type.
ListFeatureClasses
(string Wild Card, string Feature Type, string Dataset)
Returns an enumeration of feature classes in the current workspace or optional dataset, based on a query string and type.
ListRasters
(string Wild Card, string Raster Type)
Returns an enumeration of rasters in the current workspace based on a query string and type.
ListTables
(string Wild Card, string Table Type)
Returns an enumeration of tables in the current workspace based on a query string and type.
ListWorkspaces
(string Wild Card, string WorkspaceType)
Returns an enumeration of workspaces in the current workspace based on a query string and type.

Workspace environment

The methods listed in the previous table require a specified workspace environment to identify the location from which the enumeration will be created. A workspace is a directory, database, or dataset containing geographic data (for example, geodatabase, geodatabase feature dataset, coverage, folder, and so on) and other supporting data. The wild card option uses an asterisk to mean any character. More than one asterisk can be used in the wild card string. For example, the wild card *road* can be used to find items containing the word road.
The result of each of these methods is an IGpEnumList. Once the enumeration has been created with the values you want, you can loop through it in your program to work with each individual value.
All methods have a wild card parameter, which is used to restrict the objects or datasets listed by name. A wild card defines a name filter and all the content in the created enumeration must pass that filter. For example, you can list all feature classes in a workspace that start with the letter c. See the following code example:
[Java]
//List all feature classes starting with the letter c.
gp.setEnvironmentValue("workspace", inputWorkspace);
IGpEnumList featureClasses = gp.listFeatureClasses("c*", "", "");
String featureClass = featureClasses.next();
System.out.println("----------------Feature Classes starting with c----------------")
    ;
while (!"" .equals(featureClass)){
    System.out.println(featureClass);
    featureClass = featureClasses.next();
}
The enumeration can also be restricted to match certain data properties, such as only polygon feature classes, integer fields, or coverage datasets. This is what the Type parameter is used for in all methods.
In the following code example, the feature classes in a workspace are filtered using a wild card and a data type; only polygon feature classes are in the resulting enumeration:
[Java]
System.out.println("----------------Polygon Feature Classes----------------");
gp.setEnvironmentValue("workspace", inputWorkspace);
featureClasses = gp.listFeatureClasses("", "polygon", "");
featureClass = featureClasses.next();
while (!"" .equals(featureClass)){
    System.out.println(featureClass);
    featureClass = featureClasses.next();
}
The following code example shows how to use an IGpEnumList created by a list function. The script is used to create raster pyramids for all the rasters that are TIF images within a folder.
[Java]
// List all .tif files in the workspace and build pyramids
gp.setEnvironmentValue("workspace", inputWorkspace);
IGpEnumList rasters = gp.listRasters("", "TIF");
String raster = rasters.next();
BuildPyramids buildPyramids = new BuildPyramids(raster);
while (!"" .equals(raster)){
    System.out.println("-----------------Building pyramids for: " + raster + 
        "---------------");
    gp.execute(buildPyramids, null);
    raster = rasters.next();
}

List methods default behavior

List methods default behavior is to list all supported types. A keyword is used to restrict the returned enumeration to a specific type. The Type keywords for each method are shown in the following table:
Methods
Type keywords
ListDatasets  All, Feature, Coverage, RasterCatalog, CAD, VPF, TIN, Topology
ListFeatureClasses
All, Point, Label, Node, Line, Arc, Route, Polygon, Region
ListFields
All, SmallInteger, Integer, Single, Double, String, Date, OID, Geometry, Blob
ListWorkspaces
All, Coverage, Access, SDE, Folder
ListTables
All, dBASE, INFO
ListRasters
All, ADRG, BIL, BIP, BSQ, BMP, CADRG, CIB, ERS, GIF, GIS, GRID, STACK, IMG, JPEG, LAN, SID, SDE, TIF, RAW, PNG, NITF
A common conversion task is the large scale transfer of data from one format to another.


See Also:

Batch processing