ArcGIS中IFeatureDataConverter接口的ConvertFeatureClass方法例子
来源:互联网 发布:润洁氯化钠滴眼液 知乎 编辑:程序博客网 时间:2024/05/26 07:29
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
- ArcGIS中IFeatureDataConverter接口的ConvertFeatureClass方法例子
- ArcGIS官方提供的使用ConvertFeatureClass方法高效导出数据的代码示例
- 使用IFeatureDataConverter接口快速导出Table的C#代码
- Arcgis 中 进行buffer 处理的方法。
- ArcGIS中数据之间的转换接口IFeatureDataConverter2
- arcengine Ifeaturedataconverter
- ArcGis中投影的方法以及计算面积的方法
- ArcGis中投影的方法以及计算面积的方法
- ArcGIS Server的REST接口
- ArcGIS Engine中调用GP的两种方法
- (转载)ArcGIS Engine中各种点的创建方法
- ArcGIS Engine中删除要素的几种方法总结
- ArcGIS Engine中调用GP的两种方法
- Arcgis中显示执行时间的两种方法
- 在ArcGIS空间数据库中增加点数据的方法
- ARCGIS 10.x 中找回Samples工具箱的方法
- ArcGIS中去除Z或M值的方法
- ArcGIS中创建符号方法
- zoj 1789||poj 1611 The Suspects(并查集,简单)
- 高质量C++/C编程指南 -- 第7章 内存管理 P4
- 也学Oracle之辟谷篇
- 构造、析构函数可否为virtual
- ubuntu11.10 32bit 下android2.3 源码下载
- ArcGIS中IFeatureDataConverter接口的ConvertFeatureClass方法例子
- iOS: iphone在真机测试以及apns的设置
- RLE行程长度压缩算法
- 黑马程序员--ADO.NET数据库访问技术(二)
- 最长公共子序列(LCS)问题(连续子序列)的三种解法
- 获取可执行文件的路径GetModuleFileName
- Android控件Gallery3D效果 .
- 最长公共子序列(LCS)问题(非连续子序列)的两种解法
- 虚函数、纯虚函数详解