private static ITable CreateTable(IWorkspace2 workspace, string tableName, IFields fields)
        {
            UID uid = new UIDClass {Value = "esriGeoDatabase.Object"};

            if (workspace == null) return null;

            IFeatureWorkspace featWorkspace = (IFeatureWorkspace) workspace;

            if (workspace.NameExists[esriDatasetType.esriDTTable, tableName])
            {
                using (ComReleaser releaser = new ComReleaser())
                {
                    ITable table = featWorkspace.OpenTable(tableName);
                    releaser.ManageLifetime(table);
                    ((IDataset) table).Delete();
                }
            }


            IFieldChecker fieldChecker = new FieldCheckerClass();
            IEnumFieldError enumFieldError = null;
            IFields validatedFields = null;
            fieldChecker.ValidateWorkspace = workspace as IWorkspace;
            fieldChecker.Validate(fields, out enumFieldError, out validatedFields);

            return featWorkspace.CreateTable(tableName, validatedFields, uid, null, string.Empty);
        }
		public SimplePointCursor(string filePath, IFields fields, int OID, 
			System.Array fieldMap, IEnvelope queryEnv, esriGeometryType geomType)	
		{
			//HIGHLIGHT: 0 - Set up cursor
			m_bIsFinished = false;
			m_pStreamReader = new System.IO.StreamReader(filePath);
			m_fields = fields;
			m_iOID = OID;
			m_fieldMap = fieldMap;
			m_searchEnv = queryEnv;
			switch (geomType)
			{
				case esriGeometryType.esriGeometryPolygon:
					m_wkGeom = new Polygon() as IGeometry;
					m_workPts = new PointClass[5];
					for (int i = 0; i < m_workPts.Length; i++)
						m_workPts[i] = new PointClass();
					break;
				case esriGeometryType.esriGeometryPolyline:
					m_wkGeom = new PolylineClass() as IGeometry;
					m_workPts = new PointClass[5];
					for (int i = 0; i < m_workPts.Length; i++)
						m_workPts[i] = new PointClass();
					break;
				
				case esriGeometryType.esriGeometryPoint:
					m_wkGeom = new PointClass() as IGeometry;
					break;
				default:	//doesn't need to set worker geometry if it is table 
					break;
			}

			//advance cursor so data is readily available
			this.NextRecord();
		}
Exemplo n.º 3
0
        public void WakeUpComputer(IFields fields)
        {
            if (String.IsNullOrEmpty(fields.DnsName) || String.IsNullOrEmpty(fields.MacAddress))
            {
                UpdateStatusLabel(fields, String.Format(Resources.en_US.ERROR_EMPTY_FIELDS, Environment.NewLine), true);
                return;
            }

            GetLeasedIpAddressOfDns(fields);
        }
Exemplo n.º 4
0
        private bool CopyFilesToRemoteIpAddress(IFields fields, string remoteIp)
        {
            if (remoteIp == null)
                return false;

            string remotePath = @"\\" + remoteIp + @"\C$\Temp\";
            string remoteFolder = remotePath + "WakeOnLan";

            try
            {
                UpdateStatusLabel(fields, "Trying To Accessing Directory On " + remoteIp);

                // Check is there is access to the remote IP's C drive
                DirectorySecurity dirSec = Directory.GetAccessControl(remotePath);

                // Creates remote directory
                DirectoryInfo dirInfo = Directory.CreateDirectory(remoteFolder);

                try
                {
                    string remoteWolPath = remoteFolder + @"\" + Resources.Executables.EXECUTABLE_NAME_WOL;
                    string localPsExecPath = Environment.CurrentDirectory + @"\" + Resources.Executables.EXECUTABLE_NAME_PSEXEC;

                    UpdateStatusLabel(fields, "Writing Files To Remote Directory On " + remoteIp);

                    // Write wol.exe to remote computer
                    File.WriteAllBytes(remoteWolPath, Resources.Executables.wol);

                    // Write PsExec.exe to local computer
                    File.WriteAllBytes(localPsExecPath, Resources.Executables.PsExec);

                    // Executing remote wol.exe
                    RemoteRunWol(fields, remoteIp, localPsExecPath);
                }
                catch (Exception)
                {
                    // When writing wol.exe fails
                    MessageBox.Show("Error copying file");
                    return false;
                }

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
Exemplo n.º 5
0
 private void CbBox_TargetLayer_SelectedIndexChanged(object sender, EventArgs e)
 {
     LstBox_FieldName.Items.Clear();
     pSelectedFeatureLayer = m_pCurMap.get_Layer(CbBox_TargetLayer.SelectedIndex) as IFeatureLayer;
     pFields = pSelectedFeatureLayer.FeatureClass.Fields;
     for (int i = 0; i < pFields.FieldCount; i++)
     {
         if (pFields.get_Field(i).Type != esriFieldType.esriFieldTypeGeometry &&
             pFields.get_Field(i).Type != esriFieldType.esriFieldTypeOID)
         {
             LstBox_FieldName.Items.Add('\"' + pFields.get_Field(i).Name + '\"');
         }
     }
     if (LstBox_FieldName.Items.Count != 0)
     {
         pField = pFields.get_Field(pFields.FindField(LstBox_FieldName.Items[0].ToString().Split('\"')[1]));
         LstBox_FieldName.SelectedIndex = 0;
     }
 }
Exemplo n.º 6
0
        private void ReLoadRasterLayerTable(ILayer layer)
        {
            if (!(layer is IRasterLayer))
            {
                return;
            }

            IRasterLayer rasterLayer = layer as IRasterLayer;

            if (rasterLayer.BandCount != 1)
            {
                MessageBox.Show("只有单波段短整型栅格数据才具有属性表", "提示", MessageBoxButtons.OK);
                return;
            }

            ITable table = LibCerMap.ClsGDBDataCommon.GetTableofLayer(rasterLayer);

            if (table == null)
            {
                return;
            }

            IFields fields = table.Fields;

            //添加字段列
            for (int i = 0; i < fields.FieldCount; i++)
            {
                m_AttributeTable.Columns.Add();
                m_AttributeTable.Columns[i].ColumnName = fields.Field[i].Name;
            }
            ICursor cursor = table.Search(null, false);
            IRow    row    = null;

            while ((row = cursor.NextRow()) != null)
            {
                DataRow dataRow = m_AttributeTable.NewRow();
                for (int i = 0; i < fields.FieldCount; i++)
                {
                    dataRow[i] = row.get_Value(i);
                }
                m_AttributeTable.Rows.Add(dataRow);
            }
        }
Exemplo n.º 7
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());
            }
        }
        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);
            }
        }
        //用帮助里的例子,修改了字段和空间参考
        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);
        }
        /// <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.º 11
0
        private IFeatureLayer CreateSHP_Point(List <Point3D> PointList, string FileFullPath)
        {
            int               index     = FileFullPath.LastIndexOf("\\");
            string            filename  = System.IO.Path.GetFileNameWithoutExtension(FileFullPath);
            string            shpFolder = System.IO.Path.GetDirectoryName(FileFullPath);
            IWorkspaceFactory shpWSF    = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace shpFWS    = (IFeatureWorkspace)shpWSF.OpenFromFile(WorkSpaceName, 0);
            //建立基本属性表
            IFields pFields = CreateShapeFields(esriGeometryType.esriGeometryPoint);

            IFeatureClass pFeatureClass;
            string        filename_shp = WorkSpaceName + @"/" + filename + ".shp";

            if (System.IO.File.Exists(filename_shp))
            {
                System.IO.File.Delete(filename_shp);
                System.IO.File.Delete(System.IO.Path.ChangeExtension(filename_shp, ".dbf"));
                System.IO.File.Delete(System.IO.Path.ChangeExtension(filename_shp, ".shx"))
                ;
            }
            pFeatureClass = shpFWS.CreateFeatureClass(filename, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");


            for (int j = 0; j < PointList.Count; j++)
            {
                IPoint pPoint = new PointClass();
                pPoint.X = PointList[j].X;
                pPoint.Y = PointList[j].Y;
                IFeature pFeature = pFeatureClass.CreateFeature();
                pFeature.Shape = pPoint as IGeometry;
                pFeature.Store();
            }

            //完善属性表
            Complete_PropertyTable(ref pFeatureClass, PointList);

            IFeatureLayer pFeatureLayer = new FeatureLayerClass();

            pFeatureLayer.Name         = filename;
            pFeatureLayer.FeatureClass = pFeatureClass;
            return(pFeatureLayer);
        }
Exemplo n.º 12
0
        private void btnQuery_Click(object sender, EventArgs e)
        {
            dataGridViewR.Rows.Clear();
            if (txtDM.Text == "")
            {
                MessageBox.Show("请输入查询信息!", "提示",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            IQueryFilter pQFilter = new QueryFilterClass();
            string       strWhere = "DM LIKE '%" + txtDM.Text.Trim() + "%'";

            pQFilter.WhereClause = strWhere;
            IFeatureClass  pFClass  = pFLayer.FeatureClass;
            IFields        pFields  = pFClass.Fields;
            IFeatureCursor pFCursor = pFClass.Search(pQFilter, false);
            IFeature       pFeature = pFCursor.NextFeature();
            int            orderNO  = 0;

            while (pFeature != null)
            {
                //DataGridViewRow pDGVR = new DataGridViewRow();
                dataGridViewR.Rows.Add();
                //pLVI.Tag = pFeature.OID;
                for (int i = 0, j = 0; i < pFields.FieldCount; i++, j++)
                {
                    if (pFields.get_Field(i).Type == esriFieldType.esriFieldTypeGeometry ||
                        pFields.get_Field(i).Name == "DM")
                    {
                        j--;
                        continue;
                    }

                    dataGridViewR.Rows[orderNO].Cells[j].Value = pFeature.get_Value(i);
                }

                pFeature = pFCursor.NextFeature();
                orderNO++;
            }
            dataGridViewR.Refresh();
        }
Exemplo n.º 13
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));
         }
     }
 }
Exemplo n.º 14
0
        public static void TextElementLabel(IMapControl2 mapControl, IFeatureLayer featureLayer, string fieldName)
        {
            IMap pMap = mapControl.Map;
            // 获取图层所有要素
            IFeatureCursor pFeatureCursor = featureLayer.FeatureClass.Search(null, false);
            IFeature       pFeature       = pFeatureCursor.NextFeature();

            while (pFeature != null)
            {
                IFields pFields = pFeature.Fields;
                // 找出标注字段的索引号
                int index = pFields.FindField(fieldName);
                // 得到要素的Envelope对象
                IEnvelope pEnv   = pFeature.Extent;
                IPoint    pPoint = new PointClass()
                {
                    X = pEnv.XMin + pEnv.Width / 2,
                    Y = pEnv.YMin + pEnv.Height / 2
                };
                // 新建字体对象
                stdole.IFontDisp pFont = new stdole.StdFontClass() as stdole.IFontDisp;
                pFont.Name = "arial";
                // 设置文本符号
                ITextSymbol pTextSymbol = new TextSymbolClass()
                {
                    Size  = 20,
                    Font  = pFont,
                    Color = AeUtils.GetRgbColor(255, 0, 0)
                };
                // 添加文本对象
                IElement pTextElement = new TextElementClass()
                {
                    Text      = pFeature.get_Value(index).ToString(),
                    ScaleText = true,
                    Symbol    = pTextSymbol
                };
                pTextElement.Geometry = pPoint;
                (pMap as IGraphicsContainer).AddElement(pTextElement, 0);
                mapControl.Refresh(esriViewDrawPhase.esriViewGraphics);
                pFeature = pFeatureCursor.NextFeature();
            }
        }
Exemplo n.º 15
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);
                        }
                    }
                }
            }
        }
Exemplo n.º 16
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.º 17
0
        /// <summary>
        /// 根据参考注记层新建注记层
        /// </summary>
        /// <param name="targetName">创建注记图层的名称</param>
        /// <param name="pTargetWrksps">目标工作空间</param>
        /// <param name="pTargetDs">所属目标数据集</param>
        /// <param name="pRefAnnoFtCls">参考图层</param>
        /// <returns></returns>
        private static IFeatureClass CreateAnnotationClass(string targetName, IFeatureWorkspace pTargetWrksps, IFeatureDataset pTargetDs, IFeatureClass pRefAnnoFtCls, out string msg)
        {
            msg = "";
            try
            {
                IFeatureWorkspaceAnno pAnnoWrksps = pTargetWrksps as IFeatureWorkspaceAnno;
                if (pAnnoWrksps == null || pRefAnnoFtCls == null)
                {
                    return(null);
                }
                if (pRefAnnoFtCls.Extension is IAnnotationClassExtension pAnnoExten)
                {
                    IClone pClone = pAnnoExten.AnnoProperties as IClone;
                    IAnnotateLayerPropertiesCollection pAnnoProCol = (IAnnotateLayerPropertiesCollection)pClone.Clone();

                    esriUnits           eUnits    = pAnnoExten.ReferenceScaleUnits;
                    double              dbScale   = pAnnoExten.ReferenceScale;
                    IGraphicsLayerScale pGraScale = new GraphicsLayerScaleClass
                    {
                        ReferenceScale = dbScale,
                        Units          = eUnits
                    };
                    pClone = pAnnoExten.SymbolCollection as IClone;
                    ISymbolCollection pSymbolCol = (ISymbolCollection)pClone.Clone();

                    pClone = pRefAnnoFtCls.Fields as IClone;
                    IFields pFields = (IFields)pClone.Clone();

                    IObjectClassDescription pOCDesc = new AnnotationFeatureClassDescriptionClass();

                    IDataset pDs = (IDataset)pRefAnnoFtCls;
                    return(pAnnoWrksps.CreateAnnotationClass(targetName, pFields, pOCDesc.InstanceCLSID, pOCDesc.ClassExtensionCLSID, pRefAnnoFtCls.ShapeFieldName,
                                                             null, pTargetDs, null, pAnnoProCol, pGraScale, pSymbolCol, false));
                }
                return(null);
            }
            catch (Exception ex)
            {
                msg = ex.Message;
                return(null);
            }
        }
Exemplo n.º 18
0
        public bool AddField(string fieldName, esriFieldType filedType, int fieldLength)
        {
            //var featureLayer = axMapControl1.get_Layer(0) as IFeatureLayer;

            try
            {
                if (_layer != null)
                {
                    IFields pFields = _layer.FeatureClass.Fields;
                }

                IFieldEdit pFieldEdit = new FieldClass();

                pFieldEdit.Name_2 = fieldName.Length > 5 ? fieldName.Substring(0, 5) : fieldName;

                pFieldEdit.Type_2 = filedType;

                pFieldEdit.Editable_2 = true;

                pFieldEdit.AliasName_2 = fieldName;

                pFieldEdit.Length_2 = fieldLength;

                ITable pTable = (ITable)_layer;

                if (pTable != null)
                {
                    pTable.AddField(pFieldEdit);
                }

                ShowFeatureLayerAttrib(_layer);

                return(true);
            }


            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(false);
            }
        }
Exemplo n.º 19
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.º 20
0
        public static ITable CreateObjectClass(IWorkspace workspace, String className, IFields fields)
        {
            IFeatureWorkspace       featureWorkspace = (IFeatureWorkspace)workspace;
            IObjectClassDescription ocDescription    = new ObjectClassDescriptionClass();

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

            fieldChecker.ValidateWorkspace = 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.
            ITable table = featureWorkspace.CreateTable(className, validatedFields,
                                                        ocDescription.InstanceCLSID, null, "");

            return(table);
        }
Exemplo n.º 21
0
 private void cbField1_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (cbField2.Enabled == true)
     {
         cbField2.Items.Clear();
         IFeatureLayer featureLayer  = (IFeatureLayer)getLayersByName(cbLayer.Text);
         IFeatureClass pFeatureClass = featureLayer.FeatureClass;
         IFields       pFields       = pFeatureClass.Fields;
         for (int i = 0; i < pFields.FieldCount; i++)
         {
             // MessageBox.Show(pFields.get_Field(i).Name + ":" + pFields.get_Field(i).Type);
             //设置筛选条件为只能是int类型的字段而且去除掉cbfield1已经选过的字段
             if ((pFields.get_Field(i).Type == esriFieldType.esriFieldTypeDouble) &&
                 (!pFields.get_Field(i).Name.Equals(cbField1.Text)))
             {
                 cbField2.Items.Add(pFields.get_Field(i).Name);
             }
         }
     }
 }
        private IFeatureClass CreateFeatureClass([NotNull] string name,
                                                 esriGeometryType type,
                                                 bool zAware = false)
        {
            ISpatialReference sref = SpatialReferenceUtils.CreateSpatialReference
                                         ((int)esriSRProjCS2Type.esriSRProjCS_CH1903Plus_LV95,
                                         true);

            SpatialReferenceUtils.SetXYDomain(sref, -10000, -10000, 10000, 10000,
                                              0.0001, 0.001);

            IFields fields = FieldUtils.CreateFields(
                FieldUtils.CreateOIDField(),
                FieldUtils.CreateShapeField(
                    "Shape",
                    type,
                    sref, 1000, zAware));

            return(DatasetUtils.CreateSimpleFeatureClass(_testWs, name, fields));
        }
Exemplo n.º 23
0
        public IFeatureClass CreateFeatureDatasetFeatureClass(IFeatureDataset featureDataset, String featureClassName, IFields fieldsCollection, esriFeatureType featureType, String shapeFieldName)
        {
            IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass();
            IObjectClassDescription  ocDesc = (IObjectClassDescription)fcDesc;

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

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

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

            return(featureClass);
        }
Exemplo n.º 24
0
        public override IFields GetFields()
        {
            IObjectClassDescription objectClassDescription = new ObjectClassDescription();
            IFields requiredFields = objectClassDescription.RequiredFields;

            (requiredFields as IFieldsEdit).AddField(base.CreateStringField(
                                                         this.zdregisterTable_0.FeatureClassNameField, this.zdregisterTable_0.FeatureClassNameField, 150));
            (requiredFields as IFieldsEdit).AddField(base.CreateStringField(this.zdregisterTable_0.ZDBHFieldName,
                                                                            this.zdregisterTable_0.ZDBHFieldName, 30));
            (requiredFields as IFieldsEdit).AddField(base.CreateDateField(this.zdregisterTable_0.RegisterDateFieldName,
                                                                          this.zdregisterTable_0.RegisterDateFieldName));
            (requiredFields as IFieldsEdit).AddField(base.CreateStringField(this.zdregisterTable_0.GDBConnectInfoName,
                                                                            this.zdregisterTable_0.GDBConnectInfoName, 150));
            (requiredFields as IFieldsEdit).AddField(base.CreateStringField(this.zdregisterTable_0.GuidName,
                                                                            this.zdregisterTable_0.GuidName, 80));
            (requiredFields as IFieldsEdit).AddField(
                base.CreateStringField(this.zdregisterTable_0.HistoryFeatureClassName,
                                       this.zdregisterTable_0.HistoryFeatureClassName, 150));
            return(requiredFields);
        }
Exemplo n.º 25
0
 /// <summary>
 /// 初始化Tab表
 /// </summary>
 /// <param name="pDataGridView"></param>
 /// <param name="strTable"></param>
 public static void GetTable(DevComponents.DotNetBar.Controls.DataGridViewX pDataGridView, string strTable)
 {
     try
     {
         IFeatureWorkspace pFeatureWorkspace = m_Workspace as IFeatureWorkspace;
         ITable            pTable            = pFeatureWorkspace.OpenTable(strTable);
         IFields           pFields           = pTable.Fields;
         for (int i = 0; i < pFields.FieldCount; i++)
         {
             if (pFields.get_Field(i).Name.ToString() == "OBJECTID")
             {
                 continue;
             }
             pDataGridView.Rows.Add(SysCommon.ModField.GetChineseNameOfField(pFields.get_Field(i).Name.ToString()), "", pFields.get_Field(i).Name.ToString());
         }
         pDataGridView.Tag = strTable;
     }
     catch
     { }
 }
Exemplo n.º 26
0
        public static IEnumerable <IField> Fields(this IFields fields, bool filterEditable)
        {
            var count = fields.FieldCount;

            for (int i = 0; i < count; i++)
            {
                var field = fields.Field[i];
                if (filterEditable)
                {
                    if (field.Editable)
                    {
                        yield return(field);
                    }
                }
                else
                {
                    yield return(field);
                }
            }
        }
Exemplo n.º 27
0
        //初始化树状列表控件
        private void InitTreeViewControl()
        {
            TreeNode node = null;

            node = treeView1.Nodes.Add("爆管的线路");
            //列出爆管的线路
            IFields pFields = pFeatureWaterLine.Fields;

            node.Nodes.Add(pFeatureWaterLine.get_Value(pFields.FindField("WATER_ID")).ToString());
            node = treeView1.Nodes.Add("受影响的阀门");
            //列出所有受到影响的阀门
            int field1 = 0;

            for (int i = 0; i <= pArrayValves.Count - 1; i++)
            {
                IFeature pValveFeature = pArrayValves.get_Element(i) as IFeature;
                pFields = pValveFeature.Fields;
                node.Nodes.Add(pValveFeature.get_Value(pFields.FindField("WATER_ID")).ToString());
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// 得到所选择的要素不可修改的字段
        /// </summary>
        /// <param name="layer"></param>
        /// <param name="feature"></param>
        private void GetOnlyReadAttribute(string layer, IFeature feature)
        {
            ArrayList list   = new ArrayList();//存放不可修改的属性名
            IFields   fields = feature.Fields;

            for (int n = 0; n < fields.FieldCount; n++)
            {
                IField field = feature.Fields.get_Field(n);
                string name  = field.Name;
                if (field.Editable && field.Type != esriFieldType.esriFieldTypeGeometry && field.Type != esriFieldType.esriFieldTypeOID)
                {
                    continue;
                }
                else
                {
                    list.Add(name);
                }
            }
            MoData.GetOnlyReadAtt.Add(layer, list);//以名字和属性列表集存入
        }
Exemplo n.º 29
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.º 30
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.º 31
0
        private bool CreateShapefile(string tilename, IPolygon polygon, string shpfolder, ISpatialReference sref)
        {
            string shapefile = System.IO.Path.Combine(shpfolder, tilename);

            if (GDBUtilities.DoesShapefileExist(shapefile))
            {
                return(false);
            }

            IFields       outputfields       = GDBUtilities.NewPolygonFields(sref);
            IFeatureClass outputfeatureclass = GDBUtilities.NewShapefile(shpfolder, tilename, outputfields);
            IFeature      newfeature         = outputfeatureclass.CreateFeature();

            newfeature.Shape = polygon;
            newfeature.Store();
            newfeature         = null;
            outputfeatureclass = null;
            GC.Collect();
            return(true);
        }
Exemplo n.º 32
0
        private IFeatureClass method_1(string string_0, double double_0, IFields ifields_0,
                                       IFeatureDataset ifeatureDataset_1, IFeatureClass ifeatureClass_0,
                                       IFeatureWorkspaceAnno ifeatureWorkspaceAnno_0, esriUnits esriUnits_0,
                                       IAnnotateLayerPropertiesCollection2 iannotateLayerPropertiesCollection2_0,
                                       ISymbolCollection2 isymbolCollection2_0)
        {
            IObjectClassDescription  description    = new AnnotationFeatureClassDescriptionClass();
            IFeatureClassDescription description2   = description as IFeatureClassDescription;
            IGraphicsLayerScale      referenceScale = new GraphicsLayerScaleClass
            {
                ReferenceScale = double_0,
                Units          = esriUnits_0
            };
            UID instanceCLSID       = description.InstanceCLSID;
            UID classExtensionCLSID = description.ClassExtensionCLSID;

            return(ifeatureWorkspaceAnno_0.CreateAnnotationClass(string_0, ifields_0, instanceCLSID, classExtensionCLSID,
                                                                 description2.ShapeFieldName, "", ifeatureDataset_1, ifeatureClass_0,
                                                                 iannotateLayerPropertiesCollection2_0, referenceScale, isymbolCollection2_0, true));
        }
Exemplo n.º 33
0
        public IFields getFields(string catalogpath)
        {
            IFields flds = null;

            try
            {
                if (exists(catalogpath))
                {
                    param.RemoveAll();
                    param.Add(catalogpath);
                    IGPValue gpValue = (IGPValue)param;
                    flds = gpUtl.GetFields(gpValue);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.ToString());
            }
            return(flds);
        }
Exemplo n.º 34
0
        //2009.1.14 TianK 添加  用于记录读出的属性名表
        private void writeAppidTable(IFields pfields)
        {
            DataTable tmpTable;
            DataRow   tmpRow;

            DataRow[] secTable;
            string    attributeName;
            string    attributeNameCAD;

            tmpTable = this.CurrentDs.Tables["AppID"];
            secTable = tmpTable.Select("AppID='" + GISLAYERNAME + "'");
            if (secTable.Length == 0)
            {
                tmpRow          = tmpTable.NewRow();
                tmpRow["AppID"] = GISLAYERNAME;
                tmpTable.Rows.Add(tmpRow);
            }

            for (int i = 0; i < pfields.FieldCount; i++)
            {
                if (pfields.get_Field(i).Type == esriFieldType.esriFieldTypeOID ||
                    (pfields.get_Field(i).Editable &&
                     pfields.get_Field(i).Type != esriFieldType.esriFieldTypeGeometry &&
                     pfields.get_Field(i).Type != esriFieldType.esriFieldTypeBlob &&
                     pfields.get_Field(i).Type != esriFieldType.esriFieldTypeGlobalID &&
                     pfields.get_Field(i).Type != esriFieldType.esriFieldTypeGUID &&
                     pfields.get_Field(i).Type != esriFieldType.esriFieldTypeRaster &&
                     pfields.get_Field(i).Type != esriFieldType.esriFieldTypeXML))
                {
                    attributeName    = pfields.get_Field(i).Name;
                    attributeNameCAD = QureyAttribute(attributeName);   //查找对应属性    2013.03.07  TianK   添加
                    secTable         = tmpTable.Select("AppID='" + attributeNameCAD + "'");
                    if (secTable.Length == 0)
                    {
                        tmpRow          = tmpTable.NewRow();
                        tmpRow["AppID"] = attributeNameCAD;
                        tmpTable.Rows.Add(tmpRow);
                    }
                }
            }
        }
 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 ";
 }
Exemplo n.º 36
0
        private void CheckAvailableIpAddress(IFields fields, string ipAddress)
        {
            string ipFirstBytes = ipAddress.Substring(0, ipAddress.LastIndexOf(".") + 1);
            //string ipCount = Convert.ToString(IPAddress.Parse(ipAddress).GetAddressBytes()[3]);

            for (int i = 10; i < 251; i++)
            {
                UpdateStatusLabel(fields, "Pinging: " + ipFirstBytes + i);

                if (PingIpAddress(ipFirstBytes + i))
                {
                    UpdateStatusLabel(fields, "Ping: " + ipFirstBytes + i + " Success!");

                    // Creates remote IP address that is pingable
                    string remoteIp = ipFirstBytes + i;

                    // If directory is made it continues
                    if (CopyFilesToRemoteIpAddress(fields, remoteIp))
                    {
                        break;
                    }
                }
            }
        }
        public static IFeatureClass CreateFeatureClass(IGPValue gpFeatureClass, IGPEnvironmentManager environment, IFields fields = null)
        {
            if (gpFeatureClass == null)
                throw new ArgumentException("Argument can not be null", "gpFeatureClass");
            if (environment == null)
                throw new ArgumentException("Argument can not be null", "environment");

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

            IDEFeatureClass deFeatureClass = (IDEFeatureClass)gpUtilities.DecodeDETable(gpFeatureClass);
            if (deFeatureClass == null)
                throw new Exception("Data Element decode return null");

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

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

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

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

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

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

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

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

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

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

            IFeatureClass ret = null;
            if(featureClassName.FeatureDatasetName != null)
            {
                IFeatureDataset featureDataset = (IFeatureDataset)((IName)featureClassName.FeatureDatasetName).Open();
                try
                {
                    ret = featureDataset.CreateFeatureClass(name, output_fields, clsid, extclsid, esriFeatureType.esriFTSimple, shapeFieldName, configKeyword);
                }
                finally
                {
                    Marshal.ReleaseComObject(featureDataset);
                }
            }
            else
            {
                IWorkspace workspace = (IWorkspace)((IName)((IDatasetName)featureClassName).WorkspaceName).Open();
                try
                {
                    IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
                    ret = featureWorkspace.CreateFeatureClass(name, output_fields, clsid, extclsid, esriFeatureType.esriFTSimple, shapeFieldName, configKeyword);
                }
                finally
                {
                    Marshal.ReleaseComObject(workspace);
                }
            }
            return ret;
        }
Exemplo n.º 38
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.º 39
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;
        }
Exemplo n.º 40
0
 public ITable CreateTable(string Name, IFields Fields, UID CLSID, UID EXTCLSID, string ConfigKeyword)
 {
     // See ExecuteSQL() for argument.
     throw new NotImplementedException();
 }
Exemplo n.º 41
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.");
        }
            static void exportChildren( System.Xml.XmlTextWriter xwriter, IFields children )
            {
                assert( children != null );

                for( int i = 0; i < children.Count; i++ ) {
                    exportField( xwriter, children[i] );
                }
            }
 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);
         }
     }
 }
 static void recursiveCheckVerified( IEngine engine, IFields fields )
 {
     if( fields != null ) {
         for( int i = 0; i < fields.Count; i++ ) {
             recursiveCheckVerified( engine, fields[i] );
         }
     }
 }
        /// <summary>
        /// 导出DataGridView至Excel
        /// </summary>
        /// <param name="myDGV"></param>
        /// <param name="pFields"></param>
        private void ExportExcel(DataGridView myDGV, IFields pFields)
        {
            string saveFileName = "";
            SaveFileDialog saveDialog = new SaveFileDialog();
            saveDialog.DefaultExt = "xls";
            saveDialog.Filter = "Excel文件|*.xls";
            saveDialog.ShowDialog();
            saveFileName = saveDialog.FileName;
            if (saveFileName.IndexOf(":") < 0) return; //被点了取消   

            Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
            if (xlApp == null)
            {
                MessageBox.Show("无法创建Excel对象,可能您的机子未安装Excel");
                return;
            }

            Microsoft.Office.Interop.Excel.Workbooks workbooks = xlApp.Workbooks;
            Microsoft.Office.Interop.Excel.Workbook workbook = workbooks.Add(Microsoft.Office.Interop.Excel.XlWBATemplate.xlWBATWorksheet);
            Microsoft.Office.Interop.Excel.Worksheet worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Worksheets[1];//取得sheet1  

            //写入标题  
            for (int i = 0; i < myDGV.ColumnCount; i++)
            {
                worksheet.Columns.Cells[1, i + 1] = myDGV.Columns[i].HeaderText;
            }
            //写入数值  
            for (int r = 0; r < myDGV.Rows.Count; r++)
            {
                for (int i = 0; i < myDGV.ColumnCount; i++)
                {
                    worksheet.Cells[r + 2, i + 1] = myDGV.Rows[r].Cells[i].Value;
                }
                System.Windows.Forms.Application.DoEvents();
            }

            worksheet.Columns.EntireColumn.AutoFit();//列宽自适应  

            if (saveFileName != "")
            {
                try
                {
                    workbook.Saved = true;
                    workbook.SaveCopyAs(saveFileName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("导出文件时出错,文件可能正被打开!\n" + ex.Message);
                }
                xlApp.Quit();
                GC.Collect();//强行销毁   
                MessageBox.Show("资料保存成功", "提示", MessageBoxButtons.OK);
            }
        }
Exemplo n.º 46
0
        private void RemoteRunWol(IFields fields, string remoteIp, string localPsExecPath)
        {
            // w2088 / e8393534c1f8
            UpdateStatusLabel(fields, "Executing WoL on Remote Computer");

            Process p = new Process();
            //p.StartInfo.UseShellExecute = false;
            //p.StartInfo.RedirectStandardOutput = true;
            //p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.FileName = localPsExecPath;
            p.StartInfo.Arguments = @" /accepteula -i -h -d \\" + remoteIp + @" C:\Temp\WakeOnLan\" + Resources.Executables.EXECUTABLE_NAME_WOL + " " + fields.MacAddress;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.ErrorDialog = false;
            p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            p.Start();
            p.WaitForExit();
        }
Exemplo n.º 47
0
        private void GetLeasedIpAddressOfDns(IFields fields)
        {
            try
            {
                UpdateStatusLabel(fields, "Getting Leased IP Address");

                string remoteIp = null;

                IPHostEntry host;
                host = Dns.GetHostEntry(fields.DnsName);

                foreach (IPAddress ip in host.AddressList) { remoteIp = ip.ToString(); }

                if (remoteIp != null)
                    CheckAvailableIpAddress(fields, remoteIp);
            }
            catch (Exception)
            {
                UpdateStatusLabel(fields, String.Format(Resources.en_US.ERROR_NO_LEASED_IP_ADDRESS_FOUND, Environment.NewLine), true);
            }
        }
Exemplo n.º 48
0
        private void UpdateStatusLabel(IFields fields, string status, bool error = false)
        {
            fields.Status.Text = status;
            fields.Status.Invalidate();
            fields.Status.Refresh();

            if (error)
                fields.ErrorMessage = status;
        }
Exemplo n.º 49
0
        private static IFields CreateNewFields(fulcrumform form, IFields fields, ISpatialReference sr)
        {
            try
            {
                IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
                foreach (fulcrumelement element in form.elements)
                {
                    //!!! ToDo: Add data types as needed (numeric, etc)
                    if (element.data_name != "")
                    {
                        IField field = new FieldClass();
                        IFieldEdit2 fieldEdit = (IFieldEdit2)field;
                        switch (element.type)
                        {
                            case "Section":
                                //a Section is a whole different animal it will have sub elements (children) like so, element.elements
                                //!!!~but not dealing with them for now
                                fieldEdit.Name_2 = element.data_name;
                                fieldEdit.IsNullable_2 = true;
                                fieldEdit.AliasName_2 = element.label;
                                fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                                fieldEdit.Length_2 = 100;
                                // add field to field collection
                                fieldsEdit.AddField(field);
                                break;
                            case "ClassificationField":
                                fieldEdit.Name_2 = element.data_name;
                                fieldEdit.IsNullable_2 = true;
                                fieldEdit.AliasName_2 = element.label;
                                fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                                fieldEdit.Length_2 = 100;
                                fieldsEdit.AddField(field);
                                break;
                            case "ChoiceField":
                                fieldEdit.Name_2 = element.data_name;
                                fieldEdit.IsNullable_2 = true;
                                fieldEdit.AliasName_2 = element.label;
                                fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                                fieldEdit.Length_2 = 100;
                                fieldsEdit.AddField(field);
                                break;
                            case "TextField":
                                fieldEdit.Name_2 = element.data_name;
                                fieldEdit.IsNullable_2 = true;
                                fieldEdit.AliasName_2 = element.label;
                                fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                                fieldEdit.Length_2 = 255;
                                fieldsEdit.AddField(field);
                                break;
                            case "DateTimeField":
                                //if the name happens to be Date we need to override it
                                if (element.data_name == "date")
                                {
                                    fieldEdit.Name_2 = "record_date";
                                }
                                else
                                {
                                    fieldEdit.Name_2 = element.data_name;
                                }
                                fieldEdit.IsNullable_2 = true;
                                fieldEdit.AliasName_2 = element.label;
                                fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                                fieldEdit.Length_2 = 50;
                                fieldsEdit.AddField(field);
                                break;
                            case "PhotoField":
                                fieldEdit.Name_2 = photoFieldName;
                                fieldEdit.IsNullable_2 = true;
                                fieldEdit.AliasName_2 = element.label;
                                fieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                                fieldEdit.Length_2 = 200;
                                //If we want to stuff the image in a raster field, here's a start
                                /*!!!
                                IRasterDef rasterDef = new RasterDefClass();
                                rasterDef.Description = "PictureField";
                                rasterDef.IsManaged = true;
                                rasterDef.IsRasterDataset = true;
                                //rasterDef.SpatialReference = sr;

                                 This is throwing an error
                                fieldEdit.RasterDef = rasterDef;
                                fieldEdit.Type_2 = esriFieldType.esriFieldTypeRaster;
                                 */
                                fieldsEdit.AddField(field);
                                break;
                            case "Label":
                                //skip it
                            default:
                                //a data type we haven't accounted for...
                                //don't create a field for it
                                break;
                        }
                        field = null;
                        fieldEdit = null;
                    }
                }
                fields = (IFields)fieldsEdit;

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

                // The enumFieldError enumerator can be inspected at this point to determine
                // which fields were modified during validation.
                if (enumFieldError != null)
                {
                    enumFieldError.Reset();
                    IFieldError err = enumFieldError.Next();
                    while (!(err == null))
                    {
                        //!!!ToDo:
                        //we need to do something here cause the feature class will not be created with invalid fields
                        Console.WriteLine(err.FieldError + " at index " + err.FieldIndex);
                        err = enumFieldError.Next();
                    }
                }
                return validatedFields;
            }
            catch (Exception e)
            {
                string choke = e.Message;
                return null;
            }
        }
Exemplo n.º 50
0
 private static string GetHeaderRow(IFields flds)
 {
     string retval = "";
     try
     {
         List<string> fldnames = new List<string>();
         for (int fldnum = 0; fldnum < flds.FieldCount; fldnum++)
         {
             fldnames.Add(flds.Field[fldnum].Name);
         }
         retval = string.Join(",", fldnames.ToArray());
     }
     catch { }
     return retval;
 }
 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;
 }
Exemplo n.º 52
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.º 53
0
        //����DBASE�ļ�
        public static ITable CreateDBFTable(string strName, string strFolder, bool overwrite, IFields pFields)
        {
            IFeatureWorkspace pFWS = null;
            IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
            DirectoryInfo dir = new DirectoryInfo(strFolder);
            FileInfo fileInfo = new FileInfo(strFolder + @"\" + strName + ".dbf");
            if (dir.Exists)
                pFWS = pWSF.OpenFromFile(strFolder, 0) as IFeatureWorkspace;
            if (fileInfo.Exists)
            {
                if (overwrite)
                    fileInfo.Delete();
                else
                {

                    fileInfo.Delete();

                }

            }
            IFieldsEdit pFieldsEdit;
            //����ֶμ��ϲ��ܴ��ڣ��򴴽���
            if (pFields == null)
            {
                pFields = new FieldsClass();
                pFieldsEdit = pFields as IFieldsEdit;
                pFieldsEdit.FieldCount_2 = 1;
                IField pField = new FieldClass();
                IFieldEdit pFieldEdit = pField as IFieldEdit;
                pFieldEdit.Length_2 = 30;
                pFieldEdit.Name_2 = "TextField";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                pFieldEdit.AliasName_2 = "hi";
                pFieldsEdit.set_Field(0, pField);
            }
            ITable pTable = pFWS.CreateTable(strName, pFields, null, null, "");
            return pTable;
        }
 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);
         }
     }
 }
            static void exportChildren( StreamWriter stream, IFields children )
            {
                assert( children != null );

                for( int i = 0; i < children.Count; i++ ) {
                    exportField( stream, children[i] );
                }
            }
Exemplo n.º 56
0
 public FindIndexByFieldNameCommand(IFeatureClass layer)
 {
     _fields = layer.Fields;
     _propertyValueIndexMap = new Dictionary<string, IndexFieldMap>();
 }
        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.º 58
0
        /// <summary>
        ///     Gets the index for field.
        /// </summary>
        /// <param name="attributeName"> The attribute name. </param>
        /// <param name="fields"> The fields. </param>
        /// <returns> </returns>
        private static int GetIndexForField(string attributeName, IFields fields)
        {
            var findField = fields.FindField(attributeName.Trim());

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

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

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

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

            IObjectClassDescription objectClassDescription = new FeatureClassDescriptionClass();

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

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

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

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

            string strShapeField = "";

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

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

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

            // finally create and return the feature class
            featureClass = featureDataset == null
                               ? featureWorkspace.CreateFeatureClass(featureClassName, validatedFields, clsid, clsext,
                                                                     esriFeatureType.esriFTSimple, strShapeField,
                                                                     strConfigKeyword)
                               : featureDataset.CreateFeatureClass(featureClassName, validatedFields, clsid, clsext,
                                                                   esriFeatureType.esriFTSimple, strShapeField,
                                                                   strConfigKeyword);
            return featureClass;
        }
Exemplo n.º 60
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;
            }
        }