Exemplo n.º 1
0
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            frmAddValues  values = new frmAddValues();
            IFeatureLayer layer  = (this.cboLayers.SelectedItem as LayerObject).Layer as IFeatureLayer;
            IFields       fields = layer.FeatureClass.Fields;
            IField        field  = fields.get_Field(fields.FindFieldByAliasName(this.cboFields.SelectedItem.ToString()));

            values.Layer        = (this.cboLayers.SelectedItem as LayerObject).Layer;
            values.FieldName    = field.Name;
            values.List         = this.ilist_0 as ArrayList;
            values.List         = this.ilist_0 as ArrayList;
            values.GetAllValues = this.bool_0;
            if (values.ShowDialog() == DialogResult.OK)
            {
                string[]     items       = new string[3];
                IQueryFilter queryFilter = new QueryFilterClass();
                for (int i = 0; i < values.SelectedItems.Count; i++)
                {
                    items[0] = values.SelectedItems[i].ToString();
                    items[1] = values.SelectedItems[i].ToString();
                    queryFilter.WhereClause = field.Name + " = " +
                                              this.ConvertFieldValueToString(field.Type, values.SelectedItems[i]);
                    items[2] = layer.FeatureClass.FeatureCount(queryFilter).ToString();
                    ListViewItem item = new ListViewItem(items);
                    this.listView1.Items.Add(item);
                }
            }
            this.bool_0 = values.GetAllValues;
        }
Exemplo n.º 2
0
        private void btnAddAllValues_Click(object sender, EventArgs e)
        {
            this.listView1.Items.Clear();
            this.ilist_0.Clear();
            string[]      items  = new string[3];
            IFeatureLayer layer  = (this.cboLayers.SelectedItem as LayerObject).Layer as IFeatureLayer;
            IFields       fields = layer.FeatureClass.Fields;
            IField        field  = fields.get_Field(fields.FindFieldByAliasName(this.cboFields.SelectedItem.ToString()));

            if (this.GetUniqueValues(layer, field.Name, this.ilist_0))
            {
                IQueryFilter queryFilter = new QueryFilterClass();
                this.method_4(layer.FeatureClass.ShapeType);
                for (int i = this.ilist_0.Count - 1; i >= 0; i--)
                {
                    items[0] = this.ilist_0[i].ToString();
                    items[1] = this.ilist_0[i].ToString();
                    queryFilter.WhereClause = field.Name + " = " +
                                              this.ConvertFieldValueToString(field.Type, this.ilist_0[i]);
                    items[2] = layer.FeatureClass.FeatureCount(queryFilter).ToString();
                    ListViewItem item = new ListViewItem(items);
                    this.listView1.Items.Add(item);
                    this.ilist_0.RemoveAt(i);
                }
            }
        }
Exemplo n.º 3
0
        private void CreateDEM()
        {
            IWorkspaceFactory pWsF    = new AccessWorkspaceFactory();
            IFeatureWorkspace pWs     = pWsF.OpenFromFile(textEdit1.Text, 0) as IFeatureWorkspace;
            IFeatureDataset   pFDs    = pWs.OpenFeatureDataset("GCD");
            IFeatureClass     pFc     = pFDs as IFeatureClass;
            double            power   = 1;
            object            Missing = Type.Missing;


            IFields pFields = pFc.Fields;
            int     index   = pFields.FindFieldByAliasName("高程");
            string  z       = pFields.get_Field(index).Name;


            IFeatureClassDescriptor feaDes = new FeatureClassDescriptorClass();

            feaDes.Create(pFc, null, z);
            IGeoDataset inGeoDs = feaDes as IGeoDataset;

            IRasterAnalysisEnvironment rasterEnv = new RasterInterpolationOpClass();
            double cellSize    = 20;
            object cellSizeObj = cellSize;

            rasterEnv.SetCellSize(esriRasterEnvSettingEnum.esriRasterEnvValue, ref cellSizeObj);

            IRasterRadius radius = new RasterRadiusClass();

            radius.SetVariable(12, Missing);

            IInterpolationOp2 interOp  = rasterEnv as IInterpolationOp2;
            IGeoDataset       outGeoDs = interOp.IDW(inGeoDs, power, radius, ref Missing);

            pWs = pWsF.OpenFromFile(textEdit2.Text, 0) as IFeatureWorkspace;
        }
Exemplo n.º 4
0
        /// <summary>
        /// 要素排序
        /// </summary>
        /// <param name="pFeatureClass">要排序的要素类</param>
        /// <param name="columName">Name of the colum.</param>
        private void SortFeatures(IFeatureClass pFeatureClass, string columName)
        {
            ITableSort pTableSort = new TableSortClass();
            IFields    pFields    = pFeatureClass.Fields;
            int        index      = pFields.FindFieldByAliasName(columName);
            IField     pField     = pFields.get_Field(index);

            pTableSort.Fields = pField.Name;

            switch (_up)
            {
            case true:
                pTableSort.set_Ascending(pField.Name, true);
                _up = false;
                break;

            case false:
                pTableSort.set_Ascending(pField.Name, false);
                _up = true;
                break;
            }
            pTableSort.set_CaseSensitive(pField.Name, true);
            pTableSort.Table = pFeatureClass as ITable;
            pTableSort.Sort(null);
            ICursor pCursor = pTableSort.Rows;

            _pTs = pTableSort;
            RefreshTable();
        }
Exemplo n.º 5
0
        private IGeoDataset GetBeforeGeo(IFeatureClass fc)
        {
            IInterpolationOp3 pInterpolationOp = new RasterInterpolationOpClass();

            IFields fields = fc.Fields;
            int     index  = fields.FindFieldByAliasName("高程");
            IField  field  = fields.get_Field(index);

            ISpatialFilter filter = new SpatialFilter();

            filter.Geometry   = geo;
            filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelContains;

            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);
        }
Exemplo n.º 6
0
        private void comboFields_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboValue.Items.Clear();
            ILayer        pLayer        = m_axMapControl.get_Layer(comboLayers.SelectedIndex);
            IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;

            if (pFeatureLayer == null)
            {
                return;
            }

            IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
            IFields       pFields       = pFeatureClass.Fields;

            IFeatureCursor pFeatureCursor = pFeatureClass.Search(null, false);
            IFeature       pFeature       = pFeatureCursor.NextFeature();

            int indexField = pFields.FindFieldByAliasName(comboFields.Text);

            while (pFeature != null)
            {
                comboValue.Items.Add(pFeature.get_Value(indexField));
                pFeature = pFeatureCursor.NextFeature();
            }

            System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor);
            GC.Collect();
            GC.WaitForPendingFinalizers();

            comboValue.Text = "<选择字段值>";
        }
Exemplo n.º 7
0
        private string method_3(string string_0)
        {
            IFields fields = this.igeoFeatureLayer_0.FeatureClass.Fields;
            int     index  = fields.FindFieldByAliasName(string_0);

            return(fields.get_Field(index).Name);
        }
Exemplo n.º 8
0
        private void button1_Click(object sender, EventArgs e)
        {
            IFields fields = m_pFeature.Fields;
            int     nIndex = fields.FindFieldByAliasName("Ïß·Ãû³Æ");

            m_pFeature.set_Value(nIndex, textBox1.Text);
            m_pFeature.Store();
        }
Exemplo n.º 9
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.AppStarting;  // 设置对话框的鼠标指针为等待指针
                string        fieldName    = textBox1.Text;
                string        aliasName    = textBox2.Text;
                IFeatureClass featureClass = Variable.pAttributeTableFeatureLayer.FeatureClass;
                IFields       fields       = featureClass.Fields;
                if (fields.FindField(fieldName) != -1)
                {
                    MessageBox.Show("字段名称重复!");
                    this.Cursor = Cursors.Default;  // 设置对话框的鼠标指针为默认指针
                    textBox1.Focus();
                    return;
                }
                if (fields.FindFieldByAliasName(aliasName) != -1)
                {
                    MessageBox.Show("显示名称重复!");
                    this.Cursor = Cursors.Default;  // 设置对话框的鼠标指针为默认指针
                    textBox2.Focus();
                    return;
                }
                IField     newField     = new FieldClass(); // 新建字段
                IFieldEdit newFieldEdit = (IFieldEdit)newField;
                newFieldEdit.Name_2      = fieldName;       // 设置字段名称
                newFieldEdit.AliasName_2 = aliasName;       // 设置字段别名
                switch (comboBox1.Text)                     // 设置字段类型
                {
                case "整数":
                    newFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
                    break;

                case "小数":
                    newFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;

                    break;

                case "文本":
                    newFieldEdit.Type_2   = esriFieldType.esriFieldTypeString;
                    newFieldEdit.Length_2 = int.Parse(textBox1.Text);
                    break;

                case "日期时间":
                    newFieldEdit.Type_2 = esriFieldType.esriFieldTypeDate;
                    break;
                }
                newFieldEdit.IsNullable_2 = true;  // 允许空值
                featureClass.AddField(newFieldEdit);
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.ToString(), "异常");
                this.Cursor = Cursors.Default;  // 设置对话框的鼠标指针为默认指针
                this.textBox1.Focus();
            }
        }
Exemplo n.º 10
0
 private string method_2(string string_0)
 {
     if (this.ilayer_0 is IGeoFeatureLayer)
     {
         IFields fields = (this.ilayer_0 as IGeoFeatureLayer).FeatureClass.Fields;
         int     index  = fields.FindFieldByAliasName(string_0);
         return(fields.get_Field(index).Name);
     }
     return("");
 }
        //碎线检查的算法
        private void LittleLineCheck()
        {
            Hashtable     result = new Hashtable();
            IFeatureClass currentFeatureClass;

            //获取各个线图层
            for (int i = 0; i < checkedListBoxLyr.Items.Count; i++)
            {
                //图层被选中
                if (checkedListBoxLyr.GetItemChecked(i))
                {
                    string lyrNameSelected = checkedListBoxLyr.GetItemText(checkedListBoxLyr.Items[i]);
                    //找到选中的图层名对应的图层
                    foreach (DictionaryEntry de in layersHashtable)
                    {
                        //如果Hash表中的某项key值是当前遍历的图层名
                        if (de.Key.ToString() == lyrNameSelected)
                        {
                            //将该项Value值付给当前矢量图层对象
                            currentFeatureLayer = de.Value as IFeatureLayer;

                            currentFeatureClass = currentFeatureLayer.FeatureClass;
                            IFields pfields    = currentFeatureClass.Fields;
                            int     fieldIndex = pfields.FindFieldByAliasName("Shape_Length");

                            IFeatureCursor pFeatureCursor = currentFeatureClass.Search(null, false);
                            IFeature       pFeature       = pFeatureCursor.NextFeature();
                            int            count          = 0;
                            while (pFeature != null)
                            {
                                double len = Convert.ToDouble(pFeature.get_Value(fieldIndex));
                                if (len < 1)
                                {
                                    count++;
                                }

                                pFeature = pFeatureCursor.NextFeature();
                            }
                            result.Add(lyrNameSelected, count);
                            Marshal.ReleaseComObject(pFeatureCursor);
                        }
                    }
                }
            }
            //展示检查结果
            string strResult = "";

            foreach (DictionaryEntry de in result)
            {
                //如果Hash表中的某项key值是当前遍历的图层名
                strResult += de.Key.ToString() + ":" + de.Value + "条碎线\n";
            }
            MessageBox.Show(strResult);
        }
Exemplo n.º 12
0
 private void cboFields_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (this.bool_0)
     {
         IFields fields = this.igeoFeatureLayer_0.FeatureClass.Fields;
         int     index  = fields.FindFieldByAliasName(this.cboFields.Text);
         if (index != -1)
         {
             IField field = fields.get_Field(index);
             this.string_0 = "[" + field.Name + "]";
             (this.iannotateLayerProperties_0 as ILabelEngineLayerProperties).Expression = this.string_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.º 14
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.º 15
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            if (comboLayers.Text.Length == 0)
            {
                MessageBox.Show("请选择一个图层");
                return;
            }

            if (comboFields.Text == "<选择字段值>")
            {
                MessageBox.Show("请选择一个合适的字段值");
                return;
            }

            ILayer        pLayer        = m_axMapControl.get_Layer(comboLayers.SelectedIndex);
            IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
            IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
            IFields       pFields       = pFeatureClass.Fields;
            IField        pField        = pFields.get_Field(pFields.FindFieldByAliasName(comboFields.Text));

            IQueryFilter pQueryFilter = new QueryFilterClass();

            if (pField.Type == esriFieldType.esriFieldTypeString)
            {
                pQueryFilter.WhereClause = comboFields.Text + " " + comboOperator.Text + " '" + comboValue.Text + "'";
            }
            else
            {
                pQueryFilter.WhereClause = comboFields.Text + " " + comboOperator.Text + " " + comboValue.Text;
            }

            IFeatureSelection pFeatureSelection = pFeatureLayer as IFeatureSelection;

            pFeatureSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
            ISelectionSet pSelectionSet = pFeatureSelection.SelectionSet;

            m_axMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, m_axMapControl.ActiveView.Extent);

            // 显示查询要素的属性
            lsvContent.Columns.Clear();
            lsvContent.Items.Clear();

            for (int i = 0; i < pFields.FieldCount; i++)
            {
                lsvContent.Columns.Add(pFields.get_Field(i).AliasName);
            }

            ICursor pCursor = null;

            pSelectionSet.Search(null, false, out pCursor);
            IFeatureCursor pFeatureCursor = pCursor as IFeatureCursor;

            IFeature pFeature = pFeatureCursor.NextFeature();

            while (pFeature != null)
            {
                ListViewItem item = null;
                for (int i = 0; i < pFields.FieldCount; i++)
                {
                    if (pFields.get_Field(i).Type != esriFieldType.esriFieldTypeGeometry)
                    {
                        if (i == 0)
                        {
                            item = lsvContent.Items.Add(pFeature.get_Value(i).ToString());
                        }
                        else
                        {
                            item.SubItems.Add(pFeature.get_Value(i).ToString());
                        }
                    }
                }
                pFeature = pFeatureCursor.NextFeature();
            }
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatureCursor);
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
Exemplo n.º 16
0
        //public Boolean InitForm(IFeatureLayer pFeatureLayer)
        //{
        //    if (pFeatureLayer == null) return false;
        //    IFeatureClass pFeaClass = pFeatureLayer.FeatureClass;
        //    if (pFeaClass == null) return false;
        //    m_FeatureLayer = pFeatureLayer;
        //    this.comboBoxLayer.Text = pFeatureLayer.Name;
        //    IFields pFields = pFeaClass.Fields as IFields;
        //    for (int i = 0; i < pFields.FieldCount; i++)
        //    {
        //        //this.comboBoxExGroupF.Items.Add(pFields.get_Field(i).AliasName );
        //        this.comboBoxExSumF.Items.Add(pFields.get_Field(i).AliasName );
        //    }
        //    return true;
        //}
        private void buttonXStatic_Click(object sender, EventArgs e)
        {
            //判断分组字段是否设置
            if (this.listSelectColumns.Items.Count == 0)
            {
                MessageBox.Show("请选择分组字段!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            //判断汇总字段是否设置
            if (this.comboBoxExSumF.Text.Equals(""))
            {
                MessageBox.Show("请选择汇总字段!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            //初始化进度条
            IFeatureClass pFeatureClass = _FeatureLayer.FeatureClass;

            if (pFeatureClass.FeatureCount(null) == 0)
            {
                MessageBox.Show("图层中没有可供统计的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            IFields pFields      = pFeatureClass.Fields;
            int     iFieldsindex = 0;

            iFieldsindex = pFields.FindFieldByAliasName(this.comboBoxExSumF.Text);
            string        sSumField = pFields.get_Field(iFieldsindex).Name;
            IField        pSumField = pFields.get_Field(iFieldsindex);
            esriFieldType pType     = pFields.get_Field(iFieldsindex).Type;

            if (pType != esriFieldType.esriFieldTypeDouble && pType != esriFieldType.esriFieldTypeInteger && pType != esriFieldType.esriFieldTypeSingle && pType != esriFieldType.esriFieldTypeSmallInteger)
            {
                MessageBox.Show("汇总字段须是数值型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            List <IField> listGroupbyFields = new List <IField>();

            for (int i = 0; i < listSelectColumns.Items.Count; i++)
            {
                string strFieldname  = listSelectColumns.Items[i] as string;
                int    tmpFieldindex = pFields.FindFieldByAliasName(strFieldname);
                IField pField        = pFields.get_Field(tmpFieldindex);
                if (strFieldname.Equals(this.comboBoxExSumF.Text))
                {
                    continue;
                }
                listGroupbyFields.Add(pField);
            }
            if (listGroupbyFields.Count == 0)
            {
                MessageBox.Show("请选择有效地分组字段!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            this.Hide();

            SysCommon.CProgress vProgress = new SysCommon.CProgress("进度条");
            vProgress.EnableCancel    = false;
            vProgress.ShowDescription = true;
            vProgress.FakeProgress    = true;
            vProgress.TopMost         = true;
            vProgress.ShowProgress();
            vProgress.SetProgress("创建临时成果数据库");
            try
            {
                string workpath      = Application.StartupPath + "\\..\\Temp";
                string workSpaceName = Application.StartupPath + "\\..\\Temp\\TmpStatistic.mdb";
                if (File.Exists(workSpaceName))
                {
                    File.Delete(workSpaceName);
                }
                //判断结果目录是否存在,不存在则创建
                if (System.IO.Directory.Exists(workpath) == false)
                {
                    System.IO.Directory.CreateDirectory(workpath);
                }
                //创建一个新的mdb数据库,并打开工作空间
                IWorkspace pOutWorkSpace     = ChangeJudge.CreatePDBWorkSpace(workpath, "TmpStatistic.mdb");
                string     sFeatureClassName = "";
                vProgress.SetProgress("分析目标图层数据");
                if (_FeatureLayer != null)
                {
                    IDataset   pDataSet   = _FeatureLayer.FeatureClass as IDataset;
                    IWorkspace pWorkSpace = pDataSet.Workspace;
                    sFeatureClassName = pDataSet.Name;
                    CopyPasteGDBData.CopyPasteGeodatabaseData(pWorkSpace, pOutWorkSpace, sFeatureClassName, esriDatasetType.esriDTFeatureClass);
                }
                pOutWorkSpace = null;
                if (sFeatureClassName.Contains("."))
                {
                    sFeatureClassName = sFeatureClassName.Substring(sFeatureClassName.IndexOf(".") + 1);
                }
                ModStatReport.DoCustomizeStat(workSpaceName, _FeatureLayer.Name, sFeatureClassName, listGroupbyFields, pSumField as Field, vProgress);
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                vProgress.Close();
            }
        }