Arcgis engnie 创建SHP文件

以创建点图层为例。

首先要得到保存文件的地址。

    SaveFileDialogsaveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "Shape文件(*.shp)|*.shp";
            saveFileDialog.Title = "新建点形shp文件";
            saveFileDialog.CheckFileExists = false;
            DialogResult dialogResult = saveFileDialog.ShowDialog();
            IWorkspaceFactory pWorkspaceFactory = newShapefileWorkspaceFactor y();
            intindex;
            stringfileName;
            stringfilePath;
            if(dialogResult == DialogResult.OK)
            {
                fileFullPath =saveFileDialog.FileName;
                index =fileFullPath.LastIndexOf("\");
                fileName =fileFullPath.Substring(index + 1);
                filePath =fileFullPath.Substring(0, index);
                if(System.IO.File.Exists(saveFileDialog.FileName))//检查文件是否存在
                {
                    if (MessageBox.Show("该文件夹下已经有同名文件,替换原文件?", "询问",MessageBoxButtons.OKCancel, MessageBoxIcon.Question) ==DialogResult.OK)
                    {
                        IFeatureWorkspace FWS = pWorkspaceFactory.OpenFromFile(filePath, 0)as IFeatureWorkspace;
                        IFeatureClass pFeatureClass = FWS.OpenFeatureClass(fileName);
                        IDatasetpDataset = pFeatureClass as IDataset;
                        pDataset.Delete();
                    }
                    //System.IO.File.Delete(saveFileDialog.FileName);
                    else
                        return;
                }
                 
            }
            else
            {
                fileFullPath = null;
                return;
           
然后,要为该SHP建立新的字段:
            IFieldspFields = new FieldsClass();
            IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
            IFieldpField = new FieldClass();
            IFieldEditpFieldEdit = pField as IFieldEdit;

            pFieldEdit.Name_2 = "Shape";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

            IGeometryDef pGeometryDef = new GeometryDef();
            IGeometryDefEdit pGeometryDefEdit = pGeometryDef asIGeometryDefEdit;
            pGeometryDefEdit.GeometryType_2 =esriGeometryType.esriGeometryPoint;//点、线、面什么的
            pGeometryDefEdit.SpatialReference_2 =axMapControl1.SpatialReference;

           

            ISpatialReferenceFactory 2 ipSpaRefFa = newSpatialReferenceEnvironm entClass();
            IGeographicCoordinateSys tem ipGeoCorSys = newGeographicCoordinateSyst emClass();

            ipGeoCorSys =ipSpaRefFa.CreateGeographicCoordina teSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
            ISpatialReference ipSpaRef = ipGeoCorSys;
            //IControlPrecision2 contrPrecision = ipSpaRef asIControlPrecision2;

           

            pGeometryDefEdit.SpatialReference_2 = ipSpaRef;
             

            pFieldEdit.GeometryDef_2 = pGeometryDef;

            pFieldsEdit.AddField(pField);

            pField =new FieldClass();//新建字段
            pFieldEdit= pField as IFieldEdit;
            pFieldEdit.Length_2 = 100;
            pFieldEdit.Name_2 = "editorName";
            pFieldEdit.AliasName_2 = "editorName";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
             
            pFieldsEdit.AddField(pField);
            //继续增加其它字段
        最后创建图层   

            IFeatureWorkspace pFeatureWorkspace =pWorkspaceFactory.OpenFromFile(filePath, 0) asIFeatureWorkspace;
           
            int i =fileName.IndexOf(".shp");
            if(i == -1)
            pFeatureWorkspace.CreateFeatureClass(fileName + ".shp", pFields,null, null, esriFeatureType.esriFTSimple, "Shape", "");
            else
            pFeatureWorkspace.CreateFeatureClass(fileName, pFields, null, null,esriFeatureType.esriFTSimple, "Shape", "");
           
            axMapControl1.AddShapeFile(filePath, fileName + ".shp");
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值