ArcGIS中IFeatureDataConverter接口的ConvertFeatureClass方法例子
2012-03-21 00:48
375 查看
shp转换为 featureclass:
public void ConvertShapefileToFeatureClass()
{
// Create a name object for the source (shapefile) workspace and open it.
IWorkspaceName sourceWorkspaceName = new WorkspaceNameClass
{
WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory",
PathName = @"C:\Data\Shapefiles"
};
IName sourceWorkspaceIName = (IName)sourceWorkspaceName;
IWorkspace sourceWorkspace = (IWorkspace)sourceWorkspaceIName.Open();
// Create a name object for the target (file GDB) workspace and open it.
IWorkspaceName targetWorkspaceName = new WorkspaceNameClass
{
WorkspaceFactoryProgID = "esriDataSourcesGDB.FileGDBWorkspaceFactory",
PathName = @"C:\Data\Public.gdb"
};
IName targetWorkspaceIName = (IName)targetWorkspaceName;
IWorkspace targetWorkspace = (IWorkspace)targetWorkspaceIName.Open();
// Create a name object for the source dataset.
IFeatureClassName sourceFeatureClassName = new FeatureClassNameClass();
IDatasetName sourceDatasetName = (IDatasetName)sourceFeatureClassName;
sourceDatasetName.Name = "Can_Mjr_Cities";
sourceDatasetName.WorkspaceName = sourceWorkspaceName;
// Create a name object for the target dataset.
IFeatureClassName targetFeatureClassName = new FeatureClassNameClass();
IDatasetName targetDatasetName = (IDatasetName)targetFeatureClassName;
targetDatasetName.Name = "Cities";
targetDatasetName.WorkspaceName = targetWorkspaceName;
// Open source feature class to get field definitions.
IName sourceName = (IName)sourceFeatureClassName;
IFeatureClass sourceFeatureClass = (IFeatureClass)sourceName.Open();
// Create the objects and references necessary for field validation.
IFieldChecker fieldChecker = new FieldCheckerClass();
IFields sourceFields = sourceFeatureClass.Fields;
IFields targetFields = null; IEnumFieldError enumFieldError = null;
// Set the required properties for the IFieldChecker interface.
fieldChecker.InputWorkspace = sourceWorkspace;
fieldChecker.ValidateWorkspace = targetWorkspace;
// Validate the fields and check for errors.
fieldChecker.Validate(sourceFields, out enumFieldError, out targetFields);
if (enumFieldError != null)
{
// Handle the errors in a way appropriate to your application.
Console.WriteLine("Errors were encountered during field validation.");
} // Find the shape field.
String shapeFieldName = sourceFeatureClass.ShapeFieldName;
int shapeFieldIndex = sourceFeatureClass.FindField(shapeFieldName);
IField shapeField = sourceFields.get_Field(shapeFieldIndex);
// Get the geometry definition from the shape field and clone it.
IGeometryDef geometryDef = shapeField.GeometryDef;
IClone geometryDefClone = (IClone)geometryDef;
IClone targetGeometryDefClone = geometryDefClone.Clone();
IGeometryDef targetGeometryDef = (IGeometryDef)targetGeometryDefClone;
// Cast the IGeometryDef to the IGeometryDefEdit interface.
IGeometryDefEdit targetGeometryDefEdit = (IGeometryDefEdit)targetGeometryDef;
// Set the IGeometryDefEdit properties.
targetGeometryDefEdit.GridCount_2 = 1;
targetGeometryDefEdit.set_GridSize(0, 0.75);
// Create a query filter to only select cities with a province (PROV) value of 'NS.'
IQueryFilter queryFilter = new QueryFilterClass();
queryFilter.WhereClause = "PROV = 'NS'";
queryFilter.SubFields = "Shape, NAME, TERM, Pop1996";
// Create the converter and run the conversion.
IFeatureDataConverter featureDataConverter = new FeatureDataConverterClass();
IEnumInvalidObject enumInvalidObject = featureDataConverter.ConvertFeatureClass
(sourceFeatureClassName, queryFilter, null, targetFeatureClassName,
targetGeometryDef, targetFields, "", 1000, 0); // Check for errors.
IInvalidObjectInfo invalidObjectInfo = null; enumInvalidObject.Reset();
while ((invalidObjectInfo = enumInvalidObject.Next()) != null)
{
// Handle the errors in a way appropriate to the application.
Console.WriteLine("Errors occurred for the following feature: {0}",
invalidObjectInfo.InvalidObjectID);
}
}
IFeatureDataConverter 不支持下面数据的转换
Geometric Networks
Topologies
Network Datasets
Relationship Classes
Network feature classes
Annotation or Dimension feature class
Feature classes with class extensions
Subtypes, domains and default values
public void ConvertShapefileToFeatureClass()
{
// Create a name object for the source (shapefile) workspace and open it.
IWorkspaceName sourceWorkspaceName = new WorkspaceNameClass
{
WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory",
PathName = @"C:\Data\Shapefiles"
};
IName sourceWorkspaceIName = (IName)sourceWorkspaceName;
IWorkspace sourceWorkspace = (IWorkspace)sourceWorkspaceIName.Open();
// Create a name object for the target (file GDB) workspace and open it.
IWorkspaceName targetWorkspaceName = new WorkspaceNameClass
{
WorkspaceFactoryProgID = "esriDataSourcesGDB.FileGDBWorkspaceFactory",
PathName = @"C:\Data\Public.gdb"
};
IName targetWorkspaceIName = (IName)targetWorkspaceName;
IWorkspace targetWorkspace = (IWorkspace)targetWorkspaceIName.Open();
// Create a name object for the source dataset.
IFeatureClassName sourceFeatureClassName = new FeatureClassNameClass();
IDatasetName sourceDatasetName = (IDatasetName)sourceFeatureClassName;
sourceDatasetName.Name = "Can_Mjr_Cities";
sourceDatasetName.WorkspaceName = sourceWorkspaceName;
// Create a name object for the target dataset.
IFeatureClassName targetFeatureClassName = new FeatureClassNameClass();
IDatasetName targetDatasetName = (IDatasetName)targetFeatureClassName;
targetDatasetName.Name = "Cities";
targetDatasetName.WorkspaceName = targetWorkspaceName;
// Open source feature class to get field definitions.
IName sourceName = (IName)sourceFeatureClassName;
IFeatureClass sourceFeatureClass = (IFeatureClass)sourceName.Open();
// Create the objects and references necessary for field validation.
IFieldChecker fieldChecker = new FieldCheckerClass();
IFields sourceFields = sourceFeatureClass.Fields;
IFields targetFields = null; IEnumFieldError enumFieldError = null;
// Set the required properties for the IFieldChecker interface.
fieldChecker.InputWorkspace = sourceWorkspace;
fieldChecker.ValidateWorkspace = targetWorkspace;
// Validate the fields and check for errors.
fieldChecker.Validate(sourceFields, out enumFieldError, out targetFields);
if (enumFieldError != null)
{
// Handle the errors in a way appropriate to your application.
Console.WriteLine("Errors were encountered during field validation.");
} // Find the shape field.
String shapeFieldName = sourceFeatureClass.ShapeFieldName;
int shapeFieldIndex = sourceFeatureClass.FindField(shapeFieldName);
IField shapeField = sourceFields.get_Field(shapeFieldIndex);
// Get the geometry definition from the shape field and clone it.
IGeometryDef geometryDef = shapeField.GeometryDef;
IClone geometryDefClone = (IClone)geometryDef;
IClone targetGeometryDefClone = geometryDefClone.Clone();
IGeometryDef targetGeometryDef = (IGeometryDef)targetGeometryDefClone;
// Cast the IGeometryDef to the IGeometryDefEdit interface.
IGeometryDefEdit targetGeometryDefEdit = (IGeometryDefEdit)targetGeometryDef;
// Set the IGeometryDefEdit properties.
targetGeometryDefEdit.GridCount_2 = 1;
targetGeometryDefEdit.set_GridSize(0, 0.75);
// Create a query filter to only select cities with a province (PROV) value of 'NS.'
IQueryFilter queryFilter = new QueryFilterClass();
queryFilter.WhereClause = "PROV = 'NS'";
queryFilter.SubFields = "Shape, NAME, TERM, Pop1996";
// Create the converter and run the conversion.
IFeatureDataConverter featureDataConverter = new FeatureDataConverterClass();
IEnumInvalidObject enumInvalidObject = featureDataConverter.ConvertFeatureClass
(sourceFeatureClassName, queryFilter, null, targetFeatureClassName,
targetGeometryDef, targetFields, "", 1000, 0); // Check for errors.
IInvalidObjectInfo invalidObjectInfo = null; enumInvalidObject.Reset();
while ((invalidObjectInfo = enumInvalidObject.Next()) != null)
{
// Handle the errors in a way appropriate to the application.
Console.WriteLine("Errors occurred for the following feature: {0}",
invalidObjectInfo.InvalidObjectID);
}
}
IFeatureDataConverter 不支持下面数据的转换
Geometric Networks
Topologies
Network Datasets
Relationship Classes
Network feature classes
Annotation or Dimension feature class
Feature classes with class extensions
Subtypes, domains and default values
相关文章推荐
- IFeatureDataConverter.ConvertFeatureClass Method
- ArcGIS官方提供的使用ConvertFeatureClass方法高效导出数据的代码示例
- IFeatureDataConverter.ConvertFeatureClass Method(ZZ)
- 关于AE中IFeatureWorkspace接口的CreateFeatureClass方法
- 无法将类型为 excel.applicationclass 的 com 强制转换为接口类型 的解决方法。
- ArcGis10.1 Feature Class Properties无法编辑
- No converter found for return value of type: class org.json.JSONArray解决方法
- arcgis featureclass的blob字段
- 无法嵌入互操作类型"ESRI.ArcGIS.Geometry.PolygonClass".请改用适用的接口
- Arcgis Engine(ae)接口详解(2):featureClass查询
- 如何创建一个FeatureClass,IFeatureWorkspace 接口漫谈
- 【说明】从ACCESS读取数据到ArcGIS个人数据库并创建Feature Class(point)
- C#WPF 格式化输出- IValueConverter接口的使用 Convert和ConvertBack
- 对featureclass中插入和删除feature的几种方法进行了比较
- ArcGIS 网络分析[8.2] 资料2 使用IDatasetContainer2接口的CreateDataset方法创建网络数据集
- 如何创建一个FeatureClass,IFeatureWorkspace 接口漫谈
- 【解答】从ACCESS读取数据到ArcGIS个人数据库并创建Feature Class(point)
- IFeature IFeatureClass IFeatureDataset等接口的介绍
- IFeatureClassManage接口更新图层全图显示时的范围