Esempio n. 1
0
        private void IndexSetCtrl_Load(object sender, EventArgs e)
        {
            int num;

            if ((this.ifeatureClass_0 as IDataset).Workspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace)
            {
                this.groupBox2.Visible = true;
            }
            else
            {
                this.groupBox2.Visible = false;
            }
            IIndexes indexes = this.ifeatureClass_0.Indexes;

            for (num = 0; num < indexes.IndexCount; num++)
            {
                IIndex index = indexes.get_Index(num);
                if (index.Fields.get_Field(0).Type != esriFieldType.esriFieldTypeGeometry)
                {
                    this.listBoxIndexName.Items.Add(new IndexWrap(index));
                }
            }
            int          num2        = this.ifeatureClass_0.FindField(this.ifeatureClass_0.ShapeFieldName);
            IGeometryDef geometryDef = this.ifeatureClass_0.Fields.get_Field(num2).GeometryDef;

            double[] numArray2 = new double[3];
            for (num = 0; num < geometryDef.GridCount; num++)
            {
                numArray2[num] = geometryDef.get_GridSize(num);
            }
            this.lblGridSize1.Text       = "Grid 1:" + numArray2[0].ToString("0.##");
            this.lblGridSize2.Text       = "Grid 2:" + numArray2[1].ToString("0.##");
            this.lblGridSize3.Text       = "Grid 3:" + numArray2[2].ToString("0.##");
            this.btnAddGridIndex.Enabled = geometryDef.GridCount == 0;
        }
Esempio n. 2
0
        private void InitGridSize()
        {
            if (m_pFeaCls == null)
            {
                return;
            }

            //获得igeometrydef
            string strShapeName = m_pFeaCls.ShapeFieldName;
            IField pShapeField  = m_pFeaCls.Fields.get_Field(m_pFeaCls.FindField(m_pFeaCls.ShapeFieldName));

            if (pShapeField == null)
            {
                return;
            }
            IGeometryDef pGeometryDef = pShapeField.GeometryDef as IGeometryDef;

            //获得索引信息
            int intGridCount = pGeometryDef.GridCount;

            for (int i = 0; i < pGeometryDef.GridCount; i++)
            {
                double dblGridSize = 0;
                dblGridSize = pGeometryDef.get_GridSize(i);

                switch (i)
                {
                case 0:
                    this.txtGridSize1.Text = dblGridSize.ToString();
                    break;

                case 1:
                    this.txtGridSize2.Text = dblGridSize.ToString();
                    break;

                case 2:
                    this.txtGridSize2.Text = dblGridSize.ToString();
                    break;
                }
            }
        }
        //** 功能描述: 通过一个字段集,创建另外一个字段集,直接添加传入的字段集中的所有字段的话
        //             会产生高版本和低版本不兼容的问题,

        public static IFields GetFieldsByFields(IFields pFields, ref ISpatialReference pDesSpatialReference, Dictionary <string, string> pDicField)
        {
            //pDesSpatialReference = null;
            //pDicField = null;

            int               i                    = 0;
            IField            pField               = default(IField);
            IFieldEdit        pFieldEdit           = default(IFieldEdit);
            IFieldsEdit       pFieldsEdit          = default(IFieldsEdit);
            IField            pCreateField         = default(IField);
            ISpatialReference pOriSpatialReference = default(ISpatialReference);

            IGeometryDef     pGeometryDef     = default(IGeometryDef);
            IGeometryDefEdit pGeometryDefEdit = default(IGeometryDefEdit);
            double           ymin             = 0;
            double           xmin             = 0;
            double           xmax             = 0;
            double           ymax             = 0;
            double           mMin             = 0;
            double           zmin             = 0;
            double           zmax             = 0;
            double           mMax             = 0;
            IEnvelope        pEnvelop         = default(IEnvelope);
            IGeometry        pGeometry        = default(IGeometry);
            IClone           pClone           = default(IClone);
            //标识该字段是否被添加
            bool bIsAddField = false;

            //应该把OID字段添加进去,否则会产生错误
            pFieldsEdit = new FieldsClass();

            for (i = 0; i <= pFields.FieldCount - 1; i++)
            {
                pField = pFields.get_Field(i);

                if (pField.Editable | pField.Type == esriFieldType.esriFieldTypeOID | pField.Type == esriFieldType.esriFieldTypeGlobalID | pField.Type == esriFieldType.esriFieldTypeGUID)
                {
                    pClone       = (IClone)pField;
                    pCreateField = (IField)pClone.Clone();

                    //如果更改字段名称:如果是OID字段的话,即便不在dic中也要进行添加
                    if ((pDicField != null))
                    {
                        if (pDicField.ContainsKey(Strings.Trim(pField.Name)))
                        {
                            bIsAddField = true;
                            //修改字段的名称
                            pFieldEdit        = (IFieldEdit)pCreateField;
                            pFieldEdit.Name_2 = pDicField[Strings.Trim(pField.Name)];

                            //需不需要把别名赋过去,根据需要再看吧,现在看的话应该不要赋过去,因此一般字段名和别名是一样的
                            //如果赋过去的话,显示的是原字段的别名,即不是用户想看到的字段名
                            //pFieldEdit.AliasName = pField.AliasName
                        }
                        else if (pField.Type == esriFieldType.esriFieldTypeOID | pField.Type == esriFieldType.esriFieldTypeGlobalID | pField.Type == esriFieldType.esriFieldTypeGUID)
                        {
                            bIsAddField = true;
                        }
                        else
                        {
                            bIsAddField = false;
                        }
                    }
                    else
                    {
                        bIsAddField = true;
                    }
                    if (pField.Type == esriFieldType.esriFieldTypeGeometry)
                    {
                        pGeometryDef     = pCreateField.GeometryDef;
                        pGeometryDefEdit = (IGeometryDefEdit)pGeometryDef;



                        if ((pDesSpatialReference != null))
                        {
                            pOriSpatialReference = pGeometryDef.SpatialReference;

                            //从原来的空间参考中得到domain
                            if (pOriSpatialReference.HasXYPrecision())
                            {
                                pOriSpatialReference.GetDomain(out xmin, out xmax, out ymin, out ymax);
                            }

                            pEnvelop = new EnvelopeClass();
                            pEnvelop.PutCoords(xmin, ymin, xmax, ymax);
                            pGeometry = pEnvelop;
                            pGeometry.SpatialReference = pOriSpatialReference;
                            pGeometry.Project(pDesSpatialReference);
                            xmax = pEnvelop.XMax;
                            xmin = pEnvelop.XMin;
                            ymax = pEnvelop.YMax;
                            ymin = pEnvelop.YMin;

                            pDesSpatialReference.SetDomain(xmin, xmax, ymin, ymax);

                            if (pOriSpatialReference.HasZPrecision())
                            {
                                pOriSpatialReference.GetZDomain(out zmin, out zmax);
                                pDesSpatialReference.SetZDomain(zmin, zmax);
                            }

                            if (pOriSpatialReference.HasMPrecision())
                            {
                                pOriSpatialReference.GetMDomain(out mMin, out mMax);
                                pDesSpatialReference.SetMDomain(mMin, mMax);
                            }

                            pGeometryDefEdit.SpatialReference_2 = pDesSpatialReference;
                        }
                        //修改grid的大小
                        if (pGeometryDef.GridCount != 0)
                        {
                            if (pGeometryDef.get_GridSize(0) < 100)
                            {
                                pGeometryDefEdit.set_GridSize(0, 100);
                            }
                        }
                        bIsAddField = true;
                    }

                    if (bIsAddField == true)
                    {
                        pFieldsEdit.AddField(pCreateField);
                        bIsAddField = false;
                    }
                }
            }
            return(pFieldsEdit);
        }
Esempio n. 4
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);
        }