示例#1
0
        public static IFeatureClass CreateFClassInPDB(IWorkspace accessworkspace, string feaDSname, string FCname, esriGeometryType esriGeometryType, ISpatialReference sprf)
        {
            try
            {
                IFeatureDataset featureDataset = ((IFeatureWorkspace)accessworkspace).OpenFeatureDataset(feaDSname);
                //IGeoDataset geoDataset = featureDataset as IGeoDataset;

                IFields     pFields     = new FieldsClass();
                IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
                IField      pField      = new FieldClass();
                IFieldEdit  pFieldEdit  = pField as IFieldEdit;
                pFieldEdit.Name_2 = "SHAPE";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

                IGeometryDef     pGeometryDef     = new GeometryDefClass();
                IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;
                pGeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
                pFieldEdit.GeometryDef_2        = pGeometryDef;
                pFieldsEdit.AddField(pField);


                IFeatureClass fc = featureDataset.CreateFeatureClass(FCname, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
                return(fc);
            }

            catch (Exception ee)
            {
                MessageBox.Show(ee.Message.ToString());
                return(null);
            }
        }
示例#2
0
        public static IFeatureClass CreateFeatureClass(IFeatureDataset fds,FeatureClassInfo fcInfo)
        {
            if (fds == null || fcInfo == null)
                return null;

            if ((fds.Workspace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureClass, fcInfo.Name))
            {
                ((fds.Workspace as IFeatureWorkspace).OpenFeatureClass(fcInfo.Name) as IDataset).Delete();
            }
            return fds.CreateFeatureClass(fcInfo.Name, CreateFields(fcInfo), null, null, fcInfo.FeatureType, fcInfo.ShapeFieldName, null);
        }
示例#3
0
        //创建线图层
        public IFeatureClass CreatLineFC(IFeatureDataset pFeatureDataset, IFeatureClass pPointFClass)
        {
            try
            {
                //建立shape字段
                IFields     pFields     = new FieldsClass();
                IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;
                IField      pField      = new FieldClass();
                IFieldEdit  pFieldEdit  = (IFieldEdit)pField;
                pFieldEdit.Name_2 = "SHAPE";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                //设置Geometry definition
                IGeometryDef     pGeometryDef     = new GeometryDefClass();
                IGeometryDefEdit pGeometryDefEdit = (IGeometryDefEdit)pGeometryDef;
                pGeometryDefEdit.GeometryType_2     = esriGeometryType.esriGeometryPolyline; //点、线、面
                pGeometryDefEdit.SpatialReference_2 = ClsGDBDataCommon.CreateProjectedCoordinateSystem();
                pFieldEdit.GeometryDef_2            = pGeometryDef;
                pFieldsEdit.AddField(pField);

                //新建字段
                pField                  = new FieldClass();
                pFieldEdit              = (IFieldEdit)pField;
                pFieldEdit.Name_2       = "Length";       //点类型
                pFieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
                pFieldEdit.IsNullable_2 = true;
                pFieldsEdit.AddField(pField);

                IFeatureClass pFeatureClass = pFeatureDataset.CreateFeatureClass(textBoxX3.Text + "_GmpLine", pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");

                FrmPointToLine frmP2L  = new FrmPointToLine(m_pMapCtl.Object as IMapControl3);
                IFeatureLayer  PFLayer = new FeatureLayerClass();
                PFLayer.FeatureClass = pPointFClass;
                IPointCollection pPointColl = frmP2L.ReadPoint(PFLayer);
                List <IPolyline> LineList   = CreatePolyline(pPointColl);

                for (int i = 0; i < LineList.Count; i++)
                {
                    if (LineList[i].Length > 0)
                    {
                        IFeature pFeature = pFeatureClass.CreateFeature();
                        pFeature.Shape = LineList[i];
                        string sLength = ((int)(LineList[i].Length * 100.0) / 100.0).ToString() + "m";
                        pFeature.set_Value(pFeature.Fields.FindField("Length"), sLength);
                        pFeature.Store();
                    }
                }
                return(pFeatureClass);
            }
            catch (System.Exception ex)
            {
                return(null);
            }
        }
示例#4
0
        public static IFeatureClass CreateFeatureClass(IFeatureDataset fds, FeatureClassInfo fcInfo)
        {
            if (fds == null || fcInfo == null)
            {
                return(null);
            }

            if ((fds.Workspace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureClass, fcInfo.Name))
            {
                ((fds.Workspace as IFeatureWorkspace).OpenFeatureClass(fcInfo.Name) as IDataset).Delete();
            }
            return(fds.CreateFeatureClass(fcInfo.Name, CreateFields(fcInfo), null, null, fcInfo.FeatureType, fcInfo.ShapeFieldName, null));
        }
示例#5
0
        /// <summary>
        /// 将Shapefile导入到数据库
        /// </summary>
        /// <param name="pFeaClass"></param>
        /// <param name="pWorkspace"></param>
        /// <param name="tFeatureClass"></param>
        private void importToDB(IFeatureClass pFeaClass, IWorkspace pWorkspace, IFeatureDataset tFeatureClass, string SHPName)
        {
            IFeatureClassDescription featureClassDescription = new FeatureClassDescriptionClass();
            IObjectClassDescription  objectClassDescription  = featureClassDescription as IObjectClassDescription;

            IFields         pFields         = pFeaClass.Fields;
            IFieldChecker   pFieldChecker   = new FieldCheckerClass();
            IEnumFieldError pEnumFieldError = null;
            IFields         vFields         = null;

            pFieldChecker.ValidateWorkspace = pWorkspace as IWorkspace;
            pFieldChecker.Validate(pFields, out pEnumFieldError, out vFields);
            IFeatureWorkspace featureWorkspace = pWorkspace as IFeatureWorkspace;
            IFeatureClass     sdeFeatureClass  = null;

            if (sdeFeatureClass == null)
            {
                sdeFeatureClass = tFeatureClass.CreateFeatureClass(SHPName, vFields,
                                                                   objectClassDescription.InstanceCLSID, objectClassDescription.ClassExtensionCLSID,
                                                                   pFeaClass.FeatureType, pFeaClass.ShapeFieldName, "");
                IFeatureCursor featureCursor    = pFeaClass.Search(null, true);
                IFeature       feature          = featureCursor.NextFeature();
                IFeatureCursor sdeFeatureCursor = sdeFeatureClass.Insert(true);
                IFeatureBuffer sdeFeatureBuffer;
                while (feature != null)
                {
                    sdeFeatureBuffer = sdeFeatureClass.CreateFeatureBuffer();
                    IField  shpField  = new FieldClass();
                    IFields shpFields = feature.Fields;
                    for (int i = 0; i < shpFields.FieldCount; i++)
                    {
                        shpField = shpFields.get_Field(i);
                        if (shpField.Name.Contains("Area") || shpField.Name.Contains("Leng") || shpField.Name.Contains("FID"))
                        {
                            continue;
                        }
                        int index = sdeFeatureBuffer.Fields.FindField(shpField.Name);
                        if (index != -1)
                        {
                            sdeFeatureBuffer.set_Value(index, feature.get_Value(i));
                        }
                    }
                    sdeFeatureCursor.InsertFeature(sdeFeatureBuffer);
                    sdeFeatureCursor.Flush();
                    feature = featureCursor.NextFeature();
                }
                featureCursor.Flush();
                Marshal.ReleaseComObject(feature);
                Marshal.ReleaseComObject(featureCursor);
            }
        }
        //<CSCM>
        //********************************************************************************
        //** 函 数 名: CreateFeatCls
        //** 版    权: CopyRight (C)
        //** 创 建 人:杨旭斌
        //** 功能描述:根据传入的工作区或特征数据集创建要素类,如果特征数据集不为空的话,则使用特征数据集
        //** 创建要素类,否则使用工作区创建要素类
        //** 创建日期:
        //** 修 改 人:
        //** 修改日期:
        //** 修改时间: 20070818
        //** 参数列表: sFeatClsName (String)新要素类的名称
        //         pFeatWorkSpace (IFeatureWorkspace)工作区
        //         pFields (IFields)字段
        //         pFeatDataset (IFeatureDataset)特征数据集
        //         EnumFeatType (esriFeatureType = esriFTSimple)要素类的类型
        //         sShapeFieldName (String = "shape")shape字段的名称
        //** 版    本:1.0
        //*********************************************************************************
        //</CSCM>
        //不能在ArcGIS9.1或更低版本创建的PDB里边使用ArcGIS9.2或更高版本创建要素类!
        public static IFeatureClass CreateFeatCls(ref string sFeatClsName, ref IFeatureWorkspace pFeatWorkspace, IFields pFields, ref IFeatureDataset pFeatDataset, ref esriFeatureType EnumFeatType, string sShapeFieldName)
        {
            //EnumFeatType = esriFeatureType.esriFTSimple;
            //sShapeFieldName = "shape";
            IFeatureClass functionReturnValue = default(IFeatureClass);

            try
            {
                IFeatureClass pFeatCls = default(IFeatureClass);

                //如果特征数据集不为空的话,使用特征数据集创建
                if (pFeatDataset != null)
                {
                    pFeatCls = pFeatDataset.CreateFeatureClass(sFeatClsName, pFields, null, null, EnumFeatType, sShapeFieldName, "");
                }
                else
                {
                    //If sFeatClsName.Contains(".") Then   'FOR SDE FEATURECLASS
                    //    Dim dotIndex As Integer
                    //    dotIndex = sFeatClsName.IndexOf(".")
                    //    sFeatClsName = sFeatClsName.Substring(dotIndex + 1, sFeatClsName.Length - dotIndex - 1)
                    //End If
                    pFeatCls = pFeatWorkspace.CreateFeatureClass(sFeatClsName, pFields, null, null, EnumFeatType, sShapeFieldName, "");
                }

                functionReturnValue = pFeatCls;
                return(functionReturnValue);
            }
            catch (Exception ex)
            {
                functionReturnValue = null;
                if (((System.Runtime.InteropServices.COMException)ex).ErrorCode == -2147220724)
                {
                    //g_clsErrorHandle.DisplayInformation("不能在ArcGIS9.1或更低版本创建的PDB里边使用ArcGIS9.2或更高版本创建要素类!", false);
                    MessageBoxEx.Show("不能在ArcGIS9.1或更低版本创建的PDB里边使用ArcGIS9.2或更高版本创建要素类!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (((System.Runtime.InteropServices.COMException)ex).ErrorCode == -2147219886)
                {
                    //g_clsErrorHandle.DisplayInformation("要素中字段名称不合法", false);
                    MessageBoxEx.Show("要素中字段名称不合法", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    //g_clsErrorHandle.DisplayInformation(ex.Message, false);
                    MessageBoxEx.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            return(functionReturnValue);
        }
示例#7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="featureDataset"></param>
        /// <param name="strNameOfFeatureClass"></param>
        /// <param name="isDissolved"></param>
        /// <returns></returns>
        public static IFeatureClass CreateCurveAreaFeatureClass(IFeatureDataset featureDataset, String strNameOfFeatureClass, bool isDissolved)
        {
            // This function creates a new feature class in a supplied feature dataset by building all of the
            // fields from scratch. IFeatureClassDescription (or IObjectClassDescription if the table is
            // created at the workspace level) can be used to get the required fields and are used to
            // get the InstanceClassID and ExtensionClassID.
            // Create new fields collection with the number of fields you plan to add. Must add at least two fields
            // for a feature class: Object ID and Shape field.


            // Create a feature class description object to use for specifying the CLSID and EXTCLSID.
            IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass();
            IObjectClassDescription  ocDesc = (IObjectClassDescription)fcDesc;

            return(featureDataset.CreateFeatureClass(strNameOfFeatureClass, GetCurveAreaFields(false, isDissolved), ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID, esriFeatureType.esriFTSimple, "SHAPE", ""));
        }
示例#8
0
        private IFeatureClass CreateFeatureClass(IFeatureWorkspace ipWorkspace, ISpatialReference ipSr)
        {
            //Ìí¼Óº¯ÊýCreateFeatureClass()
            IFieldsEdit ipFields = new FieldsClass();

            ipFields.FieldCount_2 = 3;
            IFieldEdit ipField = new FieldClass();

            ipField.Name_2      = "ObjectID";
            ipField.AliasName_2 = "FID";
            ipField.Type_2      = esriFieldType.esriFieldTypeOID;
            ipFields.set_Field(0, ipField);
            //Add others miscellaneous text field
            IFieldEdit ipField2 = new FieldClass();

            ipField2.Name_2      = "SmallInteger";
            ipField2.AliasName_2 = "short";
            ipField2.Type_2      = esriFieldType.esriFieldTypeSmallInteger;
            ipFields.set_Field(1, ipField2);
            //Make the shape field
            //it will need a geometry definition, with a spatial reference
            IGeometryDefEdit ipGeoDef = new GeometryDefClass();

            ipGeoDef.SpatialReference_2 = ipSr;
            ipGeoDef.GeometryType_2     =
                esriGeometryType.esriGeometryPoint;
            IFieldEdit ipField3 = new FieldClass();

            ipField3.Name_2        = "Shape";
            ipField3.AliasName_2   = "shape";
            ipField3.Type_2        = esriFieldType.esriFieldTypeGeometry;
            ipField3.GeometryDef_2 = ipGeoDef;
            ipFields.set_Field(2, ipField3);
            ipSr.SetDomain(-60000000, 60000000, -60000000, 60000000);

            IFeatureDataset ipFeatDs =
                ipWorkspace.OpenFeatureDataset("tast1");

            IFeatureClass ipFeatCls = ipFeatDs.CreateFeatureClass
                                          ("pit16er", ipFields, null, null, esriFeatureType.
                                          esriFTSimple, "Shape", "");

            return(ipFeatCls);
        }
示例#9
0
        /// <summary>
        /// 构建一个在要素集中的要素类
        /// </summary>
        /// <param name="targetWorkSpace">目标工作空间</param>
        /// <param name="DatasetName">要素集名</param>
        /// <param name="FcName">要素类名</param>
        /// <param name="FcAlias">要素类别名</param>
        /// <returns></returns>
        public bool CreateDatasetFeatureClass(IFeatureWorkspace targetWorkSpace, string DatasetName, string FcName, string FcAlias = "")
        {
            bool result = true;

            try
            {
                FieldsHelper = new FieldsHelper();
                OnAddField(FieldsHelper, FcName, FcAlias);

                IFeatureDataset targetDataset = null;
                if ((targetWorkSpace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureDataset, DatasetName) == false)
                {
                    targetDataset = targetWorkSpace.CreateFeatureDataset(DatasetName, FieldsHelper.GetSpatialRef());
                }
                else
                {
                    targetDataset = targetWorkSpace.OpenFeatureDataset(DatasetName);
                }


                if ((targetDataset as IFeatureClassContainer).get_ClassByName(FcName) != null)
                {
                    ErrorMessage = "当前要素类已经存在";
                    return(false);
                }

                UID CLSID = new UID();
                CLSID.Value = "esriGeoDatabase.Feature";

                ResultFeatureClass = targetDataset.CreateFeatureClass(FcName, FieldsHelper.Fields, CLSID, null, esriFeatureType.esriFTSimple, FieldsHelper.GetShapeFieldName(), null);

                if (string.IsNullOrEmpty(FcAlias) == false)
                {
                    IClassSchemaEdit pClassSchemaEdit = ResultFeatureClass as IClassSchemaEdit;
                    pClassSchemaEdit.AlterAliasName(FcAlias);
                }
            }
            catch (Exception ex)
            {
                result       = false;
                ErrorMessage = ex.Message;
            }
            return(result);
        }
        private IFeatureClass CreateFeatureClass(IFeatureWorkspace ws)
        {
            IFeatureClass     fc   = null;
            ISpatialReference ipSr = m_hookHelper.FocusMap.SpatialReference;

            IFeatureDataset ipFeatDs = ws.CreateFeatureDataset("newdataset", ipSr);

            IFields ipFields = new FieldsClass();

            ((IFieldsEdit)ipFields).FieldCount_2 = 3;

            IFieldEdit ipField = new FieldClass();

            ((IFieldEdit)ipField).Name_2      = "ObjectID";
            ((IFieldEdit)ipField).AliasName_2 = "FID";
            ((IFieldEdit)ipField).Type_2      = esriFieldType.esriFieldTypeOID;
            ((IFieldsEdit)ipFields).set_Field(0, ipField);
            //Add others miscellaneous text field
            IFieldEdit ipField2 = new FieldClass();

            ((IFieldEdit)ipField2).Name_2      = "SmallInteger";
            ((IFieldEdit)ipField2).AliasName_2 = "short";
            ((IFieldEdit)ipField2).Type_2      = esriFieldType.esriFieldTypeSmallInteger;
            ((IFieldsEdit)ipFields).set_Field(1, ipField2);
            //Make the shape field
            //it will need a geometry definition, with a spatial reference
            IGeometryDefEdit ipGeoDef = new GeometryDefClass();

            ipGeoDef.SpatialReference_2 = ipSr;
            ipGeoDef.GeometryType_2     = esriGeometryType.esriGeometryPolygon;
            IFieldEdit ipField3 = new FieldClass();

            ((IFieldEdit)ipField3).Name_2        = "Shape";
            ((IFieldEdit)ipField3).AliasName_2   = "shape";
            ((IFieldEdit)ipField3).Type_2        = esriFieldType.esriFieldTypeGeometry;
            ((IFieldEdit)ipField3).GeometryDef_2 = ipGeoDef;
            ((IFieldsEdit)ipFields).set_Field(2, ipField3);

            fc = ipFeatDs.CreateFeatureClass("polygon", ipFields, null, null,
                                             esriFeatureType.esriFTSimple, "Shape", "");

            return(fc);
        }
        //** 功能描述:根据传入的工作区或特征数据集创建要素类,如果特征数据集不为空的话,则使用特征数据集
        //** 创建要素类,否则使用工作区创建要素类

        //** 参数列表: sFeatClsName (String)新要素类的名称
        //         pFeatWorkSpace (IFeatureWorkspace)工作区
        //         pFields (IFields)字段
        //         pFeatDataset (IFeatureDataset)特征数据集
        //         EnumFeatType (esriFeatureType = esriFTSimple)要素类的类型
        //         sShapeFieldName (String = "shape")shape字段的名称

        public static IFeatureClass CreateFeatCls(ref string sFeatClsName, ref IFeatureWorkspace pFeatWorkspace, IFields pFields, ref IFeatureDataset pFeatDataset, ref esriFeatureType EnumFeatType, string sShapeFieldName)
        {
            IFeatureClass functionReturnValue = default(IFeatureClass);

            try
            {
                IFeatureClass pFeatCls = default(IFeatureClass);

                //如果特征数据集不为空的话,使用特征数据集创建
                if (pFeatDataset != null)
                {
                    pFeatCls = pFeatDataset.CreateFeatureClass(sFeatClsName, pFields, null, null, EnumFeatType, sShapeFieldName, "");
                }
                else
                {
                    pFeatCls = pFeatWorkspace.CreateFeatureClass(sFeatClsName, pFields, null, null, EnumFeatType, sShapeFieldName, "");
                }

                functionReturnValue = pFeatCls;
                return(functionReturnValue);
            }
            catch (Exception ex)
            {
                functionReturnValue = null;
                if (((System.Runtime.InteropServices.COMException)ex).ErrorCode == -2147220724)
                {
                    //g_clsErrorHandle.DisplayInformation("不能在ArcGIS9.1或更低版本创建的PDB里边使用ArcGIS9.2或更高版本创建要素类!", false);
                    MessageBoxEx.Show("不能在ArcGIS9.1或更低版本创建的PDB里边使用ArcGIS9.2或更高版本创建要素类!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else if (((System.Runtime.InteropServices.COMException)ex).ErrorCode == -2147219886)
                {
                    //g_clsErrorHandle.DisplayInformation("要素中字段名称不合法", false);
                    MessageBoxEx.Show("要素中字段名称不合法", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    //g_clsErrorHandle.DisplayInformation(ex.Message, false);
                    MessageBoxEx.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            return(functionReturnValue);
        }
示例#12
0
        public IFeatureClass CreateFeatureDatasetFeatureClass(IFeatureDataset featureDataset, String featureClassName, IFields fieldsCollection, esriFeatureType featureType, String shapeFieldName)
        {
            IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass();
            IObjectClassDescription  ocDesc = (IObjectClassDescription)fcDesc;

            // Use IFieldChecker to create a validated fields collection.
            IFieldChecker   fieldChecker    = new FieldCheckerClass();
            IEnumFieldError enumFieldError  = null;
            IFields         validatedFields = null;

            fieldChecker.ValidateWorkspace = featureDataset.Workspace;
            fieldChecker.Validate(fieldsCollection, out enumFieldError, out validatedFields);

            // The enumFieldError enumerator can be inspected at this point to determine
            // which fields were modified during validation.
            IFeatureClass featureClass = featureDataset.CreateFeatureClass(featureClassName, validatedFields, ocDesc.InstanceCLSID,
                                                                           ocDesc.ClassExtensionCLSID, esriFeatureType.esriFTSimple, fcDesc.ShapeFieldName, "");

            return(featureClass);
        }
示例#13
0
        private bool CreateFeatCls(IFeatureDataset featureDataset, IFeatureClass sourceFeatCls, string strTagetName, out Exception err)
        {
            try
            {
                err = null;
                IFeatureWorkspace featureWorkspace = featureDataset.Workspace as IFeatureWorkspace;

                //取源图层字段,并添加字段FromDate(生效日期),ToDate(失效日期),SourceOID(现势库对应数据OID),State(更新变化状态)
                IFields     pFields     = (sourceFeatCls.Fields as IClone).Clone() as IFields;
                IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;

                IField     newfield  = new FieldClass();           //字段对象
                IFieldEdit fieldEdit = newfield as IFieldEdit;     //字段编辑对象
                fieldEdit.Name_2      = "FromDate";
                fieldEdit.AliasName_2 = "生效日期";
                //字段类型要装化为枚举类型
                fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                pFieldsEdit.AddField(newfield);

                newfield              = new FieldClass();       //字段对象
                fieldEdit             = newfield as IFieldEdit; //字段编辑对象
                fieldEdit.Name_2      = "ToDate";
                fieldEdit.AliasName_2 = "失效日期";
                //字段类型要装化为枚举类型
                fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                pFieldsEdit.AddField(newfield);

                newfield              = new FieldClass();       //字段对象
                fieldEdit             = newfield as IFieldEdit; //字段编辑对象
                fieldEdit.Name_2      = "SourceOID";
                fieldEdit.AliasName_2 = "现势库对应数据OID";
                //字段类型要装化为枚举类型
                fieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
                pFieldsEdit.AddField(newfield);

                newfield              = new FieldClass();       //字段对象
                fieldEdit             = newfield as IFieldEdit; //字段编辑对象
                fieldEdit.Name_2      = "State";
                fieldEdit.AliasName_2 = "更新变化状态";
                //字段类型要装化为枚举类型
                fieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
                pFieldsEdit.AddField(newfield);

                newfield                 = new FieldClass();       //字段对象
                fieldEdit                = newfield as IFieldEdit; //字段编辑对象
                fieldEdit.Name_2         = "VERSION";
                fieldEdit.AliasName_2    = "更新版本号";
                fieldEdit.DefaultValue_2 = 0;
                fieldEdit.IsNullable_2   = false;
                //字段类型要装化为枚举类型
                fieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
                pFieldsEdit.AddField(newfield);


                if (sourceFeatCls.FeatureType == esriFeatureType.esriFTSimple)
                {
                    featureDataset.CreateFeatureClass(strTagetName, pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
                }
                else if (sourceFeatCls.FeatureType == esriFeatureType.esriFTAnnotation)
                {
                    IObjectClassDescription pObjectClassDesc = new AnnotationFeatureClassDescriptionClass();
                    UID pCLSID    = pObjectClassDesc.InstanceCLSID;
                    UID pExtCLSID = pObjectClassDesc.ClassExtensionCLSID;
                    IFeatureWorkspaceAnno pFeatWorkspaceAnno = (IFeatureWorkspaceAnno)featureWorkspace;
                    IAnnoClass            pAnnoCls           = (IAnnoClass)sourceFeatCls.Extension;
                    IGraphicsLayerScale   pRefScale          = new GraphicsLayerScaleClass();

                    // 设置参考比例尺的相关参数

                    pRefScale.ReferenceScale = pAnnoCls.ReferenceScale;
                    pRefScale.Units          = pAnnoCls.ReferenceScaleUnits;

                    pFeatWorkspaceAnno.CreateAnnotationClass(strTagetName, pFieldsEdit,
                                                             pCLSID, pExtCLSID, sourceFeatCls.ShapeFieldName,
                                                             "", featureDataset, null, pAnnoCls.AnnoProperties,
                                                             pRefScale, pAnnoCls.SymbolCollection, false);
                }
                return(true);
            }
            catch (Exception e)
            {
                //*******************************************************************
                //guozheng added
                if (ModData.SysLog != null)
                {
                    ModData.SysLog.Write(e, null, DateTime.Now);
                }
                else
                {
                    ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                    ModData.SysLog.Write(e, null, DateTime.Now);
                }
                //********************************************************************
                err = e;
                return(false);
            }
        }
示例#14
0
        public static IFeatureClass CreateFeatureClass(object object_0, string string_0,
                                                       ISpatialReference ispatialReference_0, esriFeatureType esriFeatureType_0,
                                                       esriGeometryType esriGeometryType_0, IFields ifields_0, UID uid_0, UID uid_1, string string_1)
        {
            if (object_0 == null)
            {
                throw new Exception("[objectWorkspace] 不能为空");
            }
            if ((object_0 is IWorkspace ? false : !(object_0 is IFeatureDataset)))
            {
                throw new Exception("[objectWorkspace] 必须是IWorkspace或IFeatureDataset");
            }
            if (string_0 == "")
            {
                throw new Exception("[name] cannot be empty");
            }
            if ((!(object_0 is IWorkspace) ? false : ispatialReference_0 == null))
            {
                throw new Exception("[spatialReference] cannot be null for StandAlong FeatureClasses");
            }
            if (uid_0 == null)
            {
                uid_0 = new UID();
                switch (esriFeatureType_0)
                {
                case esriFeatureType.esriFTSimple:
                {
                    uid_0.Value = "{52353152-891A-11D0-BEC6-00805F7C4268}";
                    break;
                }

                case esriFeatureType.esriFTSimpleJunction:
                {
                    esriGeometryType_0 = esriGeometryType.esriGeometryPoint;
                    uid_0.Value        = "{CEE8D6B8-55FE-11D1-AE55-0000F80372B4}";
                    break;
                }

                case esriFeatureType.esriFTSimpleEdge:
                {
                    esriGeometryType_0 = esriGeometryType.esriGeometryPolyline;
                    uid_0.Value        = "{E7031C90-55FE-11D1-AE55-0000F80372B4}";
                    break;
                }

                case esriFeatureType.esriFTComplexJunction:
                {
                    uid_0.Value = "{DF9D71F4-DA32-11D1-AEBA-0000F80372B4}";
                    break;
                }

                case esriFeatureType.esriFTComplexEdge:
                {
                    esriGeometryType_0 = esriGeometryType.esriGeometryPolyline;
                    uid_0.Value        = "{A30E8A2A-C50B-11D1-AEA9-0000F80372B4}";
                    break;
                }

                case esriFeatureType.esriFTAnnotation:
                {
                    esriGeometryType_0 = esriGeometryType.esriGeometryPolygon;
                    uid_0.Value        = "{E3676993-C682-11D2-8A2A-006097AFF44E}";
                    break;
                }

                case esriFeatureType.esriFTDimension:
                {
                    esriGeometryType_0 = esriGeometryType.esriGeometryPolygon;
                    uid_0.Value        = "{496764FC-E0C9-11D3-80CE-00C04F601565}";
                    break;
                }
                }
            }
            if (uid_1 == null)
            {
                switch (esriFeatureType_0)
                {
                case esriFeatureType.esriFTAnnotation:
                {
                    uid_1 = new UID()
                    {
                        Value = "{24429589-D711-11D2-9F41-00C04F6BC6A5}"
                    };
                    break;
                }

                case esriFeatureType.esriFTDimension:
                {
                    uid_1 = new UID()
                    {
                        Value = "{48F935E2-DA66-11D3-80CE-00C04F601565}"
                    };
                    break;
                }
                }
            }
            if (ifields_0 == null)
            {
                ifields_0 = new ESRI.ArcGIS.Geodatabase.Fields();
                IFieldsEdit      ifields0          = (IFieldsEdit)ifields_0;
                IGeometryDef     geometryDefClass  = new GeometryDef();
                IGeometryDefEdit esriGeometryType0 = (IGeometryDefEdit)geometryDefClass;
                esriGeometryType0.GeometryType_2 = esriGeometryType_0;
                esriGeometryType0.GridCount_2    = 1;
                esriGeometryType0.GridSize_2[0]  = 0.5;
                esriGeometryType0.AvgNumPoints_2 = 2;
                esriGeometryType0.HasM_2         = false;
                esriGeometryType0.HasZ_2         = true;
                if (object_0 is IWorkspace)
                {
                    esriGeometryType0.SpatialReference_2 = ispatialReference_0;
                }
                IField     fieldClass = new ESRI.ArcGIS.Geodatabase.Field();
                IFieldEdit fieldEdit  = (IFieldEdit)fieldClass;
                fieldEdit.Name_2      = "OBJECTID";
                fieldEdit.AliasName_2 = "OBJECTID";
                fieldEdit.Type_2      = esriFieldType.esriFieldTypeOID;
                ifields0.AddField(fieldClass);
                IField     field      = new ESRI.ArcGIS.Geodatabase.Field();
                IFieldEdit fieldEdit1 = (IFieldEdit)field;
                fieldEdit1.Name_2        = "SHAPE";
                fieldEdit1.AliasName_2   = "SHAPE";
                fieldEdit1.Type_2        = esriFieldType.esriFieldTypeGeometry;
                fieldEdit1.GeometryDef_2 = geometryDefClass;
                ifields0.AddField(field);
            }
            string name = "";
            int    num  = 0;

            while (true)
            {
                if (num > ifields_0.FieldCount - 1)
                {
                    break;
                }
                else if (ifields_0.Field[num].Type == esriFieldType.esriFieldTypeGeometry)
                {
                    name = ifields_0.Field[num].Name;
                    break;
                }
                else
                {
                    num++;
                }
            }
            if (name == "")
            {
                throw new Exception("Cannot locate geometry field in FIELDS");
            }
            IFeatureClass featureClass = null;

            if (object_0 is IWorkspace)
            {
                IFeatureWorkspace object0 = (IFeatureWorkspace)((IWorkspace)object_0);
                featureClass = object0.CreateFeatureClass(string_0, ifields_0, uid_0, uid_1, esriFeatureType_0, name,
                                                          string_1);
            }
            else if (object_0 is IFeatureDataset)
            {
                IFeatureDataset featureDataset = (IFeatureDataset)object_0;
                featureClass = featureDataset.CreateFeatureClass(string_0, ifields_0, uid_0, uid_1, esriFeatureType_0,
                                                                 name, string_1);
            }
            return(featureClass);
        }
示例#15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="outName"></param>
        /// <param name="isDissolved"></param>
        /// <returns></returns>
        public static IFeatureClass CreateOutputFc(string outPath, IFeatureClass inputFc, bool isDissolved)
        {
            IFeatureWorkspace fws = getWorkspace(outPath);

            //Debug.WriteLine(outPath);
            //Debug.WriteLine((fws as IWorkspace).PathName);
            IFeatureClass fc = null;

            string[]        pathParts       = outPath.Split('\\');
            string          outName         = pathParts[pathParts.Length - 1];
            string          featDatasetName = null;
            IFeatureDataset featDs          = null;

            if (pathParts.Length > 3)
            {
                if (pathParts[pathParts.Length - 3].ToLower().IndexOf(".gdb") > -1)
                {
                    featDatasetName = pathParts[pathParts.Length - 2];
                }
            }


            if (featDatasetName == null)
            {
                IWorkspace2 ws2 = fws as IWorkspace2;

                if (ws2.get_NameExists(esriDatasetType.esriDTFeatureClass, outName))
                {
                    IDataset dsExist = (IDataset)((IFeatureWorkspace)ws2).OpenFeatureClass(outName);
                    deleteFeatureClass(dsExist);
                }
            }
            else
            {
                IEnumDataset enumFds = (fws as IWorkspace).get_Datasets(esriDatasetType.esriDTFeatureDataset);

                IDataset _fds;

                while ((_fds = enumFds.Next()) != null)
                {
                    if (_fds.Name == featDatasetName)
                    {
                        featDs = (IFeatureDataset)_fds;

                        IEnumDataset enumFcs = featDs.Subsets;

                        IDataset ids;

                        while ((ids = enumFcs.Next()) != null)
                        {
                            if (ids.Name.ToLower() == outName.ToLower())
                            {
                                deleteFeatureClass(ids);
                                break;
                            }
                        }

                        break;
                    }
                }
            }


            IFields fields = GetCurveAreaFields(outName.IndexOf(".shp") > -1, isDissolved, ((IGeoDataset)inputFc).SpatialReference);

            try
            {
                if (featDs == null)
                {
                    fc = fws.CreateFeatureClass(outName, fields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID, esriFeatureType.esriFTSimple, "SHAPE", "");
                }
                else
                {
                    fc = featDs.CreateFeatureClass(outName, fields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID, esriFeatureType.esriFTSimple, "SHAPE", "");
                }
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                string errorMessage = "Could not create output feature class:\n";

                if (featDs == null)
                {
                    errorMessage += System.IO.Path.Combine((fws as IWorkspace).PathName, outName) + "\n";
                }
                else
                {
                    errorMessage += System.IO.Path.Combine((fws as IWorkspace).PathName, featDs.Name, outName) + "\n";
                }
                errorMessage += ex.Message;

                throw new System.IO.IOException(errorMessage);
            }

            return(fc);
        }
示例#16
0
        public static IFeatureClass CreateFeatureClass(IWorkspace workspace, IFeatureDataset featureDataset, String featureClassName, IFields fields)
        {
            IFeatureClass           featureClass;
            String                  strShapeField          = "";
            var                     featureWorkspace       = workspace as IFeatureWorkspace;
            IObjectClassDescription objectClassDescription = new FeatureClassDescriptionClass();

            #region 简单校验
            if (featureClassName == "")
            {
                return(null);
            }
            //if (workspace.get_NameExists(esriDatasetType.esriDTFeatureClass, featureClassName))
            //{
            //    featureClass = featureWorkspace.OpenFeatureClass(featureClassName);
            //    return featureClass;
            //}

            if (fields == null)
            {
                fields = objectClassDescription.RequiredFields;
                IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
                IField      field      = new FieldClass();
                IFieldEdit  fieldEdit  = (IFieldEdit)field;
                fieldEdit.Name_2 = "Name";
                fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                fieldsEdit.AddField(field);
                fields = (IFields)fieldsEdit;
            }

            var feaClsDes = objectClassDescription as IFeatureClassDescription;
            strShapeField = feaClsDes.ShapeFieldName;
            #endregion

            //查询几何字段
            if (strShapeField == "")
            {
                for (int j = 0; j < fields.FieldCount; j++)
                {
                    if (fields.get_Field(j).Type == esriFieldType.esriFieldTypeGeometry)
                    {
                        strShapeField = fields.get_Field(j).Name;
                    }
                }
            }


            // 字段检查
            IFieldChecker   fieldChecker    = new FieldCheckerClass();
            IEnumFieldError enumFieldError  = null;
            IFields         validatedFields = null;
            fieldChecker.ValidateWorkspace = (IWorkspace)workspace;
            fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

            //创建要素类
            if (featureDataset == null)
            {
                featureClass = featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, objectClassDescription.InstanceCLSID, objectClassDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, strShapeField, "");
            }
            else
            {
                featureClass = featureDataset.CreateFeatureClass(featureClassName, validatedFields, objectClassDescription.InstanceCLSID, objectClassDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, strShapeField, "");
            }
            return(featureClass);
        }
示例#17
0
        /// <summary>
        /// 创建一个要素集
        /// </summary>
        private void CreateFeatureClass()
        {
            string path    = txt_org.Text;
            string PRJFile = txt_prj.Text;
            AccessWorkspaceFactory pAccessFact = new AccessWorkspaceFactoryClass();

            IFeatureWorkspace         pFeatureWorkspace = pAccessFact.OpenFromFile(path, 0) as IFeatureWorkspace;
            ISpatialReferenceFactory2 Isp = new SpatialReferenceEnvironmentClass();                   //创建一个空间参照的接口空间

            ISpatialReference           spatial = Isp.CreateESRISpatialReferenceFromPRJFile(PRJFile); //利用要素类的PRJ文件参照
            ISpatialReferenceResolution pSRR    = (ISpatialReferenceResolution)spatial;               //设置分辨率

            pSRR.SetDefaultXYResolution();                                                            //设置默认XY值

            ISpatialReferenceTolerance pSRT = (ISpatialReferenceTolerance)spatial;

            pSRT.SetDefaultXYTolerance();//设置默认容差值
            IWorkspace space = pFeatureWorkspace as IWorkspace;

            IEnumDatasetName Dataset_name = space.get_DatasetNames(esriDatasetType.esriDTAny);//得到有多少个要素集合名字

            Dataset_name.Reset();
            IDatasetName Name_set = Dataset_name.Next();

            while (Name_set != null)
            {
                if (Name_set.Name == "Geo_Topo_ice")
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "数据集已存在,不用创建!");
                    this.Close();//如果要创建的数据集已存在,就返回,并关闭窗体
                    return;
                }
                Name_set = Dataset_name.Next();
            }
            IFeatureDataset pfd = pFeatureWorkspace.CreateFeatureDataset("Geo_Topo_ice", spatial); //创建一个要素集

            IEnumDataset dst = space.get_Datasets(esriDatasetType.esriDTAny);                      //得到所有的要素类的一个集合

            dst.Reset();
            IDataset det = dst.Next();

            _AppHk.OperatorTips = "开始创建对应的要素类...";
            while (det != null)
            {
                #region 给要素集创建空的要素类
                if (det.Type == esriDatasetType.esriDTFeatureClass)                       //判定是不是要素类
                {
                    string org_name = det.Name;                                           //原始的名字
                    _AppHk.OperatorTips = "开始创建" + org_name + "要素类...";
                    IFeatureClass f_class = pFeatureWorkspace.OpenFeatureClass(org_name); //打开源要素类
                    det.Rename(org_name + "_t");                                          //把源要素类进行重命名
                    IFields     Fieldset = new FieldsClass();                             //建立一个字段集
                    IFieldsEdit sField   = Fieldset as IFieldsEdit;                       //字段集
                    if (f_class.FeatureType != esriFeatureType.esriFTAnnotation)
                    {
                        //shape
                        IGeometryDefEdit d_edit;                       //定义一个用来接收要素类的SHAPE类型
                        d_edit = new GeometryDefClass();               //实例一个操作类
                        d_edit.GeometryType_2     = f_class.ShapeType; //将源要素类的SHAPE赋值给我们要创建的几何类型
                        d_edit.SpatialReference_2 = spatial;           //空间参考

                        string OID   = f_class.OIDFieldName;           //ODI名字
                        string SHAPE = f_class.ShapeFieldName;         //SHAPE名字

                        //IFields Fieldset = new FieldsClass();//建立一个字段集
                        //IFieldsEdit sField = Fieldset as IFieldsEdit;//字段集


                        //创建要素类里的字段
                        int count = f_class.Fields.FieldCount;//确定有多少个字段

                        #region 创建字段
                        for (int n = 0; n < count; n++)
                        {
                            IField f_ield = f_class.Fields.get_Field(n);

                            IFieldEdit fieldEdit = f_ield as IFieldEdit;
                            //Annotate
                            if (f_ield.Name == SHAPE)
                            {
                                //shape field
                                fieldEdit.Type_2        = esriFieldType.esriFieldTypeGeometry; //确定字段的类型
                                fieldEdit.GeometryDef_2 = d_edit;                              //把几何类型赋值给它
                                fieldEdit.Name_2        = SHAPE;                               //把几何类型SHPAE的名字赋值给它
                                f_ield = fieldEdit as IField;
                                sField.AddField(f_ield);                                       //加入要素集
                            }
                            else if (f_ield.Name == OID)
                            {
                                //oid
                                fieldEdit.Type_2 = esriFieldType.esriFieldTypeOID; //OID标识字段
                                fieldEdit.Name_2 = OID;                            //OID的名字
                                f_ield           = fieldEdit as IField;
                                sField.AddField(f_ield);                           //加入OID
                            }
                            else
                            {
                                //一般字段
                                fieldEdit.Name_2 = f_ield.Name;
                                fieldEdit.Type_2 = f_ield.Type;//字段的类型

                                f_ield = fieldEdit as IField;
                                sField.AddField(f_ield);
                            }
                        }
                        #endregion

                        Fieldset = sField as IFields;                                                                             //将可编辑的字段集转成一般字段集
                        pfd.CreateFeatureClass(org_name, Fieldset, f_class.CLSID, null, esriFeatureType.esriFTSimple, SHAPE, ""); //给要素集中创建要素类
                    }
                    else
                    {
                        createAnnoFeatureClass(org_name, pfd, pfd.Workspace as IFeatureWorkspace, sField, 2000);
                    }

                    det = dst.Next();//重新遍历下一个
                }
                else
                {
                    det = dst.Next();//重新遍历下一个
                }
                #endregion
            }
            _AppHk.OperatorTips = "要素集合创建成功!";
            GetValue(pFeatureWorkspace);//当对应的要素类建立好后,就开始给空要素类赋值
            SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "数据处理完成!");
            this.Close();
        }
示例#18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="featureDataset"></param>
        /// <param name="strNameOfFeatureClass"></param>
        /// <returns></returns>
        public static IFeatureClass CreateCurveFeatureClass(IFeatureDataset featureDataset, String strNameOfFeatureClass)
        {
            // This function creates a new feature class in a supplied feature dataset by building all of the
            // fields from scratch. IFeatureClassDescription (or IObjectClassDescription if the table is
            // created at the workspace level) can be used to get the required fields and are used to
            // get the InstanceClassID and ExtensionClassID.
            // Create new fields collection with the number of fields you plan to add. Must add at least two fields
            // for a feature class: Object ID and Shape field.
            IFields     fields     = new FieldsClass();
            IFieldsEdit fieldsEdit = (IFieldsEdit)fields;

            fieldsEdit.FieldCount_2 = 10;

            // Create Object ID field.
            IField     fieldUserDefined = new Field();
            IFieldEdit fieldEdit        = (IFieldEdit)fieldUserDefined;

            fieldEdit.Name_2      = "OBJECTID";
            fieldEdit.AliasName_2 = "OBJECTID";
            fieldEdit.Type_2      = esriFieldType.esriFieldTypeOID;
            fieldsEdit.set_Field(0, fieldUserDefined);

            // Create Shape field.
            fieldUserDefined = new Field();
            fieldEdit        = (IFieldEdit)fieldUserDefined;
            // Set up geometry definition for the Shape field.
            // You do not have to set the spatial reference, as it is inherited from the feature dataset.
            IGeometryDef     geometryDef     = new GeometryDefClass();
            IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;

            geometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline;
            // By setting the grid size to 0, you are allowing ArcGIS to determine the appropriate grid sizes for the feature class.
            // If in a personal geodatabase, the grid size is 1,000. If in a file or ArcSDE geodatabase, the grid size
            // is based on the initial loading or inserting of features.
            geometryDefEdit.GridCount_2 = 1;
            geometryDefEdit.set_GridSize(0, 0);
            geometryDefEdit.HasM_2 = false;
            geometryDefEdit.HasZ_2 = false;
            // Set standard field properties
            fieldEdit.Name_2        = "SHAPE";
            fieldEdit.Type_2        = esriFieldType.esriFieldTypeGeometry;
            fieldEdit.GeometryDef_2 = geometryDef;
            fieldEdit.IsNullable_2  = true;
            fieldEdit.Required_2    = true;
            fieldsEdit.set_Field(1, fieldUserDefined);

            // Create FromLayer
            fieldUserDefined       = new Field();
            fieldEdit              = (IFieldEdit)fieldUserDefined;
            fieldEdit.Name_2       = "FROMLAYER";
            fieldEdit.AliasName_2  = "The layer where these curves were identified from";
            fieldEdit.Editable_2   = true;
            fieldEdit.IsNullable_2 = false;
            fieldEdit.Precision_2  = 0;
            fieldEdit.Scale_2      = 5;
            fieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
            fieldsEdit.set_Field(2, fieldUserDefined);

            // Create StreetID Field
            fieldUserDefined       = new Field();
            fieldEdit              = (IFieldEdit)fieldUserDefined;
            fieldEdit.Name_2       = "STREETID";
            fieldEdit.AliasName_2  = "Polyline ID of the street where the curve is located";
            fieldEdit.Editable_2   = true;
            fieldEdit.IsNullable_2 = false;
            fieldEdit.Precision_2  = 0;
            fieldEdit.Scale_2      = 5;
            fieldEdit.Type_2       = esriFieldType.esriFieldTypeInteger;
            fieldsEdit.set_Field(3, fieldUserDefined);

            // Create StreetName Field
            fieldUserDefined       = new Field();
            fieldEdit              = (IFieldEdit)fieldUserDefined;
            fieldEdit.Name_2       = "STREETNAME";
            fieldEdit.AliasName_2  = "Name of the street where the curve is located";
            fieldEdit.Editable_2   = true;
            fieldEdit.IsNullable_2 = false;
            fieldEdit.Precision_2  = 0;
            fieldEdit.Scale_2      = 5;
            fieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
            fieldsEdit.set_Field(4, fieldUserDefined);

            // Create StreetDirc Field
            fieldUserDefined       = new Field();
            fieldEdit              = (IFieldEdit)fieldUserDefined;
            fieldEdit.Name_2       = "STREETDIRC";
            fieldEdit.AliasName_2  = "Direction of the street";
            fieldEdit.Editable_2   = true;
            fieldEdit.IsNullable_2 = false;
            fieldEdit.Precision_2  = 0;
            fieldEdit.Scale_2      = 5;
            fieldEdit.Type_2       = esriFieldType.esriFieldTypeString;
            fieldsEdit.set_Field(5, fieldUserDefined);

            // Create CurveIndex Field
            fieldUserDefined       = new Field();
            fieldEdit              = (IFieldEdit)fieldUserDefined;
            fieldEdit.Name_2       = "CURVEINDEX";
            fieldEdit.AliasName_2  = "Index of the curve within the street";
            fieldEdit.Editable_2   = true;
            fieldEdit.IsNullable_2 = false;
            fieldEdit.Precision_2  = 0;
            fieldEdit.Scale_2      = 5;
            fieldEdit.Type_2       = esriFieldType.esriFieldTypeInteger;
            fieldsEdit.set_Field(6, fieldUserDefined);

            // Create Length
            fieldUserDefined       = new Field();
            fieldEdit              = (IFieldEdit)fieldUserDefined;
            fieldEdit.Name_2       = "LENGTH";
            fieldEdit.AliasName_2  = "Length of the curve";
            fieldEdit.Editable_2   = true;
            fieldEdit.IsNullable_2 = false;
            fieldEdit.Precision_2  = 2;
            fieldEdit.Scale_2      = 5;
            fieldEdit.Type_2       = esriFieldType.esriFieldTypeDouble;
            fieldsEdit.set_Field(7, fieldUserDefined);

            // Create Radius Field
            fieldUserDefined       = new Field();
            fieldEdit              = (IFieldEdit)fieldUserDefined;
            fieldEdit.Name_2       = "RADIUS";
            fieldEdit.AliasName_2  = "Radius of the curve";
            fieldEdit.Editable_2   = true;
            fieldEdit.IsNullable_2 = false;
            fieldEdit.Precision_2  = 2;
            fieldEdit.Scale_2      = 5;
            fieldEdit.Type_2       = esriFieldType.esriFieldTypeDouble;
            fieldsEdit.set_Field(8, fieldUserDefined);

            // Create Angle Field
            fieldUserDefined       = new Field();
            fieldEdit              = (IFieldEdit)fieldUserDefined;
            fieldEdit.Name_2       = "ANGLE";
            fieldEdit.AliasName_2  = "Central Angle of the curve";
            fieldEdit.Editable_2   = true;
            fieldEdit.IsNullable_2 = false;
            fieldEdit.Precision_2  = 3;
            fieldEdit.Scale_2      = 5;
            fieldEdit.Type_2       = esriFieldType.esriFieldTypeDouble;
            fieldsEdit.set_Field(9, fieldUserDefined);

            // Create a feature class description object to use for specifying the CLSID and EXTCLSID.
            IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass();
            IObjectClassDescription  ocDesc = (IObjectClassDescription)fcDesc;

            return(featureDataset.CreateFeatureClass(strNameOfFeatureClass, fields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID, esriFeatureType.esriFTSimple, "SHAPE", ""));
        }
示例#19
0
        //创建featureclass
        private IFeatureClass CreateFeatureClass(string name, IFeatureClass pFeaCls, IFeatureDataset pFeaDataset, IFeatureWorkspace pWks)
        {
            UID uidCLSID  = null;
            UID uidCLSEXT = null;


            try
            {
                IObjectClassDescription pObjCls = null;
                if (uidCLSID == null)
                {
                    //esriGeometryType GeometryType;
                    uidCLSID = new UIDClass();
                    switch (pFeaCls.FeatureType)
                    {
                    case (esriFeatureType.esriFTSimple):
                        uidCLSID.Value = "{52353152-891A-11D0-BEC6-00805F7C4268}";
                        break;

                    case (esriFeatureType.esriFTSimpleJunction):
                        //GeometryType = esriGeometryType.esriGeometryPoint;
                        uidCLSID.Value = "{CEE8D6B8-55FE-11D1-AE55-0000F80372B4}";
                        break;

                    case (esriFeatureType.esriFTComplexJunction):
                        uidCLSID.Value = "{DF9D71F4-DA32-11D1-AEBA-0000F80372B4}";
                        break;

                    case (esriFeatureType.esriFTSimpleEdge):
                        //GeometryType = esriGeometryType.esriGeometryPolyline;
                        uidCLSID.Value = "{E7031C90-55FE-11D1-AE55-0000F80372B4}";
                        break;

                    case (esriFeatureType.esriFTComplexEdge):
                        //GeometryType = esriGeometryType.esriGeometryPolyline;
                        uidCLSID.Value = "{A30E8A2A-C50B-11D1-AEA9-0000F80372B4}";
                        break;

                    case (esriFeatureType.esriFTAnnotation):
                        //GeometryType = esriGeometryType.esriGeometryPolygon;
                        uidCLSID.Value = "{E3676993-C682-11D2-8A2A-006097AFF44E}";
                        break;

                    case (esriFeatureType.esriFTDimension):
                        //GeometryType = esriGeometryType.esriGeometryPolygon;
                        uidCLSID.Value = "{496764FC-E0C9-11D3-80CE-00C04F601565}";
                        break;
                    }
                }

                // 设置 uidCLSEXT (if Null)
                if (uidCLSEXT == null)
                {
                    switch (pFeaCls.FeatureType)
                    {
                    case (esriFeatureType.esriFTAnnotation):
                        uidCLSEXT       = new UIDClass();
                        uidCLSEXT.Value = "{24429589-D711-11D2-9F41-00C04F6BC6A5}";
                        pObjCls         = new AnnotationFeatureClassDescriptionClass();
                        break;

                    case (esriFeatureType.esriFTDimension):
                        uidCLSEXT       = new UIDClass();
                        uidCLSEXT.Value = "{48F935E2-DA66-11D3-80CE-00C04F601565}";
                        break;
                    }
                }
                //IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspace;
                IFieldChecker fdCheker = new FieldCheckerClass();//yjl20110804 add
                pEnumFieldError            = null;
                pFixedField                = null;
                fdCheker.ValidateWorkspace = pWks as IWorkspace;
                fdCheker.Validate(pFeaCls.Fields, out pEnumFieldError, out pFixedField);

                //string strShapeFieldName = pfeaturelayer.FeatureClass.ShapeFieldName;//geometry字段名
                //string[] strShapeNames = strShapeFieldName.Split('.');
                //strShapeFieldName = strShapeNames[strShapeNames.GetLength(0) - 1];

                IFields pFields = new FieldsClass();
                if (pObjCls != null)
                {
                    IFeatureClassDescription pClsDes = pObjCls as IFeatureClassDescription;
                    pFields = pObjCls.RequiredFields;
                }

                IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;

                for (int i = 0; i < pFeaCls.Fields.FieldCount; i++)
                {
                    IField   pf            = pFeaCls.Fields.get_Field(i);
                    string   strFieldName  = pf.Name;
                    string[] strFieldNames = strFieldName.Split('.');

                    bool blnfind = false;
                    for (int j = 0; j < pFields.FieldCount; j++)
                    {
                        IField   pf2        = pFields.get_Field(j);
                        string[] strfields2 = pf2.Name.Split('.');
                        if (strfields2[strfields2.GetLength(0) - 1].ToUpper() == strFieldNames[strFieldNames.GetLength(0) - 1].ToUpper())
                        {
                            blnfind = true;
                            break;
                        }
                    }

                    if (blnfind)
                    {
                        continue;
                    }

                    if (pFeaCls.FeatureType == esriFeatureType.esriFTAnnotation)
                    {
                        if (pFeaCls.ShapeFieldName == pf.Name)
                        {
                            continue;
                        }
                    }

                    if (pFeaCls.LengthField != null)
                    {
                        if (pFeaCls.LengthField.Name == pf.Name)
                        {
                            continue;
                        }
                    }
                    if (pFeaCls.AreaField != null)
                    {
                        if (pFeaCls.AreaField.Name == pf.Name)
                        {
                            continue;
                        }
                    }

                    IClone     pClone         = pFeaCls.Fields.get_Field(i) as IClone;
                    IField     pTempField     = pClone.Clone() as IField;
                    IFieldEdit pTempFieldEdit = pTempField as IFieldEdit;

                    if (pFieldsEdit.FindField(strFieldNames[strFieldNames.GetLength(0) - 1]) > -1)
                    {
                        continue;
                    }

                    pTempFieldEdit.Name_2 = strFieldNames[strFieldNames.GetLength(0) - 1];
                    pFieldsEdit.AddField(pTempField);
                }

                string   strShapeFieldName = pFeaCls.ShapeFieldName;
                string[] strShapeNames     = strShapeFieldName.Split('.');
                strShapeFieldName = strShapeNames[strShapeNames.GetLength(0) - 1];

                //修改geometrydef
                IField pFieldShape = pFeaCls.Fields.get_Field(pFeaCls.Fields.FindField(pFeaCls.ShapeFieldName));

                if (pFieldShape != null)
                {
                    IFieldEdit pFieldShapeEdit = pFields.get_Field(pFields.FindField(strShapeFieldName)) as IFieldEdit;
                    pFieldShapeEdit.GeometryDef_2 = pFieldShape.GeometryDef;
                }

                IGeometryDef pGeoDef  = pFieldShape.GeometryDef;
                double       dblIndex = pGeoDef.get_GridSize(0);

                //添加两个字段一个时间 一个名称
                if (pFields.FindField("ImportTime") < 0)
                {
                    IField     pNewField1 = new FieldClass();
                    IFieldEdit pNewEdit1  = pNewField1 as IFieldEdit;
                    pNewEdit1.Name_2      = "ImportTime";
                    pNewEdit1.AliasName_2 = "入库时间";
                    pNewEdit1.Type_2      = esriFieldType.esriFieldTypeDate;
                    pFieldsEdit.AddField(pNewField1);
                }

                if (pFields.FindField("ImportUser") < 0)
                {
                    IField     pNewField2 = new FieldClass();
                    IFieldEdit pNewEdit2  = pNewField2 as IFieldEdit;
                    pNewEdit2.Name_2      = "ImportUser";
                    pNewEdit2.AliasName_2 = "入库人";
                    pNewEdit2.Type_2      = esriFieldType.esriFieldTypeString;
                    pFieldsEdit.AddField(pNewField2);
                }

                IFeatureClass targetFeatureclass = null;


                if (pFeaCls.FeatureType == esriFeatureType.esriFTAnnotation)
                {
                    IAnnoClass pAnno = pFeaCls.Extension as IAnnoClass;

                    IFeatureWorkspaceAnno pWksAnno = pWks as IFeatureWorkspaceAnno;
                    IGraphicsLayerScale   pGl      = new GraphicsLayerScaleClass();
                    pGl.ReferenceScale = pAnno.ReferenceScale;
                    pGl.Units          = pAnno.ReferenceScaleUnits;
                    targetFeatureclass = pWksAnno.CreateAnnotationClass(name, pFields, pFeaCls.CLSID, pFeaCls.EXTCLSID, strShapeFieldName, "", pFeaDataset, null, pAnno.AnnoProperties, pGl, pAnno.SymbolCollection, false);
                }
                else
                {
                    if (pFeaDataset != null)
                    {
                        targetFeatureclass = pFeaDataset.CreateFeatureClass(name, pFixedField, uidCLSID, uidCLSEXT, pFeaCls.FeatureType, strShapeFieldName, "");
                    }
                    else
                    {
                        targetFeatureclass = pWks.CreateFeatureClass(name, pFixedField, uidCLSID, uidCLSEXT, pFeaCls.FeatureType, strShapeFieldName, "");
                    }
                }

                return(targetFeatureclass);
            }
            catch (Exception ex)
            {
                if (ex.Message == "Cannot create a low precision dataset in a high precision database.")
                {
                    MessageBox.Show("数据必须是ArcGis9.2的数据,请将数据处理成ArcGis9.2的数据!");
                }
            }
            IFeatureClass featureclass = null;

            return(featureclass);
        }
示例#20
0
        //转换要素类
        private void CoordConvertFeatureClass(IFeatureClass fc, ISpatialReference spatialReference, out IFeatureClass outfc)
        {
            WaitForm.SetCaption("正在转换" + fc.AliasName + ",请稍后...");
            outfc = null;
            IWorkspaceFactory pWsF    = new AccessWorkspaceFactoryClass();
            IFeatureWorkspace pFWs    = null;
            IFeatureClass     pTempFc = null;

            try
            {
                IFields pFields = new FieldsClass();
                pFields = GetFieldsFromFeatureClass(fc, spatialReference);

                pFWs = pWsF.OpenFromFile(m_Path + @"\" + m_Name, 0) as IFeatureWorkspace;

                IDataset pDataset  = fc as IDataset;
                string   strFCName = pDataset.Name;
                try
                {
                    pTempFc = pFWs.OpenFeatureClass(strFCName);
                }
                catch (System.Exception ex)
                {
                    IFeatureDataset pFeatureDataset    = fc.FeatureDataset;
                    IFeatureDataset pFeatureDatasetNew = null;
                    if (pFeatureDataset != null)
                    {
                        try
                        {
                            pFeatureDatasetNew = pFWs.OpenFeatureDataset(pFeatureDataset.Name);
                            pTempFc            = pFeatureDatasetNew.CreateFeatureClass(strFCName, pFields, fc.CLSID, fc.EXTCLSID, fc.FeatureType, fc.ShapeFieldName, null);
                            (pTempFc as IClassSchemaEdit).AlterAliasName(fc.AliasName);
                        }
                        catch
                        {
                            pFeatureDatasetNew = pFWs.CreateFeatureDataset(pFeatureDataset.Name, spatialReference);

                            //若为注记
                            if (fc.FeatureType == esriFeatureType.esriFTAnnotation)
                            {
                                IFeatureWorkspaceAnno pFWsAnno   = pFWs as IFeatureWorkspaceAnno;
                                IAnnoClass            pAnnoClass = fc.Extension as IAnnoClass;

                                IGraphicsLayerScale pGLS = new GraphicsLayerScaleClass();
                                pGLS.ReferenceScale = pAnnoClass.ReferenceScale;
                                pGLS.Units          = pAnnoClass.ReferenceScaleUnits;
                                try
                                {
                                    pTempFc = pFWsAnno.CreateAnnotationClass(strFCName,
                                                                             pFields, fc.CLSID, fc.EXTCLSID, fc.ShapeFieldName, "",
                                                                             pFeatureDatasetNew, null, pAnnoClass.AnnoProperties, pGLS,
                                                                             pAnnoClass.SymbolCollection, true);
                                    (pTempFc as IClassSchemaEdit).AlterAliasName(fc.AliasName);
                                }
                                catch
                                {
                                    WaitForm.Stop();
                                }
                            }
                            else//若为地理要素
                            {
                                try
                                {
                                    pTempFc = pFeatureDatasetNew.CreateFeatureClass(strFCName, pFields, null, null, fc.FeatureType, fc.ShapeFieldName, null);
                                    (pTempFc as IClassSchemaEdit).AlterAliasName(fc.AliasName);
                                }
                                catch
                                {
                                    WaitForm.Stop();
                                }
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            if (fc.FeatureType == esriFeatureType.esriFTAnnotation)//若为注记
                            {
                                IFeatureWorkspaceAnno pFWsAnno   = pFWs as IFeatureWorkspaceAnno;
                                IAnnoClass            pAnnoClass = fc.Extension as IAnnoClass;

                                IGraphicsLayerScale pGLS = new GraphicsLayerScaleClass();
                                pGLS.ReferenceScale = pAnnoClass.ReferenceScale;
                                pGLS.Units          = pAnnoClass.ReferenceScaleUnits;
                                try
                                {
                                    pTempFc = pFWsAnno.CreateAnnotationClass(strFCName,
                                                                             pFields, fc.CLSID, fc.EXTCLSID, fc.ShapeFieldName, "",
                                                                             pFeatureDatasetNew, null, pAnnoClass.AnnoProperties, pGLS,
                                                                             pAnnoClass.SymbolCollection, true);
                                    (pTempFc as IClassSchemaEdit).AlterAliasName(fc.AliasName);
                                }
                                catch
                                {
                                    WaitForm.Stop();
                                }
                            }
                            else
                            {
                                try
                                {
                                    pTempFc = pFeatureDatasetNew.CreateFeatureClass(strFCName, pFields, null, null, fc.FeatureType, fc.ShapeFieldName, null);
                                    (pTempFc as IClassSchemaEdit).AlterAliasName(fc.AliasName);
                                }
                                catch
                                {
                                    WaitForm.Stop();
                                }
                            }
                        }
                        catch
                        {
                            WaitForm.Stop();
                        }
                    }
                }
                if (fc.FeatureType == esriFeatureType.esriFTAnnotation)
                {
                    IFeature       outFeature;
                    IFeature       pFeature;
                    IFeatureCursor pFeatureCursor = GetSelectedFeatures(GetLayerByNameFromMap(m_Map, strFCName));
                    if (pFeatureCursor == null)
                    {
                        return;
                    }
                    while ((pFeature = pFeatureCursor.NextFeature()) != null)
                    {
                        try
                        {
                            outFeature = pTempFc.CreateFeature();
                            CoordConvertAnnotationFeature(pFeature, ref outFeature);
                            outFeature.Store();
                        }
                        catch (System.Exception ex)
                        {
                            WaitForm.Stop();
                        }
                    }
                    outfc = pTempFc;
                }
                else//若为几何要素
                {
                    IFeature       outFeature;
                    IFeature       pFeature;
                    IFeatureCursor pFeatureCursor = GetSelectedFeatures(GetLayerByNameFromMap(m_Map, strFCName));
                    if (pFeatureCursor == null)
                    {
                        return;
                    }
                    while ((pFeature = pFeatureCursor.NextFeature()) != null)
                    {
                        try
                        {
                            outFeature = pTempFc.CreateFeature();
                            CoordConvertFeature(pFeature, ref outFeature);
                            outFeature.Store();
                        }
                        catch
                        {
                            WaitForm.Stop();
                        }
                    }
                    outfc = pTempFc;
                }
            }
            catch (System.Exception ex)
            {
                WaitForm.Stop();
            }
        }
        public static IFeatureClass CreateFeatureClass(IGPValue gpFeatureClass, IGPEnvironmentManager environment, IFields fields = null)
        {
            if (gpFeatureClass == null)
            {
                throw new ArgumentException("Argument can not be null", "gpFeatureClass");
            }
            if (environment == null)
            {
                throw new ArgumentException("Argument can not be null", "environment");
            }


            IGeoProcessorSettings gpSettings = (IGeoProcessorSettings)environment;

            if (gpUtilities.Exists(gpFeatureClass))
            {
                if (gpSettings.OverwriteOutput == true)
                {
                    gpUtilities.Delete(gpFeatureClass);
                }
                else
                {
                    throw new Exception("Output feature class already exists: " + gpFeatureClass.GetAsText());
                }
            }


            IDEFeatureClass deFeatureClass = (IDEFeatureClass)gpUtilities.DecodeDETable(gpFeatureClass);

            if (deFeatureClass == null)
            {
                throw new Exception("Data Element decode return null");
            }

            IObjectClassDescription objectClassDescription = (IObjectClassDescription) new FeatureClassDescriptionClass();
            UID clsid    = objectClassDescription.InstanceCLSID;
            UID extclsid = objectClassDescription.ClassExtensionCLSID;

            IDataElement dataElement = (IDataElement)deFeatureClass;

            if (dataElement.CatalogPath == null)
            {
                throw new ArgumentException("Catalog path is null", "CatalogPath");
            }
            IFeatureClassName featureClassName = (IFeatureClassName)gpUtilities.CreateFeatureClassName(dataElement.CatalogPath);

            string path = dataElement.GetPath();
            string name = dataElement.Name;

            IDEGeoDataset     geoDataElement   = (IDEGeoDataset)deFeatureClass;
            ISpatialReference spatialReference = geoDataElement.SpatialReference;

            IDETable deTable        = (IDETable)deFeatureClass;
            string   shapeFieldName = deFeatureClass.ShapeFieldName;

            Dictionary <string, IField> fieldBuilder = new Dictionary <string, IField>();

            foreach (var input_fields in new IFields[] { deTable.Fields, fields })
            {
                if (input_fields == null)
                {
                    continue;
                }
                for (int i = 0; i < input_fields.FieldCount; i++)
                {
                    IField field = deTable.Fields.get_Field(i);

                    if (fieldBuilder.ContainsKey(field.Name.ToLower()))
                    {
                        fieldBuilder[field.Name.ToLower()] = (IField)((IClone)field).Clone();
                    }
                    else
                    {
                        fieldBuilder.Add(field.Name.ToLower(), (IField)((IClone)field).Clone());
                    }

                    if (field.Type == esriFieldType.esriFieldTypeGeometry)
                    {
                        shapeFieldName = field.Name;
                        break;
                    }
                }
            }

            IFields     output_fields = new FieldsClass();
            IFieldsEdit fields_edit   = (IFieldsEdit)output_fields;

            foreach (IField field in fieldBuilder.Values)
            {
                fields_edit.AddField(field);
                if (field.Type == esriFieldType.esriFieldTypeGeometry)
                {
                    IGeometryDefEdit defEdit = (IGeometryDefEdit)field.GeometryDef;
                    defEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
                }
            }

            string configKeyword = ((IGPString)environment.FindEnvironment(CONFIG_KEYWORD_PROP_NAME).Value).Value;
            //if (String.IsNullOrWhiteSpace(configKeyword)) configKeyword = "DEFAULTS";

            IFeatureClass ret = null;

            if (featureClassName.FeatureDatasetName != null)
            {
                IFeatureDataset featureDataset = (IFeatureDataset)((IName)featureClassName.FeatureDatasetName).Open();
                try
                {
                    ret = featureDataset.CreateFeatureClass(name, output_fields, clsid, extclsid, esriFeatureType.esriFTSimple, shapeFieldName, configKeyword);
                }
                finally
                {
                    Marshal.ReleaseComObject(featureDataset);
                }
            }
            else
            {
                IWorkspace workspace = (IWorkspace)((IName)((IDatasetName)featureClassName).WorkspaceName).Open();
                try
                {
                    IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
                    ret = featureWorkspace.CreateFeatureClass(name, output_fields, clsid, extclsid, esriFeatureType.esriFTSimple, shapeFieldName, configKeyword);
                }
                finally
                {
                    Marshal.ReleaseComObject(workspace);
                }
            }
            return(ret);
        }
示例#22
0
        public bool CreateFeatureClassUnderDS(string FCName, string DSName, bool IncludeFeature, bool CreateDS, string TempDBID, bool AddFID)
        {
            IFeatureWorkspace pDesFeatureWorkspace = this._Workspace as IFeatureWorkspace;
            IFeatureClass     pDesFeatureClass     = null;

            if (pDesFeatureWorkspace == null)
            {
                return(false);
            }

            IFeatureWorkspace pSourFeatureWorkspace = this._TempleteWorkspace as IFeatureWorkspace;

            if (pSourFeatureWorkspace == null)
            {
                return(false);
            }

            IFeatureDataset pDesFeatureDataset = null;
            IFeatureDataset pSrcFeatureDataset = null;

            if (CreateDS)
            {
                //创建数据集

                pSrcFeatureDataset = pSourFeatureWorkspace.OpenFeatureDataset(DSName);
                IGeoDataset pGeoDataset = pSrcFeatureDataset as IGeoDataset;
                pDesFeatureDataset = pDesFeatureWorkspace.CreateFeatureDataset(DSName + TempDBID, pGeoDataset.SpatialReference);
            }
            else
            {
                pDesFeatureDataset = pDesFeatureWorkspace.OpenFeatureDataset(DSName + TempDBID);
            }

            #region 创建目标图层
            //获取源要素类
            IFeatureClass pSourFeatureClass = pSourFeatureWorkspace.OpenFeatureClass(FCName);
            if (pSourFeatureClass == null)
            {
                return(false);
            }

            //获取源要素类后判断要素类的类型

            if (pSourFeatureClass.FeatureType == esriFeatureType.esriFTAnnotation)   //如果是注记层
            {
                IFeatureWorkspaceAnno pFWSAnno   = pDesFeatureWorkspace as IFeatureWorkspaceAnno;
                IAnnoClass            pAnnoClass = pSourFeatureClass.Extension as IAnnoClass;
                IGraphicsLayerScale   pGLS       = new GraphicsLayerScaleClass();
                pGLS.ReferenceScale = pAnnoClass.ReferenceScale;
                pGLS.Units          = pAnnoClass.ReferenceScaleUnits;

                ///添加特殊字段
                ///
                IField     pField     = new FieldClass();
                IFieldEdit pFieldEdit = pField as IFieldEdit;

                pFieldEdit.Editable_2 = true;
                pFieldEdit.Name_2     = "GOFID";
                pFieldEdit.Type_2     = esriFieldType.esriFieldTypeInteger;



                IField     pField2     = new FieldClass();
                IFieldEdit pFieldEdit2 = pField2 as IFieldEdit;

                pFieldEdit2.Editable_2 = true;
                pFieldEdit2.Name_2     = "pro_id"; //项目ID
                pFieldEdit2.Type_2     = esriFieldType.esriFieldTypeInteger;

                IFields pFields = pSourFeatureClass.Fields;

                if (AddFID)
                {
                    IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
                    pFieldsEdit.AddField(pField);
                    pFieldsEdit.AddField(pField2);
                    pDesFeatureClass = pFWSAnno.CreateAnnotationClass(FCName + TempDBID, pFields, pSourFeatureClass.CLSID, pSourFeatureClass.EXTCLSID, pSourFeatureClass.ShapeFieldName, "", pDesFeatureDataset, null, pAnnoClass.AnnoProperties, pGLS, pAnnoClass.SymbolCollection, true);
                    pFieldsEdit.DeleteField(pField);
                    pFieldsEdit.DeleteField(pField2);
                }
                else
                {
                    pDesFeatureClass = pFWSAnno.CreateAnnotationClass(FCName + TempDBID, pFields, pSourFeatureClass.CLSID, pSourFeatureClass.EXTCLSID, pSourFeatureClass.ShapeFieldName, "", pDesFeatureDataset, null, pAnnoClass.AnnoProperties, pGLS, pAnnoClass.SymbolCollection, true);
                }
            }
            else    //如果是普通要素类
            {
                ///添加特殊字段
                ///
                IField     pField     = new FieldClass();
                IFieldEdit pFieldEdit = pField as IFieldEdit;

                pFieldEdit.Editable_2 = true;
                pFieldEdit.Name_2     = "GOFID";
                pFieldEdit.Type_2     = esriFieldType.esriFieldTypeInteger;


                IField     pField2     = new FieldClass();
                IFieldEdit pFieldEdit2 = pField2 as IFieldEdit;

                pFieldEdit2.Editable_2 = true;
                pFieldEdit2.Name_2     = "pro_id"; //项目ID
                pFieldEdit2.Type_2     = esriFieldType.esriFieldTypeInteger;

                IFields pFields = pSourFeatureClass.Fields;

                if (AddFID)
                {
                    IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
                    pFieldsEdit.AddField(pField);
                    pFieldsEdit.AddField(pField2);
                    pDesFeatureClass = pDesFeatureDataset.CreateFeatureClass(FCName + TempDBID, pFields, pSourFeatureClass.CLSID, pSourFeatureClass.EXTCLSID, pSourFeatureClass.FeatureType, pSourFeatureClass.ShapeFieldName, "");
                    pFieldsEdit.DeleteField(pField);
                    pFieldsEdit.DeleteField(pField2);
                }
                else
                {
                    pDesFeatureClass = pDesFeatureDataset.CreateFeatureClass(FCName + TempDBID, pFields, pSourFeatureClass.CLSID, pSourFeatureClass.EXTCLSID, pSourFeatureClass.FeatureType, pSourFeatureClass.ShapeFieldName, "");
                }
            }

            #endregion

            if (pDesFeatureClass == null)
            {
                return(false);
            }

            //导入要素
            if (IncludeFeature)  //如果需要复制要素
            {
                Exception eError = null;

                Dictionary <string, string> pDic = new Dictionary <string, string>();
                IFeatureCursor pFeatureCursor    = pSourFeatureClass.Search(null, false);

                IFields pFields = pSourFeatureClass.Fields;

                for (int i = 0; i < pFields.FieldCount; i++)
                {
                    IField pField = pFields.get_Field(i);
                    if (pField.Editable)
                    {
                        pDic.Add(pField.Name, pField.Name);
                    }
                }

                SysCommon.Gis.SysGisDataSet pSysGisDataSet = new SysCommon.Gis.SysGisDataSet();
                pSysGisDataSet.WorkSpace = this._Workspace;

                pSysGisDataSet.NewFeatures(FCName, pFeatureCursor, pDic, null, true, true, out eError);

                //释放cursor
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor);
            }
            return(true);
        }
示例#23
0
        ///<summary>Simple helper to create a featureclass in a geodatabase.</summary>
        /// 
        ///<param name="workspace">An IWorkspace2 interface</param>
        ///<param name="featureDataset">An IFeatureDataset interface or Nothing</param>
        ///<param name="featureClassName">A System.String that contains the name of the feature class to open or create. Example: "states"</param>
        ///<param name="fields">An IFields interface</param>
        ///<param name="clsid">A UID value or Nothing. Example "esriGeoDatabase.Feature" or Nothing</param>
        ///<param name="clsext">A UID value or Nothing (this is the class extension if you want to reference a class extension when creating the feature class).</param>
        ///<param name="strConfigKeyword">An empty System.String or RDBMS table string for ArcSDE. Example: "myTable" or ""</param>
        ///  
        ///<returns>An IFeatureClass interface or a Nothing</returns>
        ///  
        ///<remarks>
        ///  (1) If a 'featureClassName' already exists in the workspace a reference to that feature class 
        ///      object will be returned.
        ///  (2) If an IFeatureDataset is passed in for the 'featureDataset' argument the feature class
        ///      will be created in the dataset. If a Nothing is passed in for the 'featureDataset'
        ///      argument the feature class will be created in the workspace.
        ///  (3) When creating a feature class in a dataset the spatial reference is inherited 
        ///      from the dataset object.
        ///  (4) If an IFields interface is supplied for the 'fields' collection it will be used to create the
        ///      table. If a Nothing value is supplied for the 'fields' collection, a table will be created using 
        ///      default values in the method.
        ///  (5) The 'strConfigurationKeyword' parameter allows the application to control the physical layout 
        ///      for this table in the underlying RDBMSfor example, in the case of an Oracle database, the 
        ///      configuration keyword controls the tablespace in which the table is created, the initial and 
        ///     next extents, and other properties. The 'strConfigurationKeywords' for an ArcSDE instance are 
        ///      set up by the ArcSDE data administrator, the list of available keywords supported by a workspace 
        ///      may be obtained using the IWorkspaceConfiguration interface. For more information on configuration 
        ///      keywords, refer to the ArcSDE documentation. When not using an ArcSDE table use an empty 
        ///      string (ex: "").
        ///</remarks>
        internal IFeatureClass CreateFeatureClass(IWorkspace2 workspace, IFeatureDataset featureDataset,
                                                  string featureClassName,
                                                  IFields fields, ESRI.ArcGIS.esriSystem.UID clsid,
                                                  ESRI.ArcGIS.esriSystem.UID clsext, string strConfigKeyword)
        {
            if (string.IsNullOrEmpty(featureClassName))
                return null;

            IFeatureClass featureClass;
            var featureWorkspace = (IFeatureWorkspace)workspace; // Cast may throw exception

            if (workspace.NameExists[esriDatasetType.esriDTFeatureClass, featureClassName])
            //feature class with that name already exists
            {
                featureClass = featureWorkspace.OpenFeatureClass(featureClassName);
                return featureClass;
            }

            // assign the class id value if not assigned
            if (clsid == null)
            {
                clsid = new ESRI.ArcGIS.esriSystem.UIDClass { Value = "esriGeoDatabase.Feature" };
                //Works for shapefiles as well
            }

            IObjectClassDescription objectClassDescription = new FeatureClassDescriptionClass();

            // if a fields collection is not passed in then supply our own
            if (fields == null)
            {
                // create the fields using the required fields method
                fields = objectClassDescription.RequiredFields;
                var fieldsEdit = (IFieldsEdit)fields; // Explicit Cast
                IField field = new FieldClass();

                // create a user defined text field
                var fieldEdit = (IFieldEdit)field; // Explicit Cast

                // setup field properties
                fieldEdit.Name_2 = "SampleField";
                fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                fieldEdit.IsNullable_2 = true;
                fieldEdit.AliasName_2 = "Sample Field Column";
                fieldEdit.DefaultValue_2 = "test";
                fieldEdit.Editable_2 = true;
                fieldEdit.Length_2 = 100;

                // add field to field collection
                fieldsEdit.AddField(field);
                fields = fieldsEdit;
            }

            string strShapeField = "";

            // locate the shape field
            for (int j = 0; j < fields.FieldCount; j++)
            {
                if (fields.Field[j].Type != esriFieldType.esriFieldTypeGeometry)
                    continue;
                strShapeField = fields.Field[j].Name;
                break;
            }

            // Use IFieldChecker to create a validated fields collection.
            IFieldChecker fieldChecker = new FieldCheckerClass();
            IEnumFieldError enumFieldError;
            IFields validatedFields;
            fieldChecker.ValidateWorkspace = (IWorkspace)workspace;
            fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

            // The enumFieldError enumerator can be inspected at this point to determine
            // which fields were modified during validation.

            // finally create and return the feature class
            featureClass = featureDataset == null
                               ? featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, clsid, clsext,
                                                                     esriFeatureType.esriFTSimple, strShapeField,
                                                                     strConfigKeyword)
                               : featureDataset.CreateFeatureClass(featureClassName, validatedFields, clsid, clsext,
                                                                   esriFeatureType.esriFTSimple, strShapeField,
                                                                   strConfigKeyword);
            return featureClass;
        }
示例#24
0
        /// <summary>
        /// Creates a Featureclass in workspace
        /// </summary>
        /// <param name="objectWorkspace">workspace where the featureclass will be created</param>
        /// <param name="name">the featureclass name</param>
        /// <param name="spatialReference">spatial reference of the new featureclass</param>
        /// <param name="featureType">the type of feature type created</param>
        /// <param name="geometryType">the geometry type of the shape field of the featureclass</param>
        /// <param name="fields">the IFields for the new featureclass</param>
        /// <param name="uidCLSID">GUID CLSID</param>
        /// <param name="uidCLSEXT">extension GUID</param>
        /// <param name="configWord">SDE configuration keyword</param>
        /// <returns>A reference to the new featureclass (IFeatureClass)</returns>
        public static IFeatureClass CreateFeatureClass(
            object objectWorkspace,
            string name,
            ISpatialReference spatialReference,
            esriFeatureType featureType,
            esriGeometryType geometryType,
            IFields fields,
            UID uidCLSID,
            UID uidCLSEXT,
            string configWord)
        {
            // Check for invalid parameters.
            if (objectWorkspace == null)
            {
                throw new Exception("[objectWorkspace] cannot be null");
            }

            if (!((objectWorkspace is IWorkspace) ||
                  (objectWorkspace is IFeatureDataset)))
            {
                throw new Exception("[objectWorkspace] must be IWorkspace or IFeatureDataset");
            }

            if (name.Equals(string.Empty))
            {
                throw new Exception("[name] cannot be empty");
            }

            if ((objectWorkspace is IWorkspace) && (spatialReference == null))
            {
                throw new Exception("[spatialReference] cannot be null for StandAlong FeatureClasses");
            }

            // Set ClassID (if Null)
            if (uidCLSID == null)
            {
                uidCLSID = new UIDClass();
                switch (featureType)
                {
                case esriFeatureType.esriFTSimple:
                    uidCLSID.Value = "{52353152-891A-11D0-BEC6-00805F7C4268}";
                    break;

                case esriFeatureType.esriFTSimpleJunction:
                    geometryType   = esriGeometryType.esriGeometryPoint;
                    uidCLSID.Value = "{CEE8D6B8-55FE-11D1-AE55-0000F80372B4}";
                    break;

                case esriFeatureType.esriFTComplexJunction:
                    uidCLSID.Value = "{DF9D71F4-DA32-11D1-AEBA-0000F80372B4}";
                    break;

                case esriFeatureType.esriFTSimpleEdge:
                    geometryType   = esriGeometryType.esriGeometryPolyline;
                    uidCLSID.Value = "{E7031C90-55FE-11D1-AE55-0000F80372B4}";
                    break;

                case esriFeatureType.esriFTComplexEdge:
                    geometryType   = esriGeometryType.esriGeometryPolyline;
                    uidCLSID.Value = "{A30E8A2A-C50B-11D1-AEA9-0000F80372B4}";
                    break;

                case esriFeatureType.esriFTAnnotation:
                    geometryType   = esriGeometryType.esriGeometryPolygon;
                    uidCLSID.Value = "{E3676993-C682-11D2-8A2A-006097AFF44E}";
                    break;

                case esriFeatureType.esriFTDimension:
                    geometryType   = esriGeometryType.esriGeometryPolygon;
                    uidCLSID.Value = "{496764FC-E0C9-11D3-80CE-00C04F601565}";
                    break;
                }
            }

            // Set uidCLSEXT (if Null)
            if (uidCLSEXT == null)
            {
                switch (featureType)
                {
                case esriFeatureType.esriFTAnnotation:
                    uidCLSEXT       = new UIDClass();
                    uidCLSEXT.Value = "{24429589-D711-11D2-9F41-00C04F6BC6A5}";
                    break;

                case esriFeatureType.esriFTDimension:
                    uidCLSEXT       = new UIDClass();
                    uidCLSEXT.Value = "{48F935E2-DA66-11D3-80CE-00C04F601565}";
                    break;
                }
            }

            // Add Fields
            if (fields == null)
            {
                // Create fields collection
                fields = new FieldsClass();
                IFieldsEdit fieldsEdit = (IFieldsEdit)fields;

                // Create the geometry field
                IGeometryDef     geometryDef     = new GeometryDefClass();
                IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;

                // Assign Geometry Definition
                geometryDefEdit.GeometryType_2 = geometryType;
                geometryDefEdit.GridCount_2    = 1;
                geometryDefEdit.set_GridSize(0, 0.5);
                geometryDefEdit.AvgNumPoints_2 = 2;
                geometryDefEdit.HasM_2         = false;
                geometryDefEdit.HasZ_2         = true;
                if (objectWorkspace is IWorkspace)
                {
                    // If this is a STANDALONE FeatureClass then add spatial reference.
                    geometryDefEdit.SpatialReference_2 = spatialReference;
                }

                // Create OID Field
                IField     fieldOID     = new FieldClass();
                IFieldEdit fieldEditOID = (IFieldEdit)fieldOID;
                fieldEditOID.Name_2      = "OBJECTID";
                fieldEditOID.AliasName_2 = "OBJECTID";
                fieldEditOID.Type_2      = esriFieldType.esriFieldTypeOID;
                fieldsEdit.AddField(fieldOID);

                // Create Geometry Field
                IField     fieldShape     = new FieldClass();
                IFieldEdit fieldEditShape = (IFieldEdit)fieldShape;
                fieldEditShape.Name_2        = "SHAPE";
                fieldEditShape.AliasName_2   = "SHAPE";
                fieldEditShape.Type_2        = esriFieldType.esriFieldTypeGeometry;
                fieldEditShape.GeometryDef_2 = geometryDef;
                fieldsEdit.AddField(fieldShape);
            }

            // Locate Shape Field
            string stringShapeFieldName = string.Empty;

            for (int i = 0; i <= fields.FieldCount - 1; i++)
            {
                if (fields.get_Field(i).Type == esriFieldType.esriFieldTypeGeometry)
                {
                    stringShapeFieldName = fields.get_Field(i).Name;
                    break;
                }
            }

            if (stringShapeFieldName == string.Empty)
            {
                throw new Exception("Cannot locate geometry field in FIELDS");
            }

            IFeatureClass featureClass = null;

            if (objectWorkspace is IWorkspace)
            {
                // Create a STANDALONE FeatureClass
                IWorkspace        workspace        = (IWorkspace)objectWorkspace;
                IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;

                featureClass = featureWorkspace.CreateFeatureClass(name, fields, uidCLSID, uidCLSEXT, featureType, stringShapeFieldName, configWord);
            }
            else if (objectWorkspace is IFeatureDataset)
            {
                IFeatureDataset featureDataset = (IFeatureDataset)objectWorkspace;
                featureClass = featureDataset.CreateFeatureClass(name, fields, uidCLSID, uidCLSEXT, featureType, stringShapeFieldName, configWord);
            }

            // Return FeatureClass
            return(featureClass);
        } // Creates a Featureclass in workspace
示例#25
0
        /// 创建要素类
        /// summary;
        /// param name="pObject";IWorkspace或者IFeatureDataset对象;
        /// param name="pName";要素类名称;
        /// param name="pSpatialReference";空间参考;
        /// param name="pFeatureType";要素类型;
        /// param name="pGeometryType";几何类型;
        /// param name="pFields";字段集;
        /// param name="pUidClsId";CLSID值;
        /// param name="pUidClsExt";EXTCLSID值;
        /// param name="pConfigWord";配置信息关键词;
        /// 返回IFeatureClass
        public IFeatureClass CreateFeatureClass(object pObject, string pName, ISpatialReference pSpatialReference,
                                                esriFeatureType pFeatureType,
                                                esriGeometryType pGeometryType, IFields pFields, UID pUidClsId, UID pUidClsExt, string pConfigWord)
        {
            #region 错误检测

            if (pObject == null)
            {
                throw new Exception("[pObject] 不能为空!");
            }
            if (!((pObject is IFeatureWorkspace) || (pObject is IFeatureDataset)))
            {
                throw (new Exception("[pObject] 必须为IFeatureWorkspace 或者 IFeatureDataset"));
            }
            if (pName.Length == 0)
            {
                throw (new Exception("[pName] 不能为空!"));
            }
            if ((pObject is IWorkspace) && (pSpatialReference == null))
            {
                throw (new Exception("[pSpatialReference] 不能为空(对于单独的要素类)"));
            }

            #endregion

            #region pUidClsID字段为空时

            if (pUidClsId == null)
            {
                pUidClsId = new UIDClass();
                switch (pFeatureType)
                {
                case (esriFeatureType.esriFTSimple):
                    if (pGeometryType == esriGeometryType.esriGeometryLine)
                    {
                        pGeometryType = esriGeometryType.esriGeometryPolyline;
                    }
                    pUidClsId.Value = "{52353152-891A-11D0-BEC6-00805F7C4268}";
                    break;

                case (esriFeatureType.esriFTSimpleJunction):
                    pGeometryType   = esriGeometryType.esriGeometryPoint;
                    pUidClsId.Value = "{CEE8D6B8-55FE-11D1-AE55-0000F80372B4}";
                    break;

                case (esriFeatureType.esriFTComplexJunction):
                    pUidClsId.Value = "{DF9D71F4-DA32-11D1-AEBA-0000F80372B4}";
                    break;

                case (esriFeatureType.esriFTSimpleEdge):
                    pGeometryType   = esriGeometryType.esriGeometryPolyline;
                    pUidClsId.Value = "{E7031C90-55FE-11D1-AE55-0000F80372B4}";
                    break;

                case (esriFeatureType.esriFTComplexEdge):
                    pGeometryType   = esriGeometryType.esriGeometryPolyline;
                    pUidClsId.Value = "{A30E8A2A-C50B-11D1-AEA9-0000F80372B4}";
                    break;

                case (esriFeatureType.esriFTAnnotation):
                    pGeometryType   = esriGeometryType.esriGeometryPolygon;
                    pUidClsId.Value = "{E3676993-C682-11D2-8A2A-006097AFF44E}";
                    break;

                case (esriFeatureType.esriFTDimension):
                    pGeometryType   = esriGeometryType.esriGeometryPolygon;
                    pUidClsId.Value = "{496764FC-E0C9-11D3-80CE-00C04F601565}";
                    break;
                }
            }

            #endregion

            #region pUidClsExt字段为空时

            if (pUidClsExt == null)
            {
                switch (pFeatureType)
                {
                case esriFeatureType.esriFTAnnotation:
                    pUidClsExt       = new UIDClass();
                    pUidClsExt.Value = "{24429589-D711-11D2-9F41-00C04F6BC6A5}";
                    break;

                case esriFeatureType.esriFTDimension:
                    pUidClsExt       = new UIDClass();
                    pUidClsExt.Value = "{48F935E2-DA66-11D3-80CE-00C04F601565}";
                    break;
                }
            }

            #endregion

            #region 字段集合为空时

            if (pFields == null)
            {
                //实倒化字段集合对象
                pFields = new FieldsClass();
                IFieldsEdit tFieldsEdit = (IFieldsEdit)pFields;

                //创建几何对象字段定义
                IGeometryDef     tGeometryDef     = new GeometryDefClass();
                IGeometryDefEdit tGeometryDefEdit = tGeometryDef as IGeometryDefEdit;

                //指定几何对象字段属性值
                tGeometryDefEdit.GeometryType_2 = pGeometryType;
                tGeometryDefEdit.GridCount_2    = 1;
                tGeometryDefEdit.set_GridSize(0, 1000);
                if (pObject is IWorkspace)
                {
                    tGeometryDefEdit.SpatialReference_2 = pSpatialReference;
                }

                //创建OID字段
                IField     fieldOID     = new FieldClass();
                IFieldEdit fieldEditOID = fieldOID as IFieldEdit;
                fieldEditOID.Name_2      = "OBJECTID";
                fieldEditOID.AliasName_2 = "OBJECTID";
                fieldEditOID.Type_2      = esriFieldType.esriFieldTypeOID;
                tFieldsEdit.AddField(fieldOID);

                //创建几何字段
                IField     fieldShape     = new FieldClass();
                IFieldEdit fieldEditShape = fieldShape as IFieldEdit;
                fieldEditShape.Name_2        = "SHAPE";
                fieldEditShape.AliasName_2   = "SHAPE";
                fieldEditShape.Type_2        = esriFieldType.esriFieldTypeGeometry;
                fieldEditShape.GeometryDef_2 = tGeometryDef;
                tFieldsEdit.AddField(fieldShape);
            }

            #endregion

            //几何对象字段名称
            string strShapeFieldName = "";
            for (int i = 0; i < pFields.FieldCount; i++)
            {
                if (pFields.get_Field(i).Type == esriFieldType.esriFieldTypeGeometry)
                {
                    strShapeFieldName = pFields.get_Field(i).Name;
                    break;
                }
            }

            if (strShapeFieldName.Length == 0)
            {
                throw (new Exception("字段集中找不到几何对象定义"));
            }

            IFeatureClass tFeatureClass = null;
            if (pObject is IWorkspace)
            {
                //创建独立的FeatureClass
                IWorkspace        tWorkspace        = pObject as IWorkspace;
                IFeatureWorkspace tFeatureWorkspace = tWorkspace as IFeatureWorkspace;
                try
                {
                    tFeatureClass = tFeatureWorkspace.CreateFeatureClass(pName, pFields, pUidClsId, pUidClsExt, pFeatureType,
                                                                         strShapeFieldName, pConfigWord);
                }
                catch (Exception ex) {
                }
            }
            else if (pObject is IFeatureDataset)
            {
                //在要素集中创建FeatureClass
                IFeatureDataset tFeatureDataset = (IFeatureDataset)pObject;
                tFeatureClass = tFeatureDataset.CreateFeatureClass(pName, pFields, pUidClsId, pUidClsExt, pFeatureType,
                                                                   strShapeFieldName, pConfigWord);
            }

            return(tFeatureClass);
        }
示例#26
0
        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            // TODO: Add createMDB.OnClick implementation
            //设定相应格式
            SaveFileDialog dbfiledlg = new SaveFileDialog();

            dbfiledlg.Filter           = "空间数据库文件(*.mdb)|*.mdb";
            dbfiledlg.RestoreDirectory = true;
            //设置格式
            if (dbfiledlg.ShowDialog() == DialogResult.OK)
            {
                string localFilePath = dbfiledlg.FileName.ToString();
                string FilePath      = localFilePath.Substring(0, localFilePath.LastIndexOf("\\"));  //获得不带文件名的文件路径
                string fileNameExt   = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1); //获取文件名,不带路径

                //实例化一个数据库
                IWorkspaceFactory ipWSFactory = new AccessWorkspaceFactoryClass();
                IWorkspaceName    ipWsName    = ipWSFactory.Create(FilePath, fileNameExt, null, 0);
                //以name对象方式打开
                IName      name        = (IName)ipWsName;
                IWorkspace ipWorkspace = (IWorkspace)name.Open();
                //创建空间参考和要素集
                ISpatialReference ipSr     = m_hookHelper.FocusMap.SpatialReference;
                IFeatureDataset   ipFeatDs = ((IFeatureWorkspace)ipWorkspace).CreateFeatureDataset("dataset", ipSr);

                //设置相应字段和属性
                IFields ipFields = new FieldsClass();
                ((IFieldsEdit)ipFields).FieldCount_2 = 3;
                IFieldEdit ipField = new FieldClass();
                ((IFieldEdit)ipField).Name_2      = "ObjectID";
                ((IFieldEdit)ipField).AliasName_2 = "FID";
                ((IFieldEdit)ipField).Type_2      = esriFieldType.esriFieldTypeOID;
                ((IFieldsEdit)ipFields).set_Field(0, ipField);
                //Add others miscellaneous text field
                IFieldEdit ipField2 = new FieldClass();
                ((IFieldEdit)ipField2).Name_2      = "SmallInteger";
                ((IFieldEdit)ipField2).AliasName_2 = "short";
                ((IFieldEdit)ipField2).Type_2      = esriFieldType.esriFieldTypeSmallInteger;
                ((IFieldsEdit)ipFields).set_Field(1, ipField2);
                //Make the shape field
                //it will need a geometry definition, with a spatial reference

                IGeometryDefEdit ipGeoDef = new GeometryDefClass();
                ipGeoDef.SpatialReference_2 = ipSr;
                ipGeoDef.GeometryType_2     = esriGeometryType.esriGeometryPoint;
                IFieldEdit ipField3 = new FieldClass();
                ((IFieldEdit)ipField3).Name_2        = "Point";
                ((IFieldEdit)ipField3).AliasName_2   = "point";
                ((IFieldEdit)ipField3).Type_2        = esriFieldType.esriFieldTypeGeometry;
                ((IFieldEdit)ipField3).GeometryDef_2 = ipGeoDef;
                ((IFieldsEdit)ipFields).set_Field(2, ipField3);

                IFeatureClass ipFeatCls = ipFeatDs.CreateFeatureClass("point", ipFields, null, null,
                                                                      esriFeatureType.esriFTSimple, "point", "");
                IFeatureLayer ipFeatLyr = new FeatureLayerClass();
                ipFeatLyr.Name         = "New Point FeatureCls";
                ipFeatLyr.FeatureClass = ipFeatCls;
                m_hookHelper.FocusMap.AddLayer(ipFeatLyr);

                IGeometryDefEdit ipGeoDef1 = new GeometryDefClass();
                ipGeoDef1.SpatialReference_2 = ipSr;
                ipGeoDef1.GeometryType_2     = esriGeometryType.esriGeometryPolygon;
                IFieldEdit ipField4 = new FieldClass();
                ((IFieldEdit)ipField4).Name_2        = "Polygon";
                ((IFieldEdit)ipField4).AliasName_2   = "polygon";
                ((IFieldEdit)ipField4).Type_2        = esriFieldType.esriFieldTypeGeometry;
                ((IFieldEdit)ipField4).GeometryDef_2 = ipGeoDef1;
                ((IFieldsEdit)ipFields).set_Field(2, ipField4);

                IFeatureClass ipFeatCls1 = ipFeatDs.CreateFeatureClass("polygon", ipFields, null, null, esriFeatureType.esriFTSimple, "Polygon", "");
                IFeatureLayer ipFeatLyr1 = new FeatureLayerClass();
                ipFeatLyr1.Name         = "New Polygon FeatureCls";
                ipFeatLyr1.FeatureClass = ipFeatCls1;
                m_hookHelper.FocusMap.AddLayer(ipFeatLyr1);

                //Make the polygon field

                IGeometryDefEdit ipGeoDef2 = new GeometryDefClass();
                ipGeoDef2.SpatialReference_2 = ipSr;
                ipGeoDef2.GeometryType_2     = esriGeometryType.esriGeometryPolyline;
                IFieldEdit ipField5 = new FieldClass();
                ((IFieldEdit)ipField5).Name_2        = "Line";
                ((IFieldEdit)ipField5).AliasName_2   = "line";
                ((IFieldEdit)ipField5).Type_2        = esriFieldType.esriFieldTypeGeometry;
                ((IFieldEdit)ipField5).GeometryDef_2 = ipGeoDef2;
                ((IFieldsEdit)ipFields).set_Field(2, ipField5);

                IFeatureClass ipFeatCls2 = ipFeatDs.CreateFeatureClass("line", ipFields, null, null, esriFeatureType.esriFTSimple, "Line", "");
                IFeatureLayer ipFeatLyr2 = new FeatureLayerClass();
                ipFeatLyr2.Name         = "New Line FeatureCls";
                ipFeatLyr2.FeatureClass = ipFeatCls2;
                m_hookHelper.FocusMap.AddLayer(ipFeatLyr2);
            }
        }
示例#27
0
        public static IFeatureClass CreateFeatureClass(IWorkspace workspace, IFeatureDataset featureDataset, String featureClassName, IFields fields)
        {
            IFeatureClass featureClass;
            String strShapeField = "";
            var featureWorkspace = workspace as IFeatureWorkspace;
            IObjectClassDescription objectClassDescription = new FeatureClassDescriptionClass();

            #region 简单校验
            if (featureClassName == "") return null;
            //if (workspace.get_NameExists(esriDatasetType.esriDTFeatureClass, featureClassName))
            //{
            //    featureClass = featureWorkspace.OpenFeatureClass(featureClassName);
            //    return featureClass;
            //}

            if (fields == null)
            {
                fields = objectClassDescription.RequiredFields;
                IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
                IField field = new FieldClass();
                IFieldEdit fieldEdit = (IFieldEdit)field;
                fieldEdit.Name_2 = "Name";
                fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                fieldsEdit.AddField(field);
                fields = (IFields)fieldsEdit;
            }

            var feaClsDes = objectClassDescription as IFeatureClassDescription;
            strShapeField = feaClsDes.ShapeFieldName;
            #endregion

            //查询几何字段
            if (strShapeField == "")
            {
                for (int j = 0; j < fields.FieldCount; j++)
                {
                    if (fields.get_Field(j).Type == esriFieldType.esriFieldTypeGeometry)
                    {
                        strShapeField = fields.get_Field(j).Name;
                    }
                }
            }

            // 字段检查
            IFieldChecker fieldChecker = new FieldCheckerClass();
            IEnumFieldError enumFieldError = null;
            IFields validatedFields = null;
            fieldChecker.ValidateWorkspace = (IWorkspace)workspace;
            fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

            //创建要素类
            if (featureDataset == null)
            {
                featureClass = featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, objectClassDescription.InstanceCLSID, objectClassDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, strShapeField, "");
            }
            else
            {
                featureClass = featureDataset.CreateFeatureClass(featureClassName, validatedFields, objectClassDescription.InstanceCLSID, objectClassDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, strShapeField, "");
            }
            return featureClass;
        }
示例#28
0
        private IFeatureClass CreateFeatureClass(IFeatureDataset featureDataset,TableStructureNode tableStructureNode, FeatureCodeNode featureCodeNode) 
        {
            try
            {
                if (featureDataset != null)
                {
                    IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass();
                    IObjectClassDescription ocDesc = (IObjectClassDescription)fcDesc;
         
                    ///创建数据表字段
                    IFieldChecker fieldChecker = new FieldCheckerClass();
                    IEnumFieldError enumFieldError = null;
                    IFields validatedFields = CreateFileds(tableStructureNode, featureCodeNode);
                    ///字段信息验证
                    IFields fixFields = null;
                    fieldChecker.ValidateWorkspace = featureDataset.Workspace;
                    fieldChecker.Validate(validatedFields, out enumFieldError, out fixFields);

                    ////创建FeatureClass
                    IFeatureClass featureClass = null;
                    if (tableStructureNode.IsGeometryTable)
                    {
                        ////创建非注记FeatureClass
                        if (featureCodeNode.GeometryType != "")
                        {
                            featureClass = featureDataset.CreateFeatureClass(featureCodeNode.TableName,
                               fixFields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID,
                               esriFeatureType.esriFTSimple, fcDesc.ShapeFieldName, "");
                        }
                        else
                        {
                            ///创建注记
                            IFormattedTextSymbol pTxtSymbo=new TextSymbolClass();

                            IFeatureWorkspaceAnno pFeatureWorkspaceAnno = this.m_pIDataset.Workspace as IFeatureWorkspaceAnno;

                            IGraphicsLayerScale pGraphSacle = new GraphicsLayerScaleClass();
                            pGraphSacle.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriFeet;
                            //pGraphSacle.ReferenceScale=1000;


                            ISymbolCollection pSymbolCollection = new SymbolCollectionClass();

                            IAnnotateLayerProperties pAnnoLayerProp = new LabelEngineLayerPropertiesClass();
                            pAnnoLayerProp.FeatureLinked = true;
                            pAnnoLayerProp.CreateUnplacedElements = false;
                            pAnnoLayerProp.DisplayAnnotation = true;
                            pAnnoLayerProp.UseOutput = true;

                            IAnnotationExpressionEngine pAnnoExpressionEngine =new AnnotationVBScriptEngineClass();
                            ILabelEngineLayerProperties pLabelEngineLayerProperties = pAnnoLayerProp as ILabelEngineLayerProperties;
                            pLabelEngineLayerProperties.ExpressionParser = pAnnoExpressionEngine;
                            pLabelEngineLayerProperties.Expression = "[DESCRIPTION]";
                            pLabelEngineLayerProperties.IsExpressionSimple = true;
                            pLabelEngineLayerProperties.Offset = 0;
                            pLabelEngineLayerProperties.SymbolID = 0;
                            pLabelEngineLayerProperties.Symbol = pTxtSymbo;

                            IAnnotateLayerTransformationProperties pAnnoLayerTransProp = pAnnoLayerProp as IAnnotateLayerTransformationProperties;
                            pAnnoLayerTransProp.ReferenceScale=200;
                            pAnnoLayerTransProp.Units= ESRI.ArcGIS.esriSystem.esriUnits.esriFeet;
                            pAnnoLayerTransProp.ScaleRatio=1;

                            IAnnotateLayerPropertiesCollection pAnnoLayerProptyCollection =new AnnotateLayerPropertiesCollectionClass();
                           pAnnoLayerProptyCollection.Add(pAnnoLayerProp);

                           featureClass= pFeatureWorkspaceAnno.CreateAnnotationClass(featureCodeNode.TableName,fixFields,ocDesc.InstanceCLSID
                               ,ocDesc.ClassExtensionCLSID,fcDesc.ShapeFieldName,"",featureDataset,null,
                               pAnnoLayerProptyCollection, pGraphSacle, pSymbolCollection,true);
                        }
                    }
                    else
                    {
                        ///创建非空间数据
                    }
                    return featureClass;
                }
                return null;
            }
            catch(Exception ex)
            {
                Logger.WriteErrorLog(ex);
                return null;
            }
        }
示例#29
0
        public IFeatureClass CreateFeatureClass(IWorkspace workspace, IFeatureDataset featureDataset = null, ISpatialReference spatialReference = null)
        {
            try
            {
                _fieldMappingInts = new Dictionary <int, int>();
                IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace;
                if (featureWorkspace == null)
                {
                    return(null);
                }
                IFeatureClassDescription featureClassDescription = new FeatureClassDescriptionClass();
                IObjectClassDescription  objectClassDescription  = featureClassDescription as IObjectClassDescription;
                IFields     requiredFields     = objectClassDescription.RequiredFields;
                IFieldsEdit requiredFieldsEdit = requiredFields as IFieldsEdit;
                for (int i = 0; i < requiredFields.FieldCount; i++)
                {
                    if (requiredFieldsEdit.Field[i].Type == esriFieldType.esriFieldTypeGeometry)
                    {
                        IFieldEdit       requiredFieldEdit = requiredFieldsEdit.Field[i] as IFieldEdit;
                        IGeometryDef     geometryDef       = new GeometryDefClass();
                        IGeometryDefEdit geometryDefEdit   = geometryDef as IGeometryDefEdit;
                        geometryDefEdit.GeometryType_2     = _featureLayer.FeatureClass.ShapeType;
                        geometryDefEdit.SpatialReference_2 = spatialReference ?? FeatureClassUtil.GetGeometryDef(_featureLayer.FeatureClass).SpatialReference;
                        requiredFieldEdit.GeometryDef_2    = geometryDefEdit;
                    }
                }
                for (int i = 0; i < _selectedFieldList.Count; i++)
                {
                    IField field = _selectedFieldList[i];
                    if (requiredFieldsEdit.FindField(field.Name) >= 0)
                    {
                        continue;
                    }
                    IField     newField     = new FieldClass();
                    IFieldEdit newFieldEdit = newField as IFieldEdit;
                    newFieldEdit.Name_2         = field.Name;
                    newFieldEdit.AliasName_2    = field.AliasName;
                    newFieldEdit.DefaultValue_2 = field.DefaultValue;
                    newFieldEdit.Domain_2       = field.Domain;
                    newFieldEdit.DomainFixed_2  = field.DomainFixed;
                    newFieldEdit.Editable_2     = field.Editable;
                    newFieldEdit.IsNullable_2   = field.IsNullable;
                    newFieldEdit.Length_2       = field.Length;
                    newFieldEdit.Precision_2    = field.Precision;
                    newFieldEdit.Required_2     = field.Required;
                    newFieldEdit.Scale_2        = field.Scale;
                    newFieldEdit.Type_2         = field.Type;
                    requiredFieldsEdit.AddField(newFieldEdit);
                }

                IFieldChecker   fieldChecker    = new FieldCheckerClass();
                IEnumFieldError enumFieldError  = null;
                IFields         validatedFields = null;
                fieldChecker.ValidateWorkspace = workspace;
                fieldChecker.Validate(requiredFields, out enumFieldError, out validatedFields);
                string        esriName     = ((IDataset)_featureLayer.FeatureClass).Name;
                IFeatureClass featureClass = null;
                if (featureDataset == null)
                {
                    featureClass = featureWorkspace.CreateFeatureClass(esriName, requiredFields, objectClassDescription.InstanceCLSID,
                                                                       objectClassDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple,
                                                                       _featureLayer.FeatureClass.ShapeFieldName, "");
                }
                else
                {
                    featureClass = featureDataset.CreateFeatureClass(esriName, requiredFields, objectClassDescription.InstanceCLSID,
                                                                     objectClassDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple,
                                                                     _featureLayer.FeatureClass.ShapeFieldName, "");
                }

                foreach (IField field in _selectedFieldList)
                {
                    if (field.Editable)
                    {
                        _fieldMappingInts.Add(featureClass.FindField(field.Name), _featureLayer.FeatureClass.FindField(field.Name));
                    }
                }

                return(featureClass);
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message);
            }
        }
示例#30
0
        private IFeatureClass CreateFeatureClass(IFeatureDataset featureDataset,TableStructureNode tableStructureNode, FeatureCodeNode featureCodeNode)
        {
            try
            {
                if (featureDataset != null)
                {
                    IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass();
                    IObjectClassDescription ocDesc = (IObjectClassDescription)fcDesc;

                    ///�������ݱ��ֶ�
                    IFieldChecker fieldChecker = new FieldCheckerClass();
                    IEnumFieldError enumFieldError = null;
                    IFields validatedFields = CreateFileds(tableStructureNode, featureCodeNode);
                    ///�ֶ���Ϣ��֤
                    IFields fixFields = null;
                    fieldChecker.ValidateWorkspace = featureDataset.Workspace;
                    fieldChecker.Validate(validatedFields, out enumFieldError, out fixFields);

                    ////����FeatureClass
                    IFeatureClass featureClass = null;
                    if (tableStructureNode.IsGeometryTable)
                    {
                        ////������ע��FeatureClass
                        if (featureCodeNode.GeometryType != "")
                        {
                            featureClass = featureDataset.CreateFeatureClass(featureCodeNode.TableName,
                               fixFields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID,
                               esriFeatureType.esriFTSimple, fcDesc.ShapeFieldName, "");
                        }
                        else
                        {
                            ///����ע��
                            IFormattedTextSymbol pTxtSymbo=new TextSymbolClass();

                            IFeatureWorkspaceAnno pFeatureWorkspaceAnno = this.m_pIDataset.Workspace as IFeatureWorkspaceAnno;

                            IGraphicsLayerScale pGraphSacle = new GraphicsLayerScaleClass();
                            pGraphSacle.Units = ESRI.ArcGIS.esriSystem.esriUnits.esriFeet;
                            //pGraphSacle.ReferenceScale=1000;

                            ISymbolCollection pSymbolCollection = new SymbolCollectionClass();

                            IAnnotateLayerProperties pAnnoLayerProp = new LabelEngineLayerPropertiesClass();
                            pAnnoLayerProp.FeatureLinked = true;
                            pAnnoLayerProp.CreateUnplacedElements = false;
                            pAnnoLayerProp.DisplayAnnotation = true;
                            pAnnoLayerProp.UseOutput = true;

                            IAnnotationExpressionEngine pAnnoExpressionEngine =new AnnotationVBScriptEngineClass();
                            ILabelEngineLayerProperties pLabelEngineLayerProperties = pAnnoLayerProp as ILabelEngineLayerProperties;
                            pLabelEngineLayerProperties.ExpressionParser = pAnnoExpressionEngine;
                            pLabelEngineLayerProperties.Expression = "[DESCRIPTION]";
                            pLabelEngineLayerProperties.IsExpressionSimple = true;
                            pLabelEngineLayerProperties.Offset = 0;
                            pLabelEngineLayerProperties.SymbolID = 0;
                            pLabelEngineLayerProperties.Symbol = pTxtSymbo;

                            IAnnotateLayerTransformationProperties pAnnoLayerTransProp = pAnnoLayerProp as IAnnotateLayerTransformationProperties;
                            pAnnoLayerTransProp.ReferenceScale=200;
                            pAnnoLayerTransProp.Units= ESRI.ArcGIS.esriSystem.esriUnits.esriFeet;
                            pAnnoLayerTransProp.ScaleRatio=1;

                            IAnnotateLayerPropertiesCollection pAnnoLayerProptyCollection =new AnnotateLayerPropertiesCollectionClass();
                           pAnnoLayerProptyCollection.Add(pAnnoLayerProp);

                           featureClass= pFeatureWorkspaceAnno.CreateAnnotationClass(featureCodeNode.TableName,fixFields,ocDesc.InstanceCLSID
                               ,ocDesc.ClassExtensionCLSID,fcDesc.ShapeFieldName,"",featureDataset,null,
                               pAnnoLayerProptyCollection, pGraphSacle, pSymbolCollection,true);
                        }
                    }
                    else
                    {
                        ///�����ǿռ�����
                    }
                    return featureClass;
                }
                return null;
            }
            catch(Exception ex)
            {
                LogAPI.WriteErrorLog(ex);
                return null;
            }
        }
示例#31
0
        public static IFeatureClass CreateFeatureClassInPGDB(IWorkspace2 workspace, IFeatureDataset featureDataset, string featureClassName, IFields fields, UID CLSID, UID CLSEXT, string strConfigKeyword, esriGeometryType esriGeometryType)
        {
            if (featureClassName == "") return null; // name was not passed in
            ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass;
            ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast
            if (workspace.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass, featureClassName)) //feature class with that name already exists
            {

                featureClass = featureWorkspace.OpenFeatureClass(featureClassName);
                return featureClass;
            }

            // assign the class id value if not assigned

            if (CLSID == null)
            {
                CLSID = new ESRI.ArcGIS.esriSystem.UIDClass();
                CLSID.Value = "esriGeoDatabase.Feature";
            }

            ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.FeatureClassDescriptionClass();

            // if a fields collection is not passed in then supply our own

            if (fields == null)
            {

                // create the fields using the required fields method

                fields = objectClassDescription.RequiredFields;

                ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields; // Explicit Cast
                ESRI.ArcGIS.Geodatabase.IField field = new ESRI.ArcGIS.Geodatabase.FieldClass();

                // create a user defined text field
                ESRI.ArcGIS.Geodatabase.IFieldEdit fieldEdit = (ESRI.ArcGIS.Geodatabase.IFieldEdit)field; // Explicit Cast

                // setup field properties
                fieldEdit.Name_2 = "SampleField";
                fieldEdit.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString;
                fieldEdit.IsNullable_2 = true;
                fieldEdit.AliasName_2 = "Sample Field Column";
                fieldEdit.DefaultValue_2 = "test";
                fieldEdit.Editable_2 = true;
                fieldEdit.Length_2 = 100;

                // add field to field collection
                fieldsEdit.AddField(field);
                fields = (ESRI.ArcGIS.Geodatabase.IFields)fieldsEdit; // Explicit Cast
            }

            System.String strShapeField = "";

            // locate the shape field
            for (int j = 0; j < fields.FieldCount; j++)
            {
                if (fields.get_Field(j).Type == esriFieldType.esriFieldTypeGeometry)
                {
                    strShapeField = fields.get_Field(j).Name;
                    ((IGeometryDefEdit)fields.get_Field(j).GeometryDef).GeometryType_2 = esriGeometryType;
                }
            }

            // Use IFieldChecker to create a validated fields collection.
            ESRI.ArcGIS.Geodatabase.IFieldChecker fieldChecker = new ESRI.ArcGIS.Geodatabase.FieldCheckerClass();
            ESRI.ArcGIS.Geodatabase.IEnumFieldError enumFieldError = null;
            ESRI.ArcGIS.Geodatabase.IFields validatedFields = null;
            fieldChecker.ValidateWorkspace = (ESRI.ArcGIS.Geodatabase.IWorkspace)workspace;
            fieldChecker.Validate(fields, out enumFieldError, out validatedFields);
            // The enumFieldError enumerator can be inspected at this point to determine
            // which fields were modified during validation.

            // finally create and return the feature class

            if (featureDataset == null)// if no feature dataset passed in, create at the workspace level
            {
                featureClass = featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword);
            }
            else
            {
                featureClass = featureDataset.CreateFeatureClass(featureClassName, validatedFields, CLSID, CLSEXT, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, strShapeField, strConfigKeyword);
            }
            return featureClass;
        }
示例#32
0
        private IFeatureClass method_1()
        {
            IFeatureClass class2 = null;

            if (this.iname_0 == null)
            {
                return(null);
            }
            object          obj2      = this.iname_0.Open();
            IWorkspace      workspace = null;
            IFeatureDataset dataset   = null;

            if (obj2 is IWorkspace)
            {
                workspace = obj2 as IWorkspace;
            }
            else if (obj2 is IFeatureDataset)
            {
                dataset   = obj2 as IFeatureDataset;
                workspace = dataset.Workspace;
            }
            IObjectClassDescription description = null;

            description = new FeatureClassDescriptionClass();
            IFieldsEdit requiredFields = description.RequiredFields as IFieldsEdit;
            IFieldEdit  field          = null;
            IFieldEdit  edit3          = null;
            int         index          = requiredFields.FindField((description as IFeatureClassDescription).ShapeFieldName);

            edit3 = requiredFields.get_Field(index) as IFieldEdit;
            IGeometryDefEdit geometryDef = edit3.GeometryDef as IGeometryDefEdit;

            if (this.cboGeometryType.SelectedIndex == 0)
            {
                geometryDef.GeometryType_2 = esriGeometryType.esriGeometryPoint;
            }
            else if (this.cboGeometryType.SelectedIndex == 1)
            {
                geometryDef.GeometryType_2 = esriGeometryType.esriGeometryMultipoint;
            }
            else if (this.cboGeometryType.SelectedIndex == 2)
            {
                geometryDef.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
            }
            else if (this.cboGeometryType.SelectedIndex == 3)
            {
                geometryDef.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
            }
            ISpatialReference spatialReference = geometryDef.SpatialReference;

            if (this.txtCoordinate.Tag is ISpatialReference)
            {
                spatialReference = this.txtCoordinate.Tag as ISpatialReference;
            }
            geometryDef.HasZ_2 = this.chkHasZ.Checked;
            geometryDef.HasM_2 = this.chkHasM.Checked;
            SpatialReferenctOperator.ChangeCoordinateSystem(workspace as IGeodatabaseRelease, spatialReference, false);
            geometryDef.SpatialReference_2 = spatialReference;
            esriFeatureType esriFTSimple = esriFeatureType.esriFTSimple;

            field             = new FieldClass();
            field.Name_2      = "Code";
            field.AliasName_2 = "要素编号";
            field.Type_2      = esriFieldType.esriFieldTypeInteger;
            requiredFields.AddField(field);
            string name = this.method_0(workspace, this.txtFeatureClassName.Text);

            try
            {
                if (dataset == null)
                {
                    class2 = (workspace as IFeatureWorkspace).CreateFeatureClass(name, requiredFields, null, null,
                                                                                 esriFTSimple, "Shape", "");
                }
                else
                {
                    class2 = dataset.CreateFeatureClass(name, requiredFields, null, null, esriFTSimple, "Shape", "");
                }
            }
            catch (Exception exception)
            {
                Logger.Current.Error("", exception, "");
            }
            return(class2);
        }
示例#33
0
        private void PRV_GetErrorFeature()
        {
            foreach (ITopologyRule IN_RuleType in LI_ITopologyRule)
            {
                int tempCount = 0;
                DicTopoError.Add(IN_RuleType.OriginSubtype.ToString(), tempCount);
                IEnvelope Temp_Envolope = (this.Topology as IGeoDataset).Extent;
                IErrorFeatureContainer Temp_ErrorContainer = Topology as IErrorFeatureContainer;
                //获取该种错误所有的错误要素
                IEnumTopologyErrorFeature Temp_EnumErrorFeature = Temp_ErrorContainer.get_ErrorFeatures(((IGeoDataset)FeatureDataset_Main).SpatialReference, IN_RuleType, Temp_Envolope, true, false);
                //提取一个错误要素
                ITopologyErrorFeature Temp_ErrorFeature = Temp_EnumErrorFeature.Next();
                if (Temp_ErrorFeature != null)
                {
                    //作为搭建模型的要素
                    IFeature Temp_MoudleFeature = Temp_ErrorFeature as IFeature;
                    //生成要素类需要CLSID和EXCLSID
                    IFeatureClassDescription Temp_FeatureClassDescription = new FeatureClassDescriptionClass();
                    IObjectClassDescription  Temp_ObjectClassDescription  = (IObjectClassDescription)Temp_FeatureClassDescription;
                    //以模型要素为模板构建一个要素类
                    //FeatureDataset_Main.CreateFeatureClass(TP_topoName, Temp_MoudleFeature.Fields, Temp_ObjectClassDescription.InstanceCLSID, Temp_ObjectClassDescription.ClassExtensionCLSID, Temp_MoudleFeature.FeatureType, "Shape", null);
                    //打开生成的目标要素类并加入集合留待输出时使用
                    IFeatureClass Temp_TargetFeatureClass;
                    string        ErrorFeatureName = TP_topoName + "_" + Temp_ErrorFeature.ShapeType.ToString();
                    try
                    {
                        Temp_TargetFeatureClass = (FeatureDataset_Main.Workspace as IFeatureWorkspace).OpenFeatureClass(ErrorFeatureName);
                    }
                    catch
                    {
                        FeatureDataset_Main.CreateFeatureClass(ErrorFeatureName, Temp_MoudleFeature.Fields, Temp_ObjectClassDescription.InstanceCLSID, Temp_ObjectClassDescription.ClassExtensionCLSID, Temp_MoudleFeature.FeatureType, "Shape", null);
                        Temp_TargetFeatureClass = (FeatureDataset_Main.Workspace as IFeatureWorkspace).OpenFeatureClass(ErrorFeatureName);
                    }
                    LI_TopoErrorFeatureClass.Add(Temp_TargetFeatureClass);
                    //将所有错误要素添加进目标要素类
                    IWorkspaceEdit Temp_WorkspaceEdit = (IWorkspaceEdit)FeatureDataset_Main.Workspace;
                    Temp_WorkspaceEdit.StartEditing(true);
                    Temp_WorkspaceEdit.StartEditOperation();
                    IFeatureBuffer Temp_FeatureBuffer = Temp_TargetFeatureClass.CreateFeatureBuffer();

                    //在目标要素类中插入所有错误要素
                    IFeatureCursor featureCursor = Temp_TargetFeatureClass.Insert(false);
                    while (Temp_ErrorFeature != null)
                    {
                        IFeature Temp_Feature = Temp_ErrorFeature as IFeature;
                        //给目标要素附属性
                        Temp_FeatureBuffer.set_Value(1, Temp_ErrorFeature.OriginClassID);
                        Temp_FeatureBuffer.set_Value(2, Temp_ErrorFeature.OriginOID);
                        Temp_FeatureBuffer.set_Value(3, Temp_ErrorFeature.DestinationClassID);
                        Temp_FeatureBuffer.set_Value(4, Temp_ErrorFeature.DestinationOID);
                        Temp_FeatureBuffer.set_Value(5, Temp_ErrorFeature.TopologyRuleType);
                        Temp_FeatureBuffer.set_Value(8, Temp_ErrorFeature.IsException);
                        Temp_FeatureBuffer.Shape = Temp_Feature.Shape;
                        if (this.DicTopoData.ContainsKey(IN_RuleType.OriginSubtype.ToString()))
                        {
                            if (IN_RuleType.Name == "面要素之间无空隙")
                            {
                                IArea pArea = (IArea)Temp_Feature.Shape.Envelope;
                                if (pArea.Area < System.Convert.ToDouble(this.DicTopoData[IN_RuleType.OriginSubtype.ToString()]))
                                {
                                    tempCount++;
                                    DicTopoError[IN_RuleType.OriginSubtype.ToString()] = tempCount;
                                    object featureOID = featureCursor.InsertFeature(Temp_FeatureBuffer);
                                    featureCursor.Flush();//保存要素
                                }
                            }
                        }
                        else
                        {
                            tempCount++;
                            DicTopoError[IN_RuleType.OriginSubtype.ToString()] = tempCount;
                            object featureOID = featureCursor.InsertFeature(Temp_FeatureBuffer);
                            featureCursor.Flush();//保存要素
                        }
                        Temp_ErrorFeature = Temp_EnumErrorFeature.Next();
                    }
                    Temp_WorkspaceEdit.StopEditOperation();
                    Temp_WorkspaceEdit.StopEditing(true);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);
                }
            }
        }
示例#34
0
        /// <summary>
        /// 以原工作空间为模板创建新的工作空间
        /// </summary>
        private void CreatWorkspaceFromOrig()
        {
            WaitForm.SetCaption("正在创建新的工作空间...请稍后");
            IFeatureClassContainer pFcContainer = null;
            IFeatureClass          pFcTemp      = null;
            IFeatureClass          pNewFc       = null;
            ISpatialReference      pSr          = null;
            ISpatialReference      pSrTemp      = null;
            IFields pflds = null;
            double  dblXmin, dblXmax, dblYmin, dblYmax;
            double  dblZmin, dblZmax, dblMmin, dblMmax;

            CreateWorkspaceDomains(m_pOrigWorkspace, m_pDestWorkspace);
            IFeatureWorkspace pFeaWorkspace = m_pDestWorkspace as IFeatureWorkspace;
            IEnumDataset      enumDs        = m_pOrigWorkspace.get_Datasets(esriDatasetType.esriDTAny);
            IDataset          pDs           = enumDs.Next();

            while (pDs != null)
            {
                if (pDs.Type == esriDatasetType.esriDTFeatureDataset)
                {
                    pSr     = new UnknownCoordinateSystemClass();
                    pSrTemp = (pDs as IGeoDataset).SpatialReference;
                    if (pSrTemp.HasXYPrecision())
                    {
                        pSrTemp.GetDomain(out dblXmin, out dblXmax, out dblYmin, out dblYmax);
                        pSr.SetDomain(dblXmin, dblXmax, dblYmin, dblYmax);
                    }
                    if (pSrTemp.HasZPrecision())
                    {
                        pSrTemp.GetZDomain(out dblZmin, out dblZmax);
                        pSr.SetZDomain(dblZmin, dblZmax);
                    }
                    if (pSrTemp.HasMPrecision())
                    {
                        pSrTemp.GetMDomain(out dblMmin, out dblMmax);
                        pSr.SetMDomain(dblMmin, dblMmax);
                    }
                    IFeatureDataset pFeaDs = pFeaWorkspace.CreateFeatureDataset(pDs.Name, pSr);
                    pFcContainer = (IFeatureClassContainer)pDs;
                    if (pFcContainer.ClassCount > 0)
                    {
                        for (int i = 0; i < pFcContainer.ClassCount; i++)
                        {
                            try
                            {
                                pFcTemp = pFcContainer.get_Class(i);
                                pflds   = CommonFunction.GetFieldsFormFeatureClass(pFcTemp);

                                //若为注记
                                if (pFcTemp.FeatureType == esriFeatureType.esriFTAnnotation)
                                {
                                    IFeatureWorkspaceAnno pFWSAno    = pFeaWorkspace as IFeatureWorkspaceAnno;
                                    IAnnoClass            pAnnoClass = pFcTemp.Extension as IAnnoClass;
                                    IGraphicsLayerScale   pGLS       = new GraphicsLayerScaleClass();
                                    pGLS.ReferenceScale = pAnnoClass.ReferenceScale;
                                    pGLS.Units          = pAnnoClass.ReferenceScaleUnits;


                                    pNewFc = pFWSAno.CreateAnnotationClass((pFcTemp as IDataset).Name,
                                                                           pflds, pFcTemp.CLSID, pFcTemp.EXTCLSID, pFcTemp.ShapeFieldName,
                                                                           "", pFeaDs, null, pAnnoClass.AnnoProperties, pGLS, pAnnoClass.SymbolCollection, true);
                                    (pNewFc as IClassSchemaEdit).AlterAliasName(pFcTemp.AliasName);
                                }
                                else//若为地理要素
                                {
                                    try
                                    {
                                        pNewFc = pFeaDs.CreateFeatureClass((pFcTemp as IDataset).Name,
                                                                           pflds, pFcTemp.CLSID, pFcTemp.EXTCLSID, pFcTemp.FeatureType, pFcTemp.ShapeFieldName, null);
                                        if (pFcTemp.AliasName == "图廓线")
                                        {
                                            int n = 0;
                                        }
                                        (pNewFc as IClassSchemaEdit).AlterAliasName(pFcTemp.AliasName);
                                    }
                                    catch (System.Exception ex)
                                    {
                                        System.Console.WriteLine(ex.Message);
                                    }
                                }
                            }
                            catch (System.Exception ex)
                            {
                                System.Console.WriteLine(ex.Message);
                            }
                        }
                    }
                }
                else if (pDs.Type == esriDatasetType.esriDTFeatureClass)
                {
                    pFcTemp = (IFeatureClass)pDs;
                    pflds   = CommonFunction.GetFieldsFormFeatureClass(pFcTemp, pSr);
                    try
                    {
                        pNewFc = pFeaWorkspace.CreateFeatureClass(pDs.Name,
                                                                  pflds,
                                                                  pFcTemp.CLSID,
                                                                  pFcTemp.EXTCLSID,
                                                                  pFcTemp.FeatureType,
                                                                  pFcTemp.ShapeFieldName,
                                                                  null);
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine(ex.Message);
                    }
                }
                else if (pDs.Type == esriDatasetType.esriDTTable)
                {
                    ITable pTable = (ITable)pDs;
                    try
                    {
                        ITable pNewTable = pFeaWorkspace.CreateTable(pDs.Name,
                                                                     pTable.Fields,
                                                                     pTable.CLSID,
                                                                     pTable.EXTCLSID,
                                                                     null);
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine(ex.Message);
                    }
                }
                pDs = enumDs.Next();
            }
        }
示例#35
0
 /// <summary>
 /// Creates a new feature class based on the MappableFeature type.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="featureDataset"></param>
 /// <param name="name"></param>
 /// <param name="geometryType"></param>
 /// <returns></returns>
 public static IFeatureClass CreateFeatureClass <T>(this IFeatureDataset featureDataset, string name, esriGeometryType geometryType) where T : MappableFeature
 {
     return(featureDataset.CreateFeatureClass <T>(name, geometryType, false));
 }