using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using SOASystem.Data.FileGDBClient;

namespace FileGDBProviderTest
{
class FeatureDatasets
{
public static bool TestFeatureDatasets()
{
String fileGDBPath = @"C:\FileGDBProvider\data\FeatureDatasets\FeatureDatasets.gdb";
try
{
// Delete the FileGDB if it is already exists
try
{
FileGDBConnection.DeleteGeodatabase(fileGDBPath);
}
catch { }
// Create a new FileGDB geodatabase
FileGDBConnection conn = FileGDBConnection.CreateGeodatabase(fileGDBPath);
conn.Close();
}
catch (FileGDBException e)
{
foreach (FileGDBError err in e.Errors)
Console.WriteLine(err.Message + err.ErrorCode);
}

// Load a feature dataset XML definition into a string. An example of a data
// element is provided in the sample as "TransitFD.xml".
//
String fdSchemaPath = @"C:\FileGDBProvider\data\FeatureDatasets\TransitFD.xml";
FileStream fStream = new FileStream(fdSchemaPath, FileMode.Open);
StreamReader sr = new StreamReader(fStream);
String fdXmlSchema = sr.ReadToEnd();
sr.Close();
fStream.Close();

String connString = "database=" fileGDBPath ";";
FileGDBConnection conn = new FileGDBConnection(connString);
try
{
conn.Open();
conn.CreateFeatureDataset(fdXmlSchema);
}
catch (FileGDBException e)
{
foreach (FileGDBError err in e.Errors)
Console.WriteLine(err.Message + err.ErrorCode);
}

// Load a table XML definition into a string. There are several differences
// between this example and adding a table at the root level of the geodatabase:
// - The table must have a shape field
// - The spatial reference must match that of the feature dataset
// - The definition's CatalogPath must include the feature dataset
//
String tblSchemaPath = @"C:\FileGDBProvider\data\FeatureDatasets\BusStopsTable.xml";
fStream = new FileStream(tblSchemaPath, FileMode.Open);
sr = new StreamReader(fStream);
String tblXmlSchema = sr.ReadToEnd();
sr.Close();
fStream.Close();

try
{
conn.CreateTable(tblXmlSchema, "\\Transit"); // Transit feature dataset
}
catch (FileGDBException e)
{
foreach (FileGDBError err in e.Errors)
Console.WriteLine(err.Message + err.ErrorCode);
}
finally
{
conn.Close();
}

return true;
}
}
}

Last edited Aug 25, 2011 at 5:18 PM by dotnetprovider, version 1

Comments

No comments yet.