Exemplo n.º 1
0
        /// <summary>
        /// 显示指定要素的属性
        /// </summary>
        /// <param name="identifiedFeature"></param>
        private void ShowFeatureAttributes(IFeature identifiedFeature)
        {
            if (identifiedFeature == null)
            {
                //初始化属性列表
                InitializeAttributesList();
                return;
            }
            //清空数据列表
            lstProperties.Items.Clear();
            lstProperties.Columns.Clear();
            //若查询数据不为空则显示数据
            //添加列头
            ColumnHeader fieldHeader = new ColumnHeader();

            fieldHeader.Text  = "字段名";
            fieldHeader.Width = 85;
            ColumnHeader valueHeader = new ColumnHeader();

            valueHeader.Text  = "属性值";
            valueHeader.Width = lstProperties.Width - fieldHeader.Width - 25;
            lstProperties.Columns.AddRange(new ColumnHeader[] { fieldHeader, valueHeader });
            //添加值对
            IFields fields = identifiedFeature.Fields;
            //几何图形
            IGeometry shape = identifiedFeature.Shape;

            for (int i = 0; i < fields.FieldCount; i++)
            {
                IField       field      = fields.get_Field(i);
                ListViewItem lvi        = new ListViewItem(field.AliasName);
                string       fieldValue = string.Empty;
                if (field.Type == esriFieldType.esriFieldTypeGeometry)
                {
                    fieldValue = shape.GeometryType.ToString().Substring(12);
                }
                else
                {
                    fieldValue = identifiedFeature.get_Value(i).ToString();
                }
                lvi.SubItems.Add(fieldValue);
                lstProperties.Items.Add(lvi);
            }
        }
Exemplo n.º 2
0
        //using a class description object创建一个新要素类,并赋予空间参考和要素类型
        private IFeatureClass CreateFeatureClass(String featureClassName, IFeatureWorkspace featureWorkspace, ISpatialReference spatialReference)
        {  //实例化要素类描述对象,获得默认字段
            IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
            IObjectClassDescription  ocDescription = (IObjectClassDescription)fcDescription;
            IFields fields = ocDescription.RequiredFields;
            // 找到图形字段定义空间参考和类型
            int              shapeFieldIndex = fields.FindField(fcDescription.ShapeFieldName);
            IField           field           = fields.get_Field(shapeFieldIndex);
            IGeometryDef     geometryDef     = field.GeometryDef;
            IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;

            geometryDefEdit.GeometryType_2     = esriGeometryType.esriGeometryPolygon;
            geometryDefEdit.SpatialReference_2 = spatialReference;

            IFeatureClass featureClass = featureWorkspace.CreateFeatureClass(featureClassName, fields, ocDescription.InstanceCLSID, ocDescription.ClassExtensionCLSID,
                                                                             esriFeatureType.esriFTSimple, fcDescription.ShapeFieldName, "");

            return(featureClass);
        }
Exemplo n.º 3
0
        private void loadFieldsTab()
        {
            this.lsvFields.Items.Clear();
            ITable  pTable  = this.pLayer as ITable;
            IFields pFields = pTable.Fields;
            IField  pField;

            //string fieldType;
            for (int i = 0; i < pFields.FieldCount; i++)
            {
                pField = pFields.get_Field(i);
                this.lsvFields.Items.Add(pField.Name);
                this.lsvFields.Items[i].SubItems.Add(pField.AliasName);
                this.lsvFields.Items[i].SubItems.Add(this.strfieldType[(int)pField.Type]);
                this.lsvFields.Items[i].SubItems.Add(pField.Length.ToString());
                this.lsvFields.Items[i].SubItems.Add(pField.Precision.ToString());
                this.lsvFields.Items[i].SubItems.Add(pField.Scale.ToString());
            }
        }
Exemplo n.º 4
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.FieldListbox.Items.Clear();
            int    LayerNum = this.comboBox1.SelectedIndex;
            ILayer pLayer   = pMap.get_Layer(LayerNum);

            if (pLayer is IFeatureLayer)
            {
                IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
                IFields       pFields       = pFeatureLayer.FeatureClass.Fields;
                m_feaFC = pFeatureLayer.FeatureClass;
                for (int i = 0; i < pFields.FieldCount; i++)
                {
                    this.FieldListbox.Items.Add(pFields.get_Field(i).Name);
                }
            }

            //this.FieldListbox.SelectedIndex = 0;
        }
Exemplo n.º 5
0
        private void FindOIDField()
        {
            if (currentLayer == null)
            {
                return;
            }
            IFields fields = currentLayer.FeatureClass.Fields;
            IField  field;

            for (int i = 0; i < fields.FieldCount; i++)
            {
                field = fields.get_Field(i);
                if (field.Type == esriFieldType.esriFieldTypeOID)
                {
                    strOBJECTID = field.Name;
                    break;
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates the geometry layer.
        /// </summary>
        /// <param name="sName">Name of the s.</param>
        /// <param name="geometry">The geometry.</param>
        /// <param name="featureWorkspace">The feature workspace.</param>
        /// <param name="sAlias">The s alias.</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        public static bool CreateGeometryLayer(string sName, IGeometry geometry, IFeatureWorkspace featureWorkspace, string sAlias = "")
        {
            bool result;

            try
            {
                IObjectClassDescription objectClassDescription = new FeatureClassDescriptionClass();
                IFields          requiredFields  = objectClassDescription.RequiredFields;
                string           shapeFieldName  = (objectClassDescription as IFeatureClassDescription).ShapeFieldName;
                int              index           = requiredFields.FindField(shapeFieldName);
                IGeometryDef     geometryDef     = requiredFields.get_Field(index).GeometryDef;
                IGeometryDefEdit geometryDefEdit = geometryDef as IGeometryDefEdit;
                geometryDefEdit.GeometryType_2     = geometry.GeometryType;
                geometryDefEdit.SpatialReference_2 = geometry.SpatialReference;
                IFeatureClass featureClass = featureWorkspace.CreateFeatureClass(sName, requiredFields, new UIDClass
                {
                    Value = "esriGeoDatabase.Feature"
                }, null, esriFeatureType.esriFTSimple, shapeFieldName, "");
                try
                {
                    IFeature feature = featureClass.CreateFeature();
                    feature.Shape = geometry;
                    feature.Store();
                    if (!string.IsNullOrEmpty(sAlias))
                    {
                        EngineAPI.AlterDatasetAlias(featureClass, sAlias);
                    }
                }
                finally
                {
                    if (featureClass != null)
                    {
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(featureClass);
                    }
                }
                result = true;
            }
            catch
            {
                result = false;
            }
            return(result);
        }
Exemplo n.º 7
0
        public static esriFieldType GetArcGisFieldType(string strFieldName)
        {
            try
            {
                IFields fields = clsGlobals.arcFeatLayer.FeatureClass.Fields;
                IField  field  = fields.get_Field(clsGlobals.arcFeatLayer.FeatureClass.Fields.FindField(strFieldName));

                return(field.Type);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error Message: " + Environment.NewLine + ex.Message + Environment.NewLine + Environment.NewLine +
                                "Error Source: " + Environment.NewLine + ex.Source + Environment.NewLine + Environment.NewLine +
                                "Error Location:" + Environment.NewLine + ex.StackTrace,
                                "Push Utrans Roads to SGID!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                return(0);
            }
        }
Exemplo n.º 8
0
 private void cboLayer_SelectedIndexChanged(object sender, EventArgs e)
 {
     this.memoEdit.Text = "";
     this.cboFields.Properties.Items.Clear();
     if (this.cboLayer.SelectedIndex >= 0)
     {
         this.btnQueryDialog.Enabled = true;
         IFeatureLayer layer = (this.cboLayer.SelectedItem as LayerObject).Layer as IFeatureLayer;
         if ((layer as IFeatureSelection).SelectionSet.Count > 0)
         {
             this.chkUseSelected.Enabled = true;
             this.chkUseSelected.Checked = true;
         }
         else
         {
             this.chkUseSelected.Checked = false;
             this.chkUseSelected.Enabled = false;
             this.chkUseSelected.Checked = false;
         }
         IFields fields = layer.FeatureClass.Fields;
         for (int i = 0; i < fields.FieldCount; i++)
         {
             IField pField = fields.get_Field(i);
             if ((((pField.Type != esriFieldType.esriFieldTypeOID) &&
                   (pField.Type != esriFieldType.esriFieldTypeGeometry)) &&
                  ((pField.Type != esriFieldType.esriFieldTypeRaster) &&
                   (pField.Type != esriFieldType.esriFieldTypeBlob))) && pField.Editable)
             {
                 this.cboFields.Properties.Items.Add(new FieldWrap(pField));
             }
         }
         if (this.cboFields.Properties.Items.Count > 0)
         {
             this.cboFields.SelectedIndex = 0;
         }
     }
     else
     {
         this.btnQueryDialog.Enabled = false;
         this.chkUseSelected.Checked = false;
         this.chkUseSelected.Enabled = false;
     }
 }
Exemplo n.º 9
0
 //鼠标点击事件
 private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
 {
     if (pMouseOperate == "ZoomIn")
     {
         axMapControl1.Extent = axMapControl1.TrackRectangle();
     }
     if (pMouseOperate == "ZoomOut")
     {
         IEnvelope penv = axMapControl1.Extent;
         penv.Expand(2, 2, true);
         axMapControl1.Extent = penv;
     }
     if (pMouseOperate == "Pan")
     {
         axMapControl1.Pan();
     }
     if (pMouseOperate == "Identify")
     {
         IPoint point = new ESRI.ArcGIS.Geometry.Point();
         point.PutCoords(e.mapX, e.mapY);
         IFeatureLayer pFeatureLayer  = axMapControl1.get_Layer(0) as IFeatureLayer;
         IFeatureClass pFeatureClass  = pFeatureLayer.FeatureClass;
         string        shapefieldname = pFeatureClass.ShapeFieldName;
         ESRI.ArcGIS.Geodatabase.ISpatialFilter pSpatialFilter = new ESRI.ArcGIS.Geodatabase.SpatialFilter();
         pSpatialFilter.Geometry   = point;
         pSpatialFilter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelIntersects;
         pSpatialFilter.set_OutputSpatialReference(shapefieldname, axMapControl1.SpatialReference);
         pSpatialFilter.GeometryField = shapefieldname;
         ESRI.ArcGIS.Geodatabase.IFeatureCursor pFeatureCursor = pFeatureClass.Search(pSpatialFilter, false);
         ESRI.ArcGIS.Geodatabase.IFeature       pFeature       = pFeatureCursor.NextFeature();
         if (pFeature != null)
         {
             axMapControl1.FlashShape(pFeature.Shape);
         }
         IFields pField = pFeature.Fields;
         listFields.Items.Clear();
         for (int i = 0; i <= pField.FieldCount - 1; i++)
         {
             listFields.Items.Add(pField.get_Field(i).Name + "=" + pFeature.get_Value(i));
         }
     }
 }
        //用帮助里的例子,修改了字段和空间参考
        public IFeatureClass CreateFeatureClass(String featureClassName, IFeatureWorkspace featureWorkspace, IField[] arrFields)
        {
            // Instantiate a feature class description to get the required fields.
            IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
            IObjectClassDescription  ocDescription = (IObjectClassDescription)fcDescription;
            IFields     fields     = ocDescription.RequiredFields;
            IFieldsEdit fieldsEdit = (IFieldsEdit)fields;

            // Add some fields to the required fields.
            foreach (IField pField in arrFields)
            {
                fieldsEdit.AddField(pField);
            }

            // Find the shape field in the required fields and modify its GeometryDef to
            // use point geometry and to set the spatial reference.
            int              shapeFieldIndex = fields.FindField(fcDescription.ShapeFieldName);
            IField           field           = fields.get_Field(shapeFieldIndex);
            IGeometryDef     geometryDef     = field.GeometryDef;
            IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;

            geometryDefEdit.GeometryType_2     = esriGeometryType.esriGeometryPolygon;
            geometryDefEdit.SpatialReference_2 = this.pMapControl.SpatialReference;//导进来的要素类使用当前地图的空间参考

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

            fieldChecker.ValidateWorkspace = (IWorkspace)featureWorkspace;
            fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

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

            // Create the feature class.//这一步极易出错,一般都是名为featureClassName的文件已存在
            IFeatureClass featureClass = featureWorkspace.CreateFeatureClass(featureClassName, validatedFields,
                                                                             ocDescription.InstanceCLSID, ocDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple,
                                                                             fcDescription.ShapeFieldName, "");

            return(featureClass);
        }
Exemplo n.º 11
0
        public void CopyFieldsToObjectFeatureClass(IFeatureClass ObjectFeatureClass)
        {
            IFields Fields = this.featureClass.Fields;
            IField  field  = null;

            IField     mField;
            IFieldEdit mFieldEdit;

            for (int j = 0; j < Fields.FieldCount; j++)
            {
                field = Fields.get_Field(j);
                if (ObjectFeatureClass.Fields.FindField(field.Name) <= -1 && (SystemFieldsList.Contains(field.Name.ToUpper()) == false))
                {
                    if (field.Type != esriFieldType.esriFieldTypeOID &&
                        field.Type != esriFieldType.esriFieldTypeGeometry)
                    {
                        if (field.Type != esriFieldType.esriFieldTypeBlob)
                        {
                            //创建一个新的字段类型
                            mField                 = new FieldClass();
                            mFieldEdit             = mField as IFieldEdit;
                            mFieldEdit.Name_2      = field.Name;
                            mFieldEdit.AliasName_2 = field.AliasName;

                            mFieldEdit.Type_2 = field.Type;

                            mFieldEdit.Length_2    = field.Length;
                            mFieldEdit.Precision_2 = field.Precision;
                            mFieldEdit.Scale_2     = field.Scale;

                            mFieldEdit.Editable_2     = field.Editable;
                            mFieldEdit.IsNullable_2   = field.IsNullable;
                            mFieldEdit.DefaultValue_2 = field.DefaultValue;
                            mFieldEdit.Domain_2       = field.Domain;
                            mFieldEdit.DomainFixed_2  = field.DomainFixed;

                            ObjectFeatureClass.AddField(mField);
                        }
                    }
                }
            }
        }
        private IGeoDataset GetBeforeGeo(IFeatureClass fc)
        {
            try
            {
                IInterpolationOp3 pInterpolationOp = new RasterInterpolationOpClass();

                IFields fields = fc.Fields;
                int     index  = fields.FindFieldByAliasName("高程");
                if (index == -1)
                {
                    return(null);
                }
                IField field = fields.get_Field(index);

                ISpatialFilter filter = new SpatialFilter();
                filter.Geometry   = geo;
                filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;
                int count = fc.FeatureCount(filter);
                if (count == 0)
                {
                    return(null);
                }
                IFeatureClassDescriptor pFcd = new FeatureClassDescriptorClass();
                pFcd.Create(fc, filter, field.Name);

                //定义搜索半径
                IRasterRadius pRadius = new RasterRadiusClass();
                object        Missing = Type.Missing;
                pRadius.SetVariable(12, ref Missing);

                //设置栅格图像的单位大小
                object cellSizeProvider         = 5;
                IRasterAnalysisEnvironment pEnv = pInterpolationOp as IRasterAnalysisEnvironment;
                pEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref cellSizeProvider);
                IGeoDataset outGeoDataset = pInterpolationOp.IDW(pFcd as IGeoDataset, 2, pRadius, ref Missing);
                return(outGeoDataset);
            }
            catch (System.Exception ex)
            {
                return(null);
            }
        }
        /// <summary>
        /// Check the Name and Alias properties of the given Raster Function Variable to see
        /// if they contain a reference to a field and get the value of the corresponding field if needed.
        /// </summary>
        /// <param name="rasterFunctionVar">The Raster Function Variable to check.</param>
        /// <param name="pRow">The row corresponding to the function raster dataset.</param>
        /// <returns></returns>
        private object FindPropertyInRow(IRasterFunctionVariable rasterFunctionVar, IRow pRow)
        {
            string       varName  = "";
            IStringArray varNames = new StrArrayClass();

            varName = rasterFunctionVar.Name;
            // If the name of  the variable contains '@Field'
            if (varName.Contains("@Field."))
            {
                varNames.Add(varName); // Add it to the list of names.
            }
            // Check the aliases of the variable
            for (int i = 0; i < rasterFunctionVar.Aliases.Count; ++i)
            {
                // Check the list of aliases for the '@Field' string
                varName = rasterFunctionVar.Aliases.get_Element(i);
                if (varName.Contains("@Field."))
                {
                    varNames.Add(varName); // and add any that are found to the list of names.
                }
            }

            // Use the list of names and find the value by looking up the appropriate field.
            for (int i = 0; i < varNames.Count; ++i)
            {
                // Get the variable name containing the field string
                varName = varNames.get_Element(i);
                // Replace the '@Field' with nothing to get just the name of the field.
                string  fieldName = varName.Replace("@Field.", "");
                IFields rowFields = pRow.Fields;
                // Look up the index of the field name in the row.
                int fieldIndex = rowFields.FindField(fieldName);
                // If it is a valid index and the field type is string, return the value.
                if (fieldIndex != -1 &&
                    ((rowFields.get_Field(fieldIndex)).Type == esriFieldType.esriFieldTypeString))
                {
                    return(pRow.get_Value(fieldIndex));
                }
            }
            // If no value has been returned yet, return null.
            return(null);
        }
Exemplo n.º 14
0
        //在点击“获取唯一属性值”按钮时触发事件,执行本函数
        //对图层的某个字段进行唯一值获取操作,并将所有的唯一值显示在listBoxValues控件中
        private void buttonGetUniqeValue_Click(object sender, EventArgs e)
        {
            try
            {
                this.listBoxValues.Items.Clear();
                //使用FeatureClass对象的IDataset接口来获取dataset和workspace的信息
                IDataset dataset = (IDataset)currentFeatureLayer.FeatureClass;
                //使用IQueryDef接口的对象来定义和查询属性信息。通过IWorkspace接口的CreateQueryDef()方法创建该对象。
                IQueryDef queryDef = ((IFeatureWorkspace)dataset.Workspace).CreateQueryDef();
                //设置所需查询的表格名称为dataset的名称
                queryDef.Tables = dataset.Name;
                //设置查询的字段名称。可以联合使用SQL语言的关键字,如查询唯一值可以使用DISTINCT关键字。
                queryDef.SubFields = "DISTINCT (" + currentFieldName + ")";
                //执行查询并返回ICursor接口的对象来访问整个结果的集合
                ICursor cursor = queryDef.Evaluate();
                //使用IField接口获取当前所需要使用的字段的信息
                IFields fields = currentFeatureLayer.FeatureClass.Fields;
                IField  field  = fields.get_Field(fields.FindField(currentFieldName));

                //对整个结果集合进行遍历,从而添加所有的唯一值
                //使用IRow接口来操作结果集合。首先定位到第一个查询结果。
                IRow row = cursor.NextRow();
                //如果查询结果非空,则一直进行添加操作
                while (row != null)
                {
                    //对String类型的字段,唯一值的前后添加'和',以符合SQL语句的要求
                    if (field.Type == esriFieldType.esriFieldTypeString)
                    {
                        listBoxValues.Items.Add("\'" + row.get_Value(0).ToString() + "\'");
                    }
                    else
                    {
                        listBoxValues.Items.Add(row.get_Value(0).ToString());
                    }
                    //继续执行下一个结果的添加
                    row = cursor.NextRow();
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 15
0
        private IFeatureClass method_2(IFeatureWorkspace ifeatureWorkspace_0, string string_4,
                                       esriFeatureType esriFeatureType_0, esriGeometryType esriGeometryType_0, IFields ifields_0)
        {
            IFeatureClass class2 = null;
            string        str;
            IFieldChecker checker = new FieldCheckerClass
            {
                ValidateWorkspace = ifeatureWorkspace_0 as IWorkspace
            };

            checker.ValidateTableName(string_4, out str);
            IObjectClassDescription description = null;

            if (esriFeatureType_0 == esriFeatureType.esriFTAnnotation)
            {
                return(this.method_1(ifeatureWorkspace_0, string_4, 1000.0, new TextSymbolClass(), ifields_0));
            }
            description = new FeatureClassDescriptionClass();
            IFieldsEdit requiredFields = description.RequiredFields as IFieldsEdit;
            IFieldEdit  edit2          = null;
            int         index          = requiredFields.FindField((description as IFeatureClassDescription).ShapeFieldName);

            edit2 = requiredFields.get_Field(index) as IFieldEdit;
            IGeometryDefEdit geometryDef  = edit2.GeometryDef as IGeometryDefEdit;
            esriFeatureType  esriFTSimple = esriFeatureType.esriFTSimple;

            edit2.GeometryDef_2 = geometryDef;
            for (int i = 0; i < ifields_0.FieldCount; i++)
            {
                requiredFields.AddField(ifields_0.get_Field(i));
            }
            try
            {
                class2 = ifeatureWorkspace_0.CreateFeatureClass(string_4, requiredFields, null, null, esriFTSimple,
                                                                (description as IFeatureClassDescription).ShapeFieldName, "");
            }
            catch (Exception exception)
            {
                Logger.Current.Error("", exception, "");
            }
            return(class2);
        }
Exemplo n.º 16
0
        private void cmbSampleFeatureClass_SelectedIndexChanged(object sender, EventArgs e)
        {
            string ftrNm = cmbSampleFeatureClass.Text;

            cmbLinkedFld.Items.Clear();
            cmbLinkedFld.Text = "";
            if (ftrNm != null && ftrNm != "")
            {
                IFields flds = ftrDic[ftrNm].Fields;
                for (int i = 0; i < flds.FieldCount; i++)
                {
                    IField        fld    = flds.get_Field(i);
                    esriFieldType flType = fld.Type;
                    if (flType != esriFieldType.esriFieldTypeRaster && flType != esriFieldType.esriFieldTypeOID && flType != esriFieldType.esriFieldTypeGeometry && flType != esriFieldType.esriFieldTypeBlob && flType != esriFieldType.esriFieldTypeDate && flType != esriFieldType.esriFieldTypeGlobalID && flType != esriFieldType.esriFieldTypeXML)
                    {
                        cmbLinkedFld.Items.Add(fld.Name);
                    }
                }
            }
        }
Exemplo n.º 17
0
        private void FrmFiledCalculator_Load(object sender, EventArgs e)
        {
            //初始化图层列表
            ITable  pTable  = (ITable)pLayer;
            IFields pFields = pTable.Fields;
            long    nRows   = pTable.RowCount(null);
            long    nFields = pFields.FieldCount;

            IField pField;

            for (int i = 0; i < nFields; i++)
            {
                pField = pFields.get_Field(i);
                this.lsbFields.Items.Add(pField.Name);
                if (pField.Name != "Shape")
                {
                    cmbCalField.Items.Add(pField.Name);
                }
            }
        }
Exemplo n.º 18
0
        private void ChklstFieldsAddItems(IFeatureLayer featureLayer)
        {
            if (featureLayer == null)
            {
                featureLayer = GetFeatureLayer(strBufferLayer);
            }
            if (featureLayer == null)
            {
                return;
            }
            IFields fields = featureLayer.FeatureClass.Fields;
            IField  field  = null;

            for (int i = 0; i < fields.FieldCount; i++)
            {
                field = fields.get_Field(i);
                chklstFields.Items.Add(field.Name);
            }
            chklstFields.Refresh();
        }
Exemplo n.º 19
0
        private void RefreshTable(IFeatureLayer _layer, IFeatureClass pFeatureClass1, DataGridView _data, string strName, ICursor pCursor)
        {
            int        index   = pCursor.Fields.FindField(strName);
            IFields    pFields = pFeatureClass1.Fields;
            DataSet    ds      = new DataSet("dsFields");
            DataTable  dt      = new DataTable(pFeatureLayer.Name);
            DataColumn dc      = null;
            //ITable table=_layer as ITable;

            IRow row = null;

            //IRow tablerow = null;
            for (int i = 0; i < pFields.FieldCount; i++)
            {
                dc = new DataColumn(pFields.get_Field(i).Name);
                dt.Columns.Add(dc);
                dc = null;
            }
            while ((row = pCursor.NextRow()) != null)
            {
                //tablerow = table.GetRow(row.OID);
                DataRow dr = dt.NewRow();
                for (int j = 0; j < pFields.FieldCount; j++)
                {
                    if (pCursor.Fields.FindField(pFeatureClass.ShapeFieldName) == j)
                    {
                        dr[j] = pFeatureClass.ShapeType.ToString();
                    }
                    else
                    {
                        dr[j] = row.get_Value(j);
                        //tablerow.set_Value(j+1,row.get_Value(j+1));
                    }

                    //tablerow.Store();
                }
                dt.Rows.Add(dr);
            }

            _data.DataSource = dt;
        }
Exemplo n.º 20
0
        public static IGeometry ModifyGeometryZMValue(IObjectClass featureClass, IGeometry modifiedGeometry)
        {
            IFeatureClass targetFeatureClass = featureClass as IFeatureClass;

            if (targetFeatureClass == null)
            {
                return(null);
            }
            string           shapeFieldName  = targetFeatureClass.ShapeFieldName;
            IFields          fields          = targetFeatureClass.Fields;
            int              geometryIndex   = fields.FindField(shapeFieldName);
            IField           field           = fields.get_Field(geometryIndex);
            IGeometryDef     geometryDef     = field.GeometryDef;
            IPointCollection pointCollection = modifiedGeometry as IPointCollection;

            if (geometryDef.HasZ)
            {
                IZAware zAware = modifiedGeometry as IZAware;
                zAware.ZAware = true;
                IZ iz = modifiedGeometry as IZ;
                //将Z值设置为0
                iz.SetConstantZ(0);
            }
            else
            {
                IZAware zAware = modifiedGeometry as IZAware;
                zAware.ZAware = false;
            }
            if (geometryDef.HasM)
            {
                IMAware mAware = modifiedGeometry as IMAware;
                mAware.MAware = true;
            }
            else
            {
                IMAware mAware = modifiedGeometry as IMAware;
                mAware.MAware = false;
            }

            return(modifiedGeometry);
        }
Exemplo n.º 21
0
        private void btnImportStruct_Click(object sender, EventArgs e)
        {
            frmOpenFile file = new frmOpenFile();

            file.AddFilter(new MyGxFilterTablesAndFeatureClasses(), true);
            file.AllowMultiSelect = false;
            if ((file.DoModalOpen() == DialogResult.OK) && (file.Items.Count != 0))
            {
                IGxDataset dataset = file.Items.get_Element(0) as IGxDataset;
                if (dataset != null)
                {
                    ITable table = dataset.Dataset as ITable;
                    if (table != null)
                    {
                        int    num;
                        IField field;
                        for (num = this.ifields_0.FieldCount - 1; num > 1; num--)
                        {
                            field = this.ifields_0.get_Field(num);
                            if ((field.Type != esriFieldType.esriFieldTypeOID) &&
                                (field.Type != esriFieldType.esriFieldTypeGeometry))
                            {
                                (this.ifields_0 as IFieldsEdit).DeleteField(field);
                            }
                        }
                        IFields fields = table.Fields;
                        for (num = 0; num < fields.FieldCount; num++)
                        {
                            field = fields.get_Field(num);
                            if ((field.Type != esriFieldType.esriFieldTypeOID) &&
                                (field.Type != esriFieldType.esriFieldTypeGeometry))
                            {
                                (this.ifields_0 as IFieldsEdit).AddField(field);
                            }
                        }
                    }
                    this.method_0(this.listView2, this.ifields_0);
                    this.method_2(this.listView2.Items[0].Tag as IField, true);
                }
            }
        }
Exemplo n.º 22
0
        private void OnLoadFeatureClass(object sender, EventArgs e)
        {
            IGxDialog iGxDlg = new GxDialogClass();

            iGxDlg.Title        = "选择点数据集";
            iGxDlg.ObjectFilter = new GxFilterPointFeatureClassesClass();
            IEnumGxObject selection;

            iGxDlg.DoModalOpen(0, out selection);
            selection.Reset();

            IGxObject iGxObject;

            while ((iGxObject = selection.Next()) != null)
            {
                IGxDataset iGxDataset = (IGxDataset)iGxObject;
                if (iGxDataset != null)
                {
                    IDataset      iDataset = iGxDataset.Dataset;
                    IFeatureClass iFc      = (IFeatureClass)iDataset;
                    mFeatureClass = iFc;

                    textBox6.Text = iGxObject.FullName;

                    //设置ComboBox
                    comboBox1.ResetText();
                    IFields iFields = iFc.Fields;
                    long    iCount  = iFields.FieldCount;
                    for (int i = 0; i < iCount; i++)
                    {
                        IField iField = iFields.get_Field(i);
                        comboBox1.Items.Add(iField.Name);
                    }

                    if (comboBox1.Items.Count > 0)
                    {
                        comboBox1.SelectedIndex = 0;
                    }
                }
            }
        }//Open Feature Class
Exemplo n.º 23
0
        private void comboBoxInData_SelectedIndexChanged(object sender, EventArgs e)
        {
            string       sLayerName = comboBoxInData.Text;
            AxMapControl axMap      = pMainFrm.getMapControl();
            IRasterLayer pRsLayer   = null;

            comboBoxField.Items.Clear();
            comboBoxField.Items.Add("无");
            try
            {
                for (int i = 0; i <= axMap.LayerCount - 1; i++)
                {
                    ILayer pLyr = axMap.get_Layer(i);
                    if (pLyr.Name == sLayerName)
                    {
                        if (pLyr is IRasterLayer)
                        {
                            pRsLayer    = pLyr as IRasterLayer;
                            m_pInRaster = pRsLayer.Raster;
                            IRasterBandCollection pBandCol = pRsLayer.Raster as IRasterBandCollection;
                            IRasterBand           pBand    = pBandCol.Item(0);
                            bool HasTable;
                            pBand.HasTable(out HasTable);
                            if (HasTable == true)
                            {
                                ITable  pTable  = pBand.AttributeTable;
                                IFields pFields = pTable.Fields;
                                for (i = 0; i <= pFields.FieldCount - 1; i++)
                                {
                                    comboBoxField.Items.Add(pFields.get_Field(i).Name);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 24
0
        private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            this.gridView1.Columns.Clear();
            currentLayer = e.Node.Tag as IFeatureLayer;
            if (currentLayer == null)
            {
                return;
            }
            IFeatureSelection featureSelection = currentLayer as IFeatureSelection;
            //获取选中得要素几何
            ISelectionSet selectionSet = featureSelection.SelectionSet;
            //获取字段
            IFields   fields = currentLayer.FeatureClass.Fields;
            DataTable dt     = new DataTable();

            for (int i = 0; i < fields.FieldCount; i++)
            {
                dt.Columns.Add(fields.get_Field(i).Name);
            }
            //获取整个数据集
            ICursor cursor;

            selectionSet.Search(null, false, out cursor);
            //获取每个要素
            IFeatureCursor featureCursor = cursor as IFeatureCursor;
            //遍历
            IFeature feature = featureCursor.NextFeature();

            String[] strs;
            while (feature != null)
            {
                strs = new String[fields.FieldCount];
                for (int i = 0; i < fields.FieldCount; i++)
                {
                    strs[i] = feature.get_Value(i).ToString();
                }
                dt.Rows.Add(strs);
                feature = featureCursor.NextFeature();
            }
            this.gridControl1.DataSource = dt;
        }
Exemplo n.º 25
0
        public int QueryValues(IRowBuffer Row)
        {
            try
            {
                if (m_sbuffer == null)
                {
                    return(-1);
                }

                for (int i = 0; i < m_fieldMap.GetLength(0); i++)
                {
                    //HIGHLIGHT: 2.2 QueryValues - field map interpretation
                    if (m_fieldMap.GetValue(i).Equals(-1))
                    {
                        continue;
                    }

                    IField valField = m_fields.get_Field(i);
                    char   parse    = m_sbuffer[m_sbuffer.Length - 1];
                    switch (valField.Type)
                    {
                    case esriFieldType.esriFieldTypeInteger:
                    case esriFieldType.esriFieldTypeDouble:
                    case esriFieldType.esriFieldTypeSmallInteger:
                    case esriFieldType.esriFieldTypeSingle:
                        Row.set_Value(i, Convert.ToInt32(parse));                                       //get ascii code # for the character
                        break;

                    case esriFieldType.esriFieldTypeString:
                        Row.set_Value(i, parse.ToString());
                        break;
                    }
                }
                return(m_iInterate);                    //HIGHLIGHT: 2.3 QueryValues - return OID
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(-1);
            }
        }
Exemplo n.º 26
0
        private IFields CreateFieldsCollection(ISpatialReference spatialReference, esriGeometryType geometryType)
        {
            IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass();
            IObjectClassDescription  ocDesc = fcDesc as IObjectClassDescription;

            IFields     fields     = ocDesc.RequiredFields;
            IFieldsEdit fieldsEdit = fields as IFieldsEdit;

            int    shapeFieldIndex = fields.FindField(fcDesc.ShapeFieldName);
            IField shapeField      = fields.get_Field(shapeFieldIndex);

            IGeometryDef     geometryDef     = shapeField.GeometryDef;
            IGeometryDefEdit geometryDefEdit = geometryDef as IGeometryDefEdit;

            geometryDefEdit.GeometryType_2 = geometryType;
            geometryDefEdit.GridCount_2    = 1;
            geometryDefEdit.set_GridSize(0, 0);
            geometryDefEdit.SpatialReference_2 = spatialReference;

            return(fields);
        }
Exemplo n.º 27
0
        public static Dictionary <string, Tuple <int, esriFieldType> > GetFieldIndexes(IFeatureClass featureClass)
        {
            Dictionary <string, Tuple <int, esriFieldType> > dict = null;

            if (null != featureClass)
            {
                int cnt = featureClass.Fields.FieldCount;
                if (cnt > 0)
                {
                    dict = new Dictionary <string, Tuple <int, esriFieldType> >();
                    IFields flds = featureClass.Fields;
                    IField  fld  = null;
                    for (int i = 0; i < cnt; ++i)
                    {
                        fld = flds.get_Field(i);
                        dict.Add(fld.Name, new Tuple <int, esriFieldType>(i, fld.Type));
                    }
                }
            }
            return(dict);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Creates the feature class.
        /// </summary>
        /// <param name="workspace">The workspace.</param>
        /// <param name="sName">Name of the file.</param>
        /// <param name="fields">The fields.</param>
        /// <param name="spatialRef">The spatial reference.</param>
        /// <param name="geoType">featureclass type.</param>
        /// <returns>IFeatureClass.</returns>
        public static IFeatureClass CreateFeatureClass(IWorkspace workspace, string sName, IFields fields, ISpatialReference spatialRef, esriGeometryType geoType)
        {
            string shapeFieldName = "";

            for (int i = 0; i < fields.FieldCount; i++)
            {
                IField field = fields.get_Field(i);
                if (field.Type == esriFieldType.esriFieldTypeGeometry)
                {
                    shapeFieldName = field.Name;
                    IGeometryDefEdit geometryDefEdit = field.GeometryDef as IGeometryDefEdit;
                    geometryDefEdit.GeometryType_2     = geoType;
                    geometryDefEdit.SpatialReference_2 = spatialRef;
                    break;
                }
            }
            UID uID = new UIDClass();

            uID.Value = "esriGeoDatabase.Feature";
            return((workspace as IFeatureWorkspace).CreateFeatureClass(sName, fields, uID, null, esriFeatureType.esriFTSimple, shapeFieldName, ""));
        }
Exemplo n.º 29
0
        private void cboOriginPrimaryKey1_SelectedIndexChanged(object sender, EventArgs e)
        {
            NewRelationClassHelper.OriginPrimaryKey = this.cboOriginPrimaryKey1.Text;
            this.cbodestForeignKey1.Properties.Items.Clear();
            IFields fields = NewRelationClassHelper.DestinationClass.Fields;
            int     index  = NewRelationClassHelper.OriginClass.Fields.FindField(this.cboOriginPrimaryKey1.Text);

            if (index != -1)
            {
                esriFieldType type = NewRelationClassHelper.OriginClass.Fields.get_Field(index).Type;
                for (int i = 0; i < fields.FieldCount; i++)
                {
                    IField field = fields.get_Field(i);
                    if (((field.Type != esriFieldType.esriFieldTypeBlob) ||
                         (field.Type != esriFieldType.esriFieldTypeGeometry)) && (type == field.Type))
                    {
                        this.cbodestForeignKey1.Properties.Items.Add(field.Name);
                    }
                }
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// 获取ITable在 T 类中包含同名可写属性的集合
        /// </summary>
        /// <param name="table"></param>
        /// <returns>以属性名为键,PropertyInfo 为值得字典对象</returns>
        private static Dictionary <string, PropertyInfo> GetFields <T>(ITable table)
        {
            Dictionary <string, PropertyInfo> result = new Dictionary <string, PropertyInfo>();
            IFields fields      = table.Fields;
            int     columnCount = fields.FieldCount;
            Type    t           = typeof(T);

            List <string> readerFields = new List <string>();

            for (int i = 0; i < columnCount; i++)
            {
                readerFields.Add(fields.get_Field(i).Name);
            }
            var properties = t.GetProperties().Where(v => v.CanWrite && readerFields.Contains(v.Name));

            foreach (PropertyInfo propertyInfo in properties)
            {
                result.Add(propertyInfo.Name, propertyInfo);
            }
            return(result);
        }
 public frmAttributeQuery(ITable inputTable)
 {
     InitializeComponent();
     tbl = inputTable;
     flds = tbl.Fields;
     IDataset dset = (IDataset)tbl;
     IWorkspace wks = (dset).Workspace;
     string wksp = wks.PathName.ToLower();
     if(wksp.EndsWith(".mdb")||wksp.EndsWith(".accbd"))
     {
         btn1.Text = "?";
         btn2.Text = "*";
         pr = '[';
         sf = ']';
     }
     for (int i = 0; i < flds.FieldCount; i++)
     {
         IField fld = flds.get_Field(i);
         lstFields.Items.Add(pr+fld.Name+sf);
     }
     lstFields.SelectedItem = lstFields.Items[0];
     lblSelect.Text = "SELECT * FROM " + dset.BrowseName + " WHERE ";
 }
        private void updateDomains(ref IFields pFlds,IWorkspace cWks)
        {
            for (int i = 0; i < pFlds.FieldCount; i++)
            {
                IField fld = pFlds.get_Field(i);
                IDomain pDom = fld.Domain;
                if (pDom != null)
                {
                    string domName = pDom.Name;
                    IDomain cDom = getDom(cWks, domName);
                    if (cDom != null)
                    {
                        IFieldEdit fldE = (IFieldEdit)fld;
                        fldE.Domain_2 = cDom;
                    }

                }
            }
        }
Exemplo n.º 33
0
        //---------------------------------------------------------------------

        /// <summary>
        /// Creates a new feature class. Returns the feature class or null if not successful. Throws but does not handle errors. 
        /// </summary>
        /// <param name="sFeatName">Feature class name.</param>
        /// <param name="configWord">Configuration keywords for the new feature class.</param>
        /// <param name="oWorkspace">Workspace in which to create the new feature class.</param>
        /// <param name="theFields">Fields collection of the new feature class.</param>
        /// <param name="featureType">Feature type of the new feature class.</param>
        /// <param name="geometryType">geometry type of the new feature class.</param>
        /// <param name="CLSID">Class ID of the new feature class. May be null if featureType is not null.</param>
        /// <param name="CLSEXT">Class extension ID of the new feature class. Pass null if none.</param>
        /// <returns>Returns the cloned feature class. Throws an error if no feature class can be created.</returns>
        private IFeatureClass CreateFeatureClass(string featureClassName, string configWord, object outWorkspace,
            IFields fields, esriFeatureType featureType, esriGeometryType geometryType, UID CLSID, UID CLSEXT)
        {
            IFeatureClass featureClass = null;
            if (outWorkspace == null) throw (new Exception("Workspace cannot be null"));
            if (!((outWorkspace is IWorkspace) || (outWorkspace is IFeatureDataset)))
                throw (new Exception("Workspace must be IWorkspace or IFeatureDataset"));
            if (featureClassName == "") throw (new Exception("Feature class name cannot be empty string"));
            UID uidCLSID = new UIDClass();
            if (CLSID == null)
            {
                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;
                }
            }
            else
            {
                uidCLSID = CLSID;
            }
            UID uidCLSEXT = new UIDClass();
            if (CLSEXT == null)
            {
                switch (featureType)
                {
                    case (esriFeatureType.esriFTAnnotation):
                        uidCLSEXT.Value = "{24429589-D711-11D2-9F41-00C04F6BC6A5}";
                        break;
                    case (esriFeatureType.esriFTDimension):
                        uidCLSEXT.Value = "{48F935E2-DA66-11D3-80CE-00C04F601565}";
                        break;
                    default:
                        uidCLSEXT = null;
                        break;
                }
            }
            else
                uidCLSEXT = CLSEXT;
            string shapeFieldName = "";
            for (int i = 0; i <= fields.FieldCount - 1; i++)
            {
                if (fields.get_Field(i).Type == esriFieldType.esriFieldTypeGeometry)
                {
                    shapeFieldName = fields.get_Field(i).Name;
                    break;
                }
            }
            if (shapeFieldName == "") throw new Exception("Cannot locate geometry field");
            if (outWorkspace is IWorkspace)
            {
                IWorkspace workspace = (IWorkspace)outWorkspace;
                IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
                featureClass = featureWorkspace.CreateFeatureClass(featureClassName, fields, uidCLSID, uidCLSEXT,
                    featureType, shapeFieldName, configWord);
            }
            else if (outWorkspace is IFeatureDataset)
            {
                IFeatureDataset featureDataset = (IFeatureDataset)outWorkspace;
                featureClass = featureDataset.CreateFeatureClass(featureClassName, fields, uidCLSID, uidCLSEXT,
                    featureType, shapeFieldName, configWord);
            }
            return featureClass;
        }
Exemplo n.º 34
0
 /// <summary>
 /// 根据传入的字段与值的字典信息,返回sql查询语句
 /// </summary>
 /// <params name="fldvals">键值字典</params>
 /// <returns>sql查询语句</returns>
 public string CreateSqlexpression(IFields flds, Dictionary<string, string> fldvals)
 {
     string sql = "";
     int k = 0;
     foreach (string key in fldvals.Keys)
     {
         int fldindex = flds.FindField(key);
         IField fld = flds.get_Field(fldindex);
         esriFieldType type = fld.Type;
         if (k == 0)
         {
             if (type == esriFieldType.esriFieldTypeString)
             {
                 sql = "\"" + key + "\"='" + fldvals[key] + "'";
             }
             else if (type == esriFieldType.esriFieldTypeInteger)
             {
                 sql = "\"" + key + "\"=" + fldvals[key];
             }
         }
         else
         {
             if (type == esriFieldType.esriFieldTypeString)
             {
                 sql += " AND \"" + key + "\"='" + fldvals[key] + "'";
             }
             else if (type == esriFieldType.esriFieldTypeInteger)
             {
                 sql += " AND \"" + key + "\"=" + fldvals[key];
             }
         }
         k++;
     }
     return sql;
 }
Exemplo n.º 35
0
        /// <summary>
        /// 在内存中创建图层
        /// </summary>
        /// <param name="DataSetName">数据集名称</param>
        /// <param name="AliaseName">别名</param>
        /// <param name="SpatialRef">空间参考</param>
        /// <param name="GeometryType">几何类型</param>
        /// <param name="PropertyFields">属性字段集合</param>
        /// <returns>IfeatureLayer</returns>
        public static IFeatureLayer CreateFeatureLayerInmemeory(string DataSetName, string AliaseName, ISpatialReference SpatialRef, esriGeometryType GeometryType, IFields PropertyFields)
        {
            IWorkspaceFactory workspaceFactory = new InMemoryWorkspaceFactoryClass();
              ESRI.ArcGIS.Geodatabase.IWorkspaceName workspaceName = workspaceFactory.Create("", "MyWorkspace", null, 0);
              ESRI.ArcGIS.esriSystem.IName name = (IName)workspaceName;
              ESRI.ArcGIS.Geodatabase.IWorkspace inmemWor = (IWorkspace)name.Open();

              IField oField = new FieldClass();
              IFields oFields = new FieldsClass();
              IFieldsEdit oFieldsEdit = null;
              IFieldEdit oFieldEdit = null;
              IFeatureClass oFeatureClass = null;
              IFeatureLayer oFeatureLayer = null;

              try
              {
                  oFieldsEdit = oFields as IFieldsEdit;
                  oFieldEdit = oField as IFieldEdit;
                  if (PropertyFields != null)
                  {
                      for (int i = 0; i < PropertyFields.FieldCount; i++)
                      {
                          oFieldsEdit.AddField(PropertyFields.get_Field(i));
                      }
                  }

                  IGeometryDef geometryDef = new GeometryDefClass();
                  IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
                  geometryDefEdit.AvgNumPoints_2 = 5;
                  geometryDefEdit.GeometryType_2 = GeometryType;
                  geometryDefEdit.GridCount_2 = 1;
                  geometryDefEdit.HasM_2 = false;
                  geometryDefEdit.HasZ_2 = false;
                  geometryDefEdit.SpatialReference_2 = SpatialRef;
                  geometryDefEdit.SpatialReference_2 = new UnknownCoordinateSystemClass();//没有这一句就报错,说尝试读取或写入受保护的内存。
                  geometryDefEdit.SpatialReference.SetDomain(-450359962737.05, 450359962737.05, -450359962737.05, 450359962737.05);//没有这句就抛异常来自HRESULT:0x8004120E。

                  oFieldEdit.Name_2 = "SHAPE";
                  oFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                  oFieldEdit.GeometryDef_2 = geometryDef;
                  oFieldEdit.IsNullable_2 = true;
                  oFieldEdit.Required_2 = true;
                  oFieldsEdit.AddField(oField);

                  oFeatureClass = (inmemWor as IFeatureWorkspace).CreateFeatureClass(DataSetName, oFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
                  (oFeatureClass as IDataset).BrowseName = DataSetName;

                  oFeatureLayer = new FeatureLayerClass();
                  oFeatureLayer.Name = AliaseName;
                  oFeatureLayer.FeatureClass = oFeatureClass;
              }
              catch (Exception ex)
              {
              }
              finally
              {
                  try
                  {
                      System.Runtime.InteropServices.Marshal.ReleaseComObject(oField);
                      System.Runtime.InteropServices.Marshal.ReleaseComObject(oFields);
                      System.Runtime.InteropServices.Marshal.ReleaseComObject(oFieldsEdit);
                      System.Runtime.InteropServices.Marshal.ReleaseComObject(oFieldEdit);
                      System.Runtime.InteropServices.Marshal.ReleaseComObject(name);
                      System.Runtime.InteropServices.Marshal.ReleaseComObject(workspaceFactory);
                      System.Runtime.InteropServices.Marshal.ReleaseComObject(workspaceName);
                      System.Runtime.InteropServices.Marshal.ReleaseComObject(inmemWor);
                      System.Runtime.InteropServices.Marshal.ReleaseComObject(oFeatureClass);
                  }
                  catch { }

                  GC.Collect();
              }
              return oFeatureLayer;
        }
Exemplo n.º 36
0
        private string get_SIDFieldName(IFields f1, IFields f2, string sidSuffix)
        {
            string theReturn = "";

            for (int i = 0; i < f1.FieldCount; i++)
            {
                string name = f1.get_Field(i).Name;
                if (name.EndsWith(sidSuffix))
                {
                    // Find a field with the same name in the table
                    int theTableIdx = f2.FindField(name);
                    if (theTableIdx >= 0)
                    {
                        theReturn = name;
                        break;
                    }
                }
            }

            return theReturn;
        }
Exemplo n.º 37
0
        private esriGeometryType GetGeometryTypeFromFields(IFields fields)
        {
            IField field = null;
            for (int i = 0; i < fields.FieldCount; i++)
            {
                field = fields.get_Field(i);
                if (field.Type == esriFieldType.esriFieldTypeGeometry)
                {
                    return field.GeometryDef.GeometryType;
                }
            }

            throw new InvalidOperationException("Unable to locate geometry field for requested layer index.");
        }
        private static void setFeatureSpatialReference(IFeatureLayer ifl_active, IName name, out IFeatureWorkspace workspace, out IWorkspaceEdit iwe, out IFields flds)
        {
            IGeoDataset igd_dest = (IGeoDataset)ifl_active.FeatureClass;
            // Open the workspace through the name object.
            workspace = (IFeatureWorkspace)name.Open();
            iwe = (IWorkspaceEdit)workspace;

            ESRI.ArcGIS.Geodatabase.IObjectClassDescription objectClassDescription = new ESRI.ArcGIS.Geodatabase.FeatureClassDescriptionClass();
            flds = objectClassDescription.RequiredFields;
            IFieldEdit fld_Edit = (IFieldEdit)flds.get_Field(flds.FindField("Shape"));

            IGeometryDefEdit pGeoDef = (IGeometryDefEdit)fld_Edit.GeometryDef;
            pGeoDef.SpatialReference_2 = igd_dest.SpatialReference;
        }
 private void cmbSampleFeatureClass_SelectedIndexChanged(object sender, EventArgs e)
 {
     string cmbTxt = cmbSampleFeatureClass.Text;
     if (cmbTxt == null || cmbTxt == "")
     {
         return;
     }
     ITable ftrCls = ftrDic[cmbTxt];
     flds = ftrCls.Fields;
     cmbDepedent.Text = "";
     cmbDepedent.Items.Clear();
     cmbIndependent.Items.Clear();
     lstIndependent.Items.Clear();
     for (int i = 0; i < flds.FieldCount; i++)
     {
         IField fld = flds.get_Field(i);
         string fldNm = fld.Name;
         esriFieldType fldType = fld.Type;
         if (fldType != esriFieldType.esriFieldTypeBlob && fldType != esriFieldType.esriFieldTypeDate && fldType != esriFieldType.esriFieldTypeGeometry && fldType != esriFieldType.esriFieldTypeGlobalID && fldType != esriFieldType.esriFieldTypeXML && fldType != esriFieldType.esriFieldTypeGUID && fldType != esriFieldType.esriFieldTypeOID && fldType != esriFieldType.esriFieldTypeRaster)
         {
             cmbIndependent.Items.Add(fldNm);
             cmbDepedent.Items.Add(fldNm);
         }
     }
 }
 private void cmbSampleFeatureClass_SelectedIndexChanged(object sender, EventArgs e)
 {
     string cmbTxt = cmbSampleFeatureClass.Text;
     if (cmbTxt == "" || cmbTxt == null)
     {
         return;
     }
     if (ftrDic.ContainsKey(cmbTxt))
     {
         gpSelection.Enabled = true;
         lstIndependent.Enabled = true;
         cmbIndependent.Enabled = true;
         ITable ftrCls = ftrDic[cmbTxt];
         flds = ftrCls.Fields;
         btnStrataRst.Visible = false;
         cmbIndependent.Items.Clear();
         lstIndependent.Items.Clear();
         cmbStrataField.Items.Clear();
         lblStrat.Text = "Groups Field";
         for (int i = 0; i < flds.FieldCount; i++)
         {
             IField fld = flds.get_Field(i);
             string fldNm = fld.Name;
             esriFieldType fldType = fld.Type;
             if (fldType != esriFieldType.esriFieldTypeBlob && fldType != esriFieldType.esriFieldTypeDate && fldType != esriFieldType.esriFieldTypeGeometry && fldType != esriFieldType.esriFieldTypeGlobalID && fldType != esriFieldType.esriFieldTypeXML && fldType != esriFieldType.esriFieldTypeGUID && fldType != esriFieldType.esriFieldTypeOID && fldType != esriFieldType.esriFieldTypeRaster)
             {
                 cmbIndependent.Items.Add(fldNm);
                 cmbStrataField.Items.Add(fldNm);
             }
         }
     }
     else
     {
         lblStrat.Text = "Groups Raster";
         btnStrataRst.Visible = true;
         cmbIndependent.Items.Clear();
         lstIndependent.Items.Clear();
         cmbStrataField.Items.Clear();
         cmbIndependent.Enabled = false;
         lstIndependent.Enabled = false;
         gpSelection.Enabled = false;
         foreach (string s in rstDic.Keys)
         {
             cmbStrataField.Items.Add(s);
         }
     }
 }
        /// <summary>
        /// creates a new featrue class
        /// </summary>
        /// <param name="wks">the workspace to create from</param>
        /// <param name="polyFtrClsName">name of the feature class</param>
        /// <param name="atrflds">name of the fields</param>
        /// <param name="geoType">the geotype</param>
        /// <param name="sr">spatial reference</param>
        /// <returns>newly created featureclass</returns>
        public IFeatureClass createFeatureClass(IWorkspace2 wks, string polyFtrClsName, IFields atrflds, esriGeometryType geoType, ISpatialReference sr)
        {
            IFeatureClass tFtr = null;
            try
            {
                IFeatureWorkspace ftrWks = (IFeatureWorkspace)wks;
                polyFtrClsName = getSafeOutputNameNonRaster((IWorkspace)wks, polyFtrClsName);
                IFeatureClassDescription fcDescription = new FeatureClassDescriptionClass();
                IObjectClassDescription ocDescription = (IObjectClassDescription)fcDescription;
                IFields fields = ocDescription.RequiredFields;
                if (atrflds != null)
                {
                    IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
                    for (int i = 0; i < atrflds.FieldCount; i++)
                    {
                        IField fld = atrflds.get_Field(i);
                        IField nFld = new FieldClass();
                        IFieldEdit nFldE = (IFieldEdit)nFld;
                        nFldE.Name_2 = fld.Name;
                        if (fld.Type != esriFieldType.esriFieldTypeOID)
                        {
                            nFldE.Type_2 = fld.Type;
                            fieldsEdit.AddField(nFld);
                        }
                    }
                }
                // Find the shape field in the required fields and modify its GeometryDef to// use point geometry and to set the spatial reference.int shapeFieldIndex = fields.FindField(fcDescription.ShapeFieldName);
                IField field = fields.get_Field(fields.FindField(fcDescription.ShapeFieldName));
                IGeometryDef geometryDef = field.GeometryDef;
                IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
                geometryDefEdit.GeometryType_2 = geoType;
                geometryDefEdit.SpatialReference_2 = sr;

                // Use IFieldChecker to create a validated fields collection.
                IFieldChecker fieldChecker = new FieldCheckerClass();
                IEnumFieldError enumFieldError = null;
                IFields validatedFields = null;
                fieldChecker.ValidateWorkspace = (IWorkspace)wks;
                fieldChecker.Validate(fields, out enumFieldError, out validatedFields);
                tFtr = ftrWks.CreateFeatureClass(polyFtrClsName, validatedFields, ocDescription.InstanceCLSID, ocDescription.ClassExtensionCLSID, esriFeatureType.esriFTSimple, fcDescription.ShapeFieldName, "");
            }
            catch(Exception e)
            {
                Console.WriteLine("Error: " + e.ToString());
            }
            return tFtr;
        }
 private int fieldExist(IFields flds, string fldName)
 {
     int x = -1;
     for (int i = 0; i < flds.FieldCount; i++)
     {
         if (flds.get_Field(i).Name.ToLower().StartsWith(fldName.ToLower().Replace("*","")))
         {
             x = i;
             break;
         }
     }
     return x;
 }
        public ITable createTable(IWorkspace wks, string tableName, IFields atrflds)
        {
            IWorkspace2 wks2 = (IWorkspace2)wks;
            IFeatureWorkspace ftrWks = (IFeatureWorkspace)wks;
            ITable tbl = null;
            try
            {

                if (wks2.get_NameExists(esriDatasetType.esriDTTable, tableName))
                {
                    return tbl;
                }

                IObjectClassDescription ocDescription = new ObjectClassDescriptionClass();
                IFields fields = ocDescription.RequiredFields;
                IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
                if (atrflds != null)
                {
                    for (int i = 0; i < atrflds.FieldCount; i++)
                    {
                        IField fld = atrflds.get_Field(i);
                        fieldsEdit.AddField(fld);
                    }
                }
                // Use IFieldChecker to create a validated fields collection.
                IFieldChecker fieldChecker = new FieldCheckerClass();
                IEnumFieldError enumFieldError = null;
                IFields validatedFields = null;
                fieldChecker.ValidateWorkspace = (IWorkspace)wks;
                fieldChecker.Validate(fields, out enumFieldError, out validatedFields);
                tbl = ftrWks.CreateTable(tableName, validatedFields, ocDescription.InstanceCLSID, ocDescription.ClassExtensionCLSID, "");
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.ToString());
            }
            return tbl;
        }
Exemplo n.º 44
0
        /// <summary>
        /// ��ȡ����
        /// </summary>
        /// <param name="ipSourceRow">�м�</param>
        /// <param name="ipMatchEdgeFields">�ֶμ�</param>
        /// <param name="nFieldArray">Ҫ���˵��ֶ�����</param>
        /// <returns></returns>
        private string GetCondition(IRow ipSourceRow, IFields ipMatchEdgeFields, List<int> nFieldArray)
        {
            //�������Բ�ѯ����
            string sMatchEdgeFieldValue = "";
            string sMatchEdgeWhereClause = "";
            esriFieldType eMatchEdgeFieldType;
            object vtFieldValue;
            IField ipMatchEdgeField = null;
            Int64 nFieldCount = nFieldArray.Count;

            string strFieldName;

            int nFieldIndex = 0;

            for (int i = 0; i < nFieldCount; i++)
            {
                nFieldIndex = nFieldArray[i];
                vtFieldValue = ipSourceRow.get_Value(nFieldIndex);
                ipMatchEdgeField = ipMatchEdgeFields.get_Field(nFieldIndex);
                string bstrFieldName = ipMatchEdgeField.Name;

                strFieldName = bstrFieldName;
                eMatchEdgeFieldType = ipMatchEdgeField.Type;
                switch (eMatchEdgeFieldType)
                {
                    case esriFieldType.esriFieldTypeSmallInteger:
                        sMatchEdgeFieldValue = vtFieldValue.ToString();
                        sMatchEdgeWhereClause += strFieldName + " = " + sMatchEdgeFieldValue;
                        break;
                    case esriFieldType.esriFieldTypeInteger:
                        sMatchEdgeFieldValue = vtFieldValue.ToString();
                        sMatchEdgeWhereClause += strFieldName + " = " + sMatchEdgeFieldValue;
                        break;
                    case esriFieldType.esriFieldTypeSingle:
                        sMatchEdgeFieldValue = vtFieldValue.ToString();
                        sMatchEdgeWhereClause += strFieldName + " = " + sMatchEdgeFieldValue;
                        break;
                    case esriFieldType.esriFieldTypeDouble:
                        sMatchEdgeFieldValue = vtFieldValue.ToString();
                        sMatchEdgeWhereClause += strFieldName + " = " + sMatchEdgeFieldValue;
                        break;
                    case esriFieldType.esriFieldTypeString:
                        sMatchEdgeFieldValue = vtFieldValue.ToString();
                        sMatchEdgeWhereClause += strFieldName + " = '" + sMatchEdgeFieldValue + "'";
                        break;
                    default:
                        break;
                }
                //	sMatchEdgeWhereClause += string(bsFieldName) + " = '" + sMatchEdgeFieldValue + "'";
                if (i != (nFieldCount - 1))
                {
                    sMatchEdgeWhereClause += " and ";
                }
            }

            return sMatchEdgeWhereClause;
        }
Exemplo n.º 45
0
        /// <summary>
        /// 创建注记层
        /// </summary>
        /// <param name="strFeaClsName">注记层名称</param>
        /// <param name="destDataset">待创建的注记层所在的featuredataset</param>
        /// <param name="ipInputFields">注记层字段</param>
        public static IFeatureClass CreateAnnotation(IFeatureClass pInputCls, IFeatureDataset destDataset, IFields ipInputFields)
        {
            try
            {
                //要素类标识信息
                IObjectClassDescription ipObjectClassDesc = new AnnotationFeatureClassDescription();
                IFeatureClassDescription ipFeatClassDesc = (IFeatureClassDescription)ipObjectClassDesc;

                IAnnoClass pAnnoClass = pInputCls.Extension as IAnnoClass;
                double scale = pAnnoClass.ReferenceScale;

                IUID ipCLSID = ipObjectClassDesc.InstanceCLSID;
                ipCLSID.Value = "esriCore.AnnotationFeature";

                IUID ipExtCLSID = ipObjectClassDesc.ClassExtensionCLSID;
                ipExtCLSID.Value = "esriCore.AnnotationFeatureClassExtension";

                //IField ipField;
                IFields ipFields = ipObjectClassDesc.RequiredFields;
                IFieldsEdit ipFieldsEdit = (IFieldsEdit)ipFields;
                int numFields = ipInputFields.FieldCount;

                esriFieldType type;
                for (int i = 0; i < numFields; i++)
                {
                    IField ipField = ipInputFields.get_Field(i);
                    type = ipField.Type;
                    if (type != esriFieldType.esriFieldTypeOID && type != esriFieldType.esriFieldTypeGeometry)
                    {
                        string fldName = ipField.Name;
                        int fldIndex = ipFields.FindField(fldName);

                        if (fldIndex == -1)
                            ipFieldsEdit.AddField(ipField);
                    }
                }

                //工作空间
                IWorkspace ipWorkspace = destDataset.Workspace;
                IFeatureWorkspaceAnno ipFeatureWorkspaceAnno = (IFeatureWorkspaceAnno)ipWorkspace;

                //显示比例
                IGraphicsLayerScale ipGraphicsLayerScale = new GraphicsLayerScaleClass();
                ipGraphicsLayerScale.ReferenceScale = scale;
                ipGraphicsLayerScale.Units = pAnnoClass.ReferenceScaleUnits;

                //符号信息
                //' set up symbol collection
                ISymbolCollection pSymbolColl = new SymbolCollectionClass();

                ITextSymbol myTxtSym = new TextSymbolClass();
                //Set the font for myTxtSym
                stdole.IFontDisp myFont = new stdole.StdFontClass() as stdole.IFontDisp;
                IFont pFt = (IFont)myFont;
                pFt.Name = "Courier New";

                myTxtSym.Font = myFont;

                // Set the Color for myTxtSym to be Dark Red
                IRgbColor myColor = new RgbColorClass();
                myColor.Red = 150;
                myColor.Green = 0;
                myColor.Blue = 0;
                myTxtSym.Color = myColor;

                // Set other properties for myTxtSym
                myTxtSym.Angle = 0;
                myTxtSym.RightToLeft = false;
                myTxtSym.VerticalAlignment = esriTextVerticalAlignment.esriTVABaseline;
                myTxtSym.HorizontalAlignment = esriTextHorizontalAlignment.esriTHAFull;
                myTxtSym.Size = 9;

                ISymbol pSymbol = (ISymbol)myTxtSym;
                pSymbolColl.set_Symbol(0, pSymbol);

                //set up the annotation labeling properties including the expression
                IAnnotateLayerProperties pAnnoProps = new LabelEngineLayerPropertiesClass();
                pAnnoProps.FeatureLinked = true;
                pAnnoProps.AddUnplacedToGraphicsContainer = false;
                pAnnoProps.CreateUnplacedElements = true;
                pAnnoProps.DisplayAnnotation = true;
                pAnnoProps.UseOutput = true;

                ILabelEngineLayerProperties pLELayerProps = (ILabelEngineLayerProperties)pAnnoProps;
                IAnnotationExpressionEngine aAnnoVBScriptEngine = new AnnotationVBScriptEngineClass();
                pLELayerProps.ExpressionParser = aAnnoVBScriptEngine;
                pLELayerProps.Expression = "[DESCRIPTION]";
                pLELayerProps.IsExpressionSimple = true;
                pLELayerProps.Offset = 0;
                pLELayerProps.SymbolID = 0;
                pLELayerProps.Symbol = myTxtSym;

                IAnnotateLayerTransformationProperties pATP = (IAnnotateLayerTransformationProperties)pAnnoProps;
                double dRefScale = ipGraphicsLayerScale.ReferenceScale;
                pATP.ReferenceScale = dRefScale;
                pATP.Units = esriUnits.esriMeters;
                pATP.ScaleRatio = 1;

                IAnnotateLayerPropertiesCollection pAnnoPropsColl = new AnnotateLayerPropertiesCollectionClass();
                pAnnoPropsColl.Add(pAnnoProps);

                //' use the AnnotationFeatureClassDescription co - class to get the list of required fields and the default name of the shape field
                IObjectClassDescription pOCDesc = new AnnotationFeatureClassDescriptionClass();
                IFeatureClassDescription pFDesc = (IFeatureClassDescription)pOCDesc;

                IFields pReqFields = pOCDesc.RequiredFields;
                IUID pInstCLSID = pOCDesc.InstanceCLSID;
                IUID pExtCLSID = pOCDesc.ClassExtensionCLSID;
                string bsShapeFieldName = pFDesc.ShapeFieldName;

                IDataset pDs = (IDataset)pInputCls;

                //创建
                string bstName = ipFeatClassDesc.ShapeFieldName;
                IFeatureClass pOutFcls =
                    ipFeatureWorkspaceAnno.CreateAnnotationClass(pDs.Name, ipFields, pOCDesc.InstanceCLSID,
                                                                 pOCDesc.ClassExtensionCLSID, pInputCls.ShapeFieldName, "", destDataset, null, pAnnoPropsColl,
                                                                 ipGraphicsLayerScale, pSymbolColl, true);
                return pOutFcls;
            }
            catch(Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                return null;
            }
            return null;
        }
        private void cmbSampleFeatureClass_SelectedIndexChanged(object sender, EventArgs e)
        {
            string cmbTxt = cmbSampleFeatureClass.Text;
            if (cmbTxt == "" || cmbTxt == null)
            {
                return;
            }
            if (ftrDic.ContainsKey(cmbTxt))
            {
                gpSelection.Enabled = true;
                ITable ftrCls = ftrDic[cmbTxt];
                flds = ftrCls.Fields;

                cmbIndependent.Items.Clear();
                lstIndependent.Items.Clear();
                lstCategoricalFlds.Clear();
                for (int i = 0; i < flds.FieldCount; i++)
                {
                    IField fld = flds.get_Field(i);
                    string fldNm = fld.Name;
                    esriFieldType fldType = fld.Type;
                    if (fldType != esriFieldType.esriFieldTypeBlob && fldType != esriFieldType.esriFieldTypeDate && fldType != esriFieldType.esriFieldTypeGeometry && fldType != esriFieldType.esriFieldTypeGlobalID && fldType != esriFieldType.esriFieldTypeXML && fldType != esriFieldType.esriFieldTypeGUID && fldType != esriFieldType.esriFieldTypeOID && fldType != esriFieldType.esriFieldTypeRaster)
                    {
                        cmbIndependent.Items.Add(fldNm);
                        if (fldType == esriFieldType.esriFieldTypeString) lstCategoricalFlds.Add(fldNm);
                    }
                }
            }
            else
            {
                gpSelection.Enabled = false;
            }
        }
Exemplo n.º 47
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;
        }
Exemplo n.º 48
0
 public static IField QueryField(IFields pFields, string sName)
 {
     IField pField = null;
     int n = pFields.FindField(sName);
     if (n > -1)
     {
         pField = pFields.get_Field(n);
         return pField;
     }
     return pField;
 }
Exemplo n.º 49
0
        private List<FieldNode> GetFieldNodes(IFields pFields)
        {
            try
            {
                IFeatureClass pFeatureCls = this.m_pITable as IFeatureClass;
                List<FieldNode> pListFieldNode = new List<FieldNode>();

                for (int i = 0; i < pFields.FieldCount; i++)
                {
                    IField itemField = pFields.get_Field(i);
                        ///只保持属性字段
                    if (itemField.Type != esriFieldType.esriFieldTypeGeometry
                        && itemField.Type != esriFieldType.esriFieldTypeOID
                        && itemField.Name.ToUpper() != "SHAPE_LENGTH"
                        && itemField.Name.ToUpper() != "SHAPE_AREA"
                        )
                    {
                        if (pFeatureCls != null && pFeatureCls.FeatureType == esriFeatureType.esriFTAnnotation)
                        {
                            AddAnnotationFieldNode(itemField, pListFieldNode);
                        }
                        else
                        {
                            string sLine = "";
                            if (itemField.Precision != null && itemField.Precision != 0)
                                sLine = itemField.Name + HeadNode.Separator
                                 + GetVCTFieldType(itemField.Type) + HeadNode.Separator
                                  + itemField.Length + HeadNode.Separator
                                   + itemField.Precision;
                            else
                                sLine = itemField.Name + HeadNode.Separator
                                + GetVCTFieldType(itemField.Type) + HeadNode.Separator
                                 + itemField.Length;
                            FieldNode pFieldNode = new FieldNode(sLine);
                            pListFieldNode.Add(pFieldNode);
                        }
                    }
                }
                return pListFieldNode;

            }
            catch (Exception ex)
            {
                LogAPI.WriteErrorLog(ex);
                return null;
            }
        }
 private void cmbSampleFeatureClass_SelectedIndexChanged(object sender, EventArgs e)
 {
     string cmbTxt = cmbSampleFeatureClass.Text;
     if (cmbTxt == "" || cmbTxt == null)
     {
         return;
     }
     IFeatureClass ftrCls = ftrDic[cmbTxt];
     flds = ftrCls.Fields;
     cmbMap.Text = "";
     cmbMap.Items.Clear();
     cmbRef.Items.Clear();
     cmbWeight.Items.Clear();
     lstCategoricalFlds.Clear();
     for (int i = 0; i < flds.FieldCount; i++)
     {
         IField fld = flds.get_Field(i);
         string fldNm = fld.Name;
         esriFieldType fldType = fld.Type;
         if (fldType != esriFieldType.esriFieldTypeBlob && fldType != esriFieldType.esriFieldTypeDate && fldType != esriFieldType.esriFieldTypeGeometry && fldType != esriFieldType.esriFieldTypeGlobalID && fldType != esriFieldType.esriFieldTypeXML && fldType != esriFieldType.esriFieldTypeGUID && fldType != esriFieldType.esriFieldTypeOID && fldType != esriFieldType.esriFieldTypeRaster)
         {
             cmbMap.Items.Add(fldNm);
             cmbRef.Items.Add(fldNm);
             if (fldType == esriFieldType.esriFieldTypeString)
             {
                 lstCategoricalFlds.Add(fldNm);
             }
             else
             {
                 cmbWeight.Items.Add(fldNm);
             }
         }
     }
 }
Exemplo n.º 51
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;
        }