How to convert simple data to a geodatabase
2007-07-20 21:40
295 查看
How to convert simple data to a geodatabase |
Development licensing | Deployment licensing |
---|---|
ArcView | ArcView |
ArcEditor | ArcEditor |
ArcInfo | ArcInfo |
Engine Developer Kit | Engine Runtime |
The IFeatureDataConverter interface only loads simple feature data (points, lines, polygons).
If working in ArcSDE, an ArcEditor or greater license will be needed for ArcGIS Desktop and the Geodatabase Update extension will be required for ArcGIS Engine.
Converting simple data to a geodatabase
The IFeatureDataConverter interface is designed to work with the ArcCatalog IGxDialog minibrowser and accepts IWorkspaceNames as input. As this example is not using a ArcCatalog IGxDialog minibrowser, two IWorkspace objects are required—one for the source data and one for the target.Connecting to a geodatabase
The inWorkspace is a shapefile and the outWorkspace, a file geodatabase. Simple features can be loaded from and to shapefiles, personal geodatabases, file geodatabases, and ArcSDE. ArcInfo coverages can be converted to any of the other listed workspaces, but cannot be used as targets. For more information, see How to connect to a geodatabase.
You need to create the necessary IWorkspaceName objects as shown in the following code:
[C#]
[code] //Create inWorkspace name.
IDataset inWorkspaceDataset = (IDataset)inWorkspaceFactory;
IWorkspaceName inWorkspaceName = (IWorkspaceName)inWorkspaceDataset.FullName;
//Create outWorkspace name.
IDataset outWorkspaceDataset = (IDataset)outWorkspaceFactory;
IWorkspaceName outWorkspaceName = (IWorkspaceName)outWorkspaceDataset.FullName;
[/code]
Using inWorkspaceName, create inDatasetName and assign the name of the input feature class, which in this case, is a shapefile (ctgFeatureshp.shp). See the following code:
[C#]
[code] // Set in dataset and feature class names.
IFeatureClassName inFeatureClassName =
newFeatureClassNameClass();
IDatasetName inDatasetName = (IDatasetName)inFeatureClassName;
inDatasetName.WorkspaceName = inWorkspaceName;
inDatasetName.Name = "ctgFeatureshp.shp";
[/code]
Using outWorkspaceName, outDatasetName using IDatasetName interface and assign the name of the output feature class, which in this case, is a file geodatabase (ctgFeature_fdcon). The name of the target feature class must not already exist in the outWorkspace. See the following code:
[C#]
[code] // Set out dataset and feature class names.
IFeatureClassName outFeatureClassName =
newFeatureClassNameClass();
IDatasetName outDatasetName = (IDatasetName)outFeatureClassName;
outDatasetName.WorkspaceName = outWorkspaceName;
outDatasetName.Name = "ctgFeature_fdcon";
[/code]
Open the input feature class using the IName.Open method to get field definitions for validation. See the following code:
[C#]
[code] //Open input Featureclass to get field definitions.
IName inName = (IName)inFeatureClassName;
IFeatureClass inFeatureClass = (IFeatureClass)inName.Open();
[/code]
Set up for field name validation. See the following code:
Setting both the IFieldChecker, InputWorkspace, and IFieldChecker.ValidateWorkspace parameters is required for correct field validation.
[C#]
[code] //Validate the field names.
IFieldChecker fieldChecker =
newFieldCheckerClass();
IFields outFeatureClassFields;
IFields inFeatureClassFields = inFeatureClass.Fields;
IEnumFieldError enumFieldError;
fieldChecker.InputWorkspace = inWorkspaceFactory;
fieldChecker.ValidateWorkspace = outWorkspaceFactory;
[/code]
Validate the fields. If an error is found, enumFieldError can be traversed and an error returned. Refer to IFieldChecker.Validate and enumFieldError for details. See the following code:
[C#]
[code] // Validate the fields.
fieldChecker.Validate(inFeatureClassFields,
outenumFieldError,
outoutFeatureClassFields);
[/code]
Get the geometry definition from the shapefile of the outFeatureClass. See the following code:
[C#]
[code] // Set up the geometry definition.
IField geometryField;
geometryField = outFeatureClassFields.get_Field(outFeatureClassFields.FindField(inFeatureClass.ShapeFieldName));
// Get the geometry field's geometry definition.
IGeometryDef geometryDef = geometryField.GeometryDef;
[/code]
This section is optional
You can set the spatial index grid size if needed. This is done through the IGeometryDefEdit.GridCount and IGeometryDefEdit.GridSize_2 parameters. It is recommended that you do not set these values and use the defaults. The default values reflect the loaded data and are usually correct. See the following code:
[C#]
[code] //Give the geometry definition a spatial index grid count and grid size.
IGeometryDefEdit outFCGeoDefEdit = (IGeometryDefEdit)geometryDef;
outFCGeoDefEdit.GridCount_2 = 1;
outFCGeoDefEdit.set_GridSize(0,30);
outFCGeoDefEdit.SpatialReference_2 = geometryField.GeometryDef.SpatialReference;
[/code]
Set up the IQueryFilter to convert all of the features by leaving a blank WhereClause. A Where clause can be used to subset the input feature class. See the following code:
[C#]
[code] IQueryFilter qf = newQueryFilterClass();
qf.WhereClause = "";
[/code]
Load the feature class. Though rarely needed, rejected features can be reported using enumErrors. See the following code:
[C#]
[code] IFeatureDataConverter fctofc = newFeatureDataConverterClass();
IEnumInvalidObject enumErrors = fctofc.ConvertFeatureClass(inFeatureClassName, qf,
null, outFeatureClassName, geometryDef, outFeatureClassFields, "", 1000, 0);
[/code]
相关文章推荐
- How to convert a simple DLINQ Query to a data set object
- QT14 how to save data in sqlite database with pushbutton
- How to Convert 10g Single-Instance database to 10g RAC using Manual Conversion procedure [ID 747457.
- How to convert CSV into Database Table?
- How to Convert 10g Single-Instance database to 10g RAC using Manual Conversion procedure (文档 ID 7474
- How to get the rowid when insert the data to Oracle database
- How to Convert 10g Single-Instance database to 10g RAC using Manual Conversion procedure
- ArcMap (ArcInfo) - How to Perform a Network Trace over a Geometric Network in a Geodatabase
- Insight into DOMDocument - how to convert data from XML to array in PHP
- How to Convert Dynamic Disk to Basic Disk without Losing Data?
- Oracle 11g Active Data Guard step by step: How to create a Physical Standby Database using RMAN
- How to Convert a 32-bit Database to 64-bit Database on Linux (remove olap)
- How to convert a 32-bit database to 64-bit database on Linux
- How to select the data type in SQLserver database such as varchar, nvarchar
- How to Convert a 32-bit Database to 64-bit Database on Linux (update olap)
- Simple Excel to connect to the database and display filtered data.
- How to load data into SAP HANA database
- Designing Data Storage Architecture- How to Sync Large SQL Server Databases to SQL Azure
- How to reduce the size of logging database OR How to purge the old data from Logging Database
- How to create a geodatabase network dataset