How to open tabular and vector data


Summary
This topic lists the supported tabular and spatial vector formats, describes the Table and FeatureLayer classes, and provides code examples of how to open a Table for the supported data formats, including adding a FeatureLayer to a map.

In this topic


To use the code in this topic, add references to ESRI.ArcGISExplorer.dll and ESRI.ArcGISExplorer.Application.dll. Add the following namespace references via using (C#) or Imports (VB .NET) statements:
  • ESRI.ArcGISExplorer.Data
  • ESRI.ArcGISExplorer.Mapping
  • ESRI.ArcGISEXplorer.Application

Supported tabular and vector data formats

ArcGIS Explorer supports the display of the following tabular and vector formats:
  • Geodatabase feature classes and tables, excluding annotation and dimension feature classes, which are unsupported. Personal geodatabases are also unsupported.
  • Shapefiles and dBase files.

Table class and FeatureLayer class

A Table object allows you to access tabular data and spatial vector data from a file or geodatabase, whereas a FeatureLayer allows you to add vector data to the map. See the following descriptions of a Table and FeatureLayer class:
  • Table class—Represents non-spatial tabular data or spatial vector data stored on disk and cannot be added to the map. Use this class to access table schema (columns, indexes, and relationships) and the data stored in each row. You can also search a table using Structured Query Language (SQL) or for a spatially enabled table, using another geometry to perform a spatial query.
  • FeatureLayer class—Represents a type of MapItem that can be added to the map and relies on having an underlying Table object so the data can display. Use this class to control layer visibility, scale thresholds, and transparency.
From a FeatureLayer object, you can access the underlying Table object using the FeatureLayer.Table property. Conversely, it is easy to create a FeatureLayer object from a Table object using the Table.OpenFromTable method.

Opening a geodatabase table or feature class

A Table object can be created for a geodatabase table or feature class using the Geodatabase.OpenTable method, or using one of the static convenience methods available on the Table class: Table.OpenFileGeodatabaseTable and Table.OpenArcSDETable. Additionally, for feature classes contained within feature datasets, which represent logical groupings of related spatial data that use the same coordinate system, you can also use the GeodatabaseFolder.OpenTable method. See the following code example:
[C#]
//Option 1—Use the Geodatabase.OpenTable instance method.
Geodatabase gdb = new Geodatabase(@"C:\Data\Scotland.gdb");
//Open feature class.
Table coastTable1 = gdb.OpenTable("scotcoast");
//Open table.
Table attributesTable1 = gdb.OpenTable("Attributes");
//Option 2—Use the GeodatabaseFolder.OpenTable method to open a feature class contained in a feature dataset.
//Any feature class can also be opened directly without accessing the GeodatabaseFolder first.
GeodatabaseFolder folder = gdb.OpenGeodatabaseFolder("FeatureDataset");
Table pointsTable2 = folder.OpenTable("REL_POINTS");
//Option 3—Use one of the static methods on the Table class.
//Open feature class.
Table coastTable2 = Table.OpenFileGeodatabaseTable(@"C:\Data\Scotland.gdb", 
    "scotcoast");
//Open table.
Table attributesTable2 = Table.OpenFileGeodatabaseTable(@"C:\Data\Scotland.gdb",
    "Attributes");
Table roadsTable1 = Table.OpenArcSDETable(@"C:\Data\Enterprise.sde", 
    "SCOTADMIN.a_roads");
//or
Table roadsTable2 = Table.OpenArcSDETable(new ArcSDEConnectionProperties(
    "192.9.206.115", "5151", "scotuser", "scotuser"), "SCOTADMIN.a_roads");
[VB.NET]
'Option 1—Use the Geodatabase.OpenTable instance method.
Dim gdb As Geodatabase = New Geodatabase("C:\Data\Scotland.gdb")
'Open feature class.
Dim coastTable1 As Table = gdb.OpenTable("scotcoast")
'Open table.
Dim attributesTable1 As Table = gdb.OpenTable("Attributes")
'Option 2—Use the GeodatabaseFolder.OpenTable method to open a feature class contained in a feature dataset.
'Any feature class can also be opened directly without accessing the GeodatabaseFolder first.
Dim Folder As GeodatabaseFolder = gdb.OpenGeodatabaseFolder("FeatureDataset")
Dim pointsTable2 As Table = Folder.OpenTable("REL_POINTS")
'Option 3—Use one of the static methods on the Table class.
'Open feature class.
Dim coastTable2 As Table = Table.OpenFileGeodatabaseTable("C:\Data\Scotland.gdb", "scotcoast")
'Open table.
Dim attributesTable2 As Table = Table.OpenFileGeodatabaseTable("C:\Data\Scotland.gdb", "Attributes")
Dim roadsTable1 As Table = Table.OpenArcSDETable("C:\Data\Enterprise.sde", "SCOTADMIN.a_roads")
'or
Dim roadsTable2 As Table = Table.OpenArcSDETable(New ArcSDEConnectionProperties("192.9.206.115", "5151", "scotuser", "scotuser"), "SCOTADMIN.a_roads")
For more information on connecting to a geodatabase, see How to connect to a geodatabase.

Opening a dBase file or shapefile

A Table object can be created for a dBase file or a shapefile using the DataDirectory.OpenTable method or using the static convenience method, Table.OpenShapefile, available on the Table class. See the following code example:
[C#]
//Option 1—Use DataDirectory.OpenTable instance method.
DataDirectory dataDir = new DataDirectory(@"C:\Data");
//Open the feature class.
Table protectedAreasTable1 = dataDir.OpenTable("ProtectedAreas");
//Open the table.
Table populationTable1 = dataDir.OpenTable("DEMOG");
//Option 2—Use the static Table.OpenShapefile method.
//Open the shapefile.
Table protectedAreasTable2 = Table.OpenShapefile(@"C:\Data\ProtectedAreas.shp");
//Open the dBase file.
Table populationTable2 = Table.OpenShapefile(@"C:\Data\DEMOG.dbf");
[VB.NET]
'Option 1—Use DataDirectory.OpenTable instance method.
Dim dataDir As DataDirectory = New DataDirectory("C:\Data")
'Open the feature class.
Dim protectedAreasTable1 As Table = dataDir.OpenTable("ProtectedAreas")
'Open the table.
Dim populationTable1 As Table = dataDir.OpenTable("DEMOG")
'Option 2—Use the static Table.OpenShapefile method.
'Open the shapefile.
Dim protectedAreasTable2 As Table = Table.OpenShapefile("C:\Data\ProtectedAreas.shp")
'Open the dBase file.
Dim populationTable2 As Table = Table.OpenShapefile("C:\Data\DEMOG.dbf")

Creating a FeatureLayer

The ArcGIS Explorer application programming interface (API) provides the following alternative approaches to creating FeatureLayer objects:
  • Provides the developer with the flexibility to determine when a layer should be connected to a data source.
  • Provides easy to use convenience methods.
See the following table that shows these approaches:
Approach
Steps
Pros and Cons
Create a FeatureLayer, then manually connect to data.
  1. Set up DataSourceProperties object.
  2. Create a FeatureLayer.
  3. Connect a FeatureLayer.
  • Highly flexible. You decide when to connect and disconnect the FeatureLayer.
  • Easy to trap connection issues.
  • Slightly more complicated approach.
Single step to create a FeatureLayer and connect to data. 
  1. Use the appropriate static method on the FeatureLayer class for a particular table type.
  • Simple, can add layer in a single line of code.
  • Needs to catch connection exceptions.
  • Less flexible.
The following code example shows the first approach where a FeatureLayer is created, then manually connected to the underlying data source using the Connect method:
[C#]
//Create a DataSourceProperties object that holds the connection information to the feature class.
DataSourceProperties featureLayerConnectionProps = new DataSourceProperties(@
    "C:\Data\Forestry.gdb", "road_hazards");
//Create a feature layer.
FeatureLayer hazardsFeatureLayer = new FeatureLayer(featureLayerConnectionProps)
    ;
//Connect the layer to the feature class.
bool connected = hazardsFeatureLayer.Connect();
//Add the layer to the map.
if (connected)
{
   
        ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay.Map.ChildItems.Add(hazardsFeatureLayer);
}

else
{
    //Investigate connection issue.
    ConnectionStatus status = hazardsFeatureLayer.ConnectionStatus;
    if (status.HasError)
    {
        System.Diagnostics.Debug.Print(status.ErrorString);
    }
}
[VB.NET]
'Create a DataSourceProperties object that holds the connection information to the feature class.
Dim featureLayerConnectionProps As DataSourceProperties = New DataSourceProperties("C:\Data\Forestry.gdb", "road_hazards")
'Create a feature layer.
Dim hazardsFeatureLayer As FeatureLayer = New FeatureLayer(featureLayerConnectionProps)
'Connect the layer to the feature class.
Dim connected As Boolean = hazardsFeatureLayer.Connect()
'Add the layer to the map.
If (connected) Then
    ESRI.ArcGISExplorer.Application.Application.ActiveMapDisplay.Map.ChildItems.Add(hazardsFeatureLayer)
Else
    'Investigate connection issue.
    Dim status As ConnectionStatus = hazardsFeatureLayer.ConnectionStatus
    If status.HasError Then
        System.Diagnostics.Debug.Print(status.ErrorString)
    End If
End If
You can use the IsConnected property to check if a layer is connected to a data source and the ConnectionStatus property to investigate connection problems.
The DataSourceProperties class holds connection information relating to any of the supported table formats by only setting the properties that are appropriate for a particular data source type. For example, the connection to a shapefile can be fully defined using the Path property. 
The following code example shows the second approach where a FeatureLayer is created and connected to the underlying data source using each of the static convenience method:
[C#]
//A file geodatabase feature class.
try
{
    FeatureLayer featureLayer1 = FeatureLayer.OpenFileGeodatabaseTable(@
        "C:\Data\Forestry.gdb", "road_hazards");
}

catch (ConnectionException connEx)
{
    System.Diagnostics.Debug.Print(connEx.Message);
}

//Add try/catch blocks to test for connection problems...
//An ArcSDE feature class.
FeatureLayer featureLayer2 = FeatureLayer.OpenArcSDETable(new
                           ArcSDEConnectionProperties("server", "5151", "user", "pwd"), 
                           "SCOTADMIN.a_roads");
//A shapefile.
FeatureLayer featureLayer3 = FeatureLayer.OpenShapefile(@"C:\Data\regions.shp");
//A table instance (which is a file geodatabase feature class).
Table districtTable = Table.OpenFileGeodatabaseTable(@"C:\Data\Forestry.gdb", 
    "district");
FeatureLayer featureLayer5 = FeatureLayer.OpenFromTable(districtTable);
[VB.NET]
'A file geodatabase feature class.
Try
Dim featureLayer1 As FeatureLayer = FeatureLayer.OpenFileGeodatabaseTable("C:\Data\Forestry.gdb", "road_hazards")
Catch connEx As ConnectionException
System.Diagnostics.Debug.Print(connEx.Message)
End Try
'Add try/catch blocks to test for connection problems...
'An ArcSDE feature class.
Dim featureLayer2 As FeatureLayer = FeatureLayer.OpenArcSDETable(New ArcSDEConnectionProperties("192.9.206.115", "5151", "scotuser", "scotuser"), "SCOTADMIN.a_roads")
'A shapefile.
Dim featureLayer3 As FeatureLayer = FeatureLayer.OpenShapefile("C:\Data\regions.shp")
'A table instance (which is a file geodatabase feature class).
Dim districtTable As Table = Table.OpenFileGeodatabaseTable("C:\Data\Forestry.gdb", "district")
Dim featureLayer5 As FeatureLayer = FeatureLayer.OpenFromTable(districtTable)
For more information on accessing the values in a table, see How to access data in a table.
ArcGIS Explorer does not provide a grid-based viewer for exploring data in a tabular format; however, you can create one by using the TableBindingAdapter class that is used in the Layer Attributes sample.


See Also:

How to connect to a geodatabase
How to access data in a table