ArcEngine创建ShapeFile文件2
/*
public IFeatureWorkspace OpenShpFeaWS(string strShapeFolder, string strShapeName)
{
IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
IFeatureWorkspace pWS = (IFeatureWorkspace)pWSF.OpenFromFile(strShapeFolder, 0);
return pWS;
}
public IFeatureWorkspace OpenMdbFeaWS(string strMdbPath)
{
string mdbfileName = System.IO.Path.GetFileNameWithoutExtension(strMdbPath); //test
string fileName = System.IO.Path.GetFileName(strMdbPath);//返回文件名 test.mdb
string fileDirectory = System.IO.Path.GetDirectoryName(strMdbPath);//返回文件目录 f://temp
IWorkspaceFactory pWorkspaceFactory = new AccessWorkspaceFactoryClass();
IWorkspaceName workspaceName = pWorkspaceFactory.Create(fileDirectory, mdbfileName, null, 0);
IName name = workspaceName as IName;
IWorkspace workspace = (IWorkspace)name.Open();
//IFeatureWorkspace pFeWs = workspace as IFeatureWorkspace;
//通过已有工作空间创建
ESRI.ArcGIS.Geodatabase.IWorkspaceFactory wsf = new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactory();
ESRI.ArcGIS.Geodatabase.IFeatureWorkspace pFeWs = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)wsf.OpenFromFile(strMdbPath, 0);
return pFeWs;
}
public bool CreateMdbfile(string strMdbFileName)
{
if (!File.Exists(strMdbFileName))
{
string mdbfileName = System.IO.Path.GetFileNameWithoutExtension(strMdbFileName); //test
string fileName = System.IO.Path.GetFileName(strMdbFileName);//返回文件名 test.mdb
string fileDirectory = System.IO.Path.GetDirectoryName(strMdbFileName);//返回文件目录 f://temp
if (mdbfileName == "") return false;
IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass();
IWorkspaceName workspaceName = workspaceFactory.Create(fileDirectory, mdbfileName, null, 0);
IName name = workspaceName as IName;
IWorkspace workspace = (IWorkspace)name.Open();
IFeatureWorkspace pFeWs = workspace as IFeatureWorkspace;
return true;
}
else
{
return false;
}
}
/// <summary>
/// 创建要素集 konghuifang 20171017
/// </summary>
/// <param name="strGeoFolder"></param>
/// <param name="pFeatureClassName"></param>
/// <param name="wkt"></param>
/// <returns></returns>
public IFeatureClass CreateFeatureClass(string pFeatureClassName, string wkt, IFeatureWorkspace pWS)
{
//打开工作空间
const string strShapeFieldName = "shape";
//设置字段集
IFields pFields = new FieldsClass();
IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;
//设置字段
IField pField = new FieldClass();
IFieldEdit pFieldEdit = (IFieldEdit)pField;
//创建类型为几何类型的字段
pFieldEdit.Name_2 = strShapeFieldName;
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
//为esriFieldTypeGeometry类型的字段创建几何定义,包括类型和空间参照
IGeometryDef pGeoDef = new GeometryDefClass(); //The geometry definition for the field if IsGeometry is TRUE.
//创建地理坐标系对象
ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();
ISpatialReference spatialReference = spatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile(@"E:\temp\Suzhou_1954_3_Degree_GK_CM_120E.prj");//.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
if (wkt.ToUpper().Contains("POLYGON") || wkt.ToUpper().Contains("MULTIPOLYGON"))
{
IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef;
pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
pGeoDefEdit.SpatialReference_2 = spatialReference;
}
else if (wkt.ToUpper().Contains("POLYLINE"))
{
IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef;
pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
pGeoDefEdit.SpatialReference_2 = spatialReference;
}
else if (wkt.ToUpper().Contains("POINT"))
{
IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef;
pGeoDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
pGeoDefEdit.SpatialReference_2 = spatialReference;
}
pFieldEdit.GeometryDef_2 = pGeoDef;
pFieldsEdit.AddField(pField);
//添加其他的字段
pField = new FieldClass();
pFieldEdit = (IFieldEdit)pField;
pFieldEdit.Name_2 = "wkt";
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
pFieldsEdit.AddField(pField);
IField pField2 = new FieldClass();
IFieldEdit pFieldEdit2 = (IFieldEdit)pField2;
pFieldEdit2.Type_2 = esriFieldType.esriFieldTypeOID;
pFieldsEdit.AddField(pField2);
IField pField3 = new FieldClass();
IFieldEdit pFieldEdit3 = (IFieldEdit)pField3;
pFieldEdit3.Name_2 = "str1";
pFieldEdit3.Type_2 = esriFieldType.esriFieldTypeString;
pFieldsEdit.AddField(pField3);
IField pField4 = new FieldClass();
IFieldEdit pFieldEdit4 = (IFieldEdit)pField4;
pFieldEdit4.Name_2 = "str2";
pFieldEdit4.Type_2 = esriFieldType.esriFieldTypeString;
pFieldsEdit.AddField(pField4);
//创建shapefile
IFeatureClass pFeatureClss = pWS.CreateFeatureClass(pFeatureClassName, pFields, null, null, esriFeatureType.esriFTSimple, strShapeFieldName, "");
return pFeatureClss;
}
*/