private double GetValueInterval(string controlName) { double valueInterval = (maxValueInput.Value - minValueInput.Value) / levelInput.Value; if (m_Layer == null || m_Layer.FeatureClass == null || controlName == "minValueInput" || controlName == "maxValueInput") { return(valueInterval); } ESRI.ArcGIS.Geodatabase.ITable pTable = m_Layer.FeatureClass as ESRI.ArcGIS.Geodatabase.ITable; if (pTable.FindField(cmbField.Text) < 0) { return(valueInterval); } ESRI.ArcGIS.Geodatabase.ICursor pCursor = pTable.Search(null, false); ESRI.ArcGIS.Geodatabase.IDataStatistics dataStatistics = new ESRI.ArcGIS.Geodatabase.DataStatisticsClass(); dataStatistics.Field = cmbField.Text; dataStatistics.Cursor = pCursor; ESRI.ArcGIS.esriSystem.IStatisticsResults statisticsResults = dataStatistics.Statistics; valueInterval = (statisticsResults.Maximum - statisticsResults.Minimum) / levelInput.Value; flag = true; minValueInput.Value = statisticsResults.Minimum; maxValueInput.Value = statisticsResults.Maximum; flag = false; System.Runtime.InteropServices.Marshal.ReleaseComObject(pCursor); System.Runtime.InteropServices.Marshal.ReleaseComObject(statisticsResults); return(valueInterval); }
/// <summary> /// 获取当前版本信息(获取环境中数据库版本表中VERSION的最大值加1做为当前编辑生成版本) /// </summary> /// <param name="ex"></param> /// <returns></returns> public int GetVersion(out Exception ex) { ex = null; int iVersion = -1; if (this.HisWs == null) { ex = new Exception("更新环境库尚未初始化"); return(-1); } try { ITable getTable = (this.HisWs as IFeatureWorkspace).OpenTable(this.m_sDBVersionTable); if (getTable.RowCount(null) == 0) { return(1); } else { int index = getTable.FindField("VERSION"); if (index < 0) { ex = new Exception("数据库版本表中未能找到VERSION字段"); return(-1); } ICursor TableCursor = getTable.Search(null, false); //IRow getRow = TableCursor.NextRow(); //while (getRow != null) //{ // int getValue =Convert.ToInt32(getRow.get_Value(index)); // if (getValue > iVersion) iVersion = getValue; // getRow = TableCursor.NextRow(); //} IDataStatistics dataStatistics = new DataStatisticsClass(); dataStatistics.Field = "VERSION"; dataStatistics.Cursor = TableCursor; ESRI.ArcGIS.esriSystem.IStatisticsResults statisticsResults = dataStatistics.Statistics; double getMaxVersion = statisticsResults.Maximum; iVersion = Convert.ToInt32(getMaxVersion); System.Runtime.InteropServices.Marshal.ReleaseComObject(TableCursor); } return(iVersion + 1); } catch (Exception eError) { //****************************************** //guozheng added System Exception log if (SysCommon.Log.Module.SysLog == null) { SysCommon.Log.Module.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog(); } SysCommon.Log.Module.SysLog.Write(eError); //****************************************** ex = new Exception("获取新数据库版本信息失败。\n原因:" + eError.Message); return(-1); } }
private void button2_Click(object sender, EventArgs e) { GetWorkPath(); IWorkspace ws = OpenShapfileWorkspace(this.strFilePath); IFeatureWorkspace pFWS = ws as IFeatureWorkspace; if (strFileName == null || strFileName != "UK_CoastlineSplit") { MessageBox.Show("Please select the CoastlineSplit in TOC"); return; } IFeatureClass fcCoastLineSplit = pFWS.OpenFeatureClass(strFileName); //IQueryFilter queryFilter = new QueryFilterClass(); ICursor cursor = (ICursor)fcCoastLineSplit.Search(null, false); //Get statistic of length field and get min and max values IDataStatistics dataStatistic = new DataStatisticsClass(); int fieldindex = fcCoastLineSplit.Fields.FindField("length"); if (fieldindex == -1) { MessageBox.Show("Please add 'length' field!"); return; } dataStatistic.Field = "length"; dataStatistic.Cursor = cursor; ESRI.ArcGIS.esriSystem.IStatisticsResults staResult = dataStatistic.Statistics; // round the result in 4 decimals maxLength = Math.Round(staResult.Maximum, 4).ToString(); minLength = Math.Round(staResult.Minimum, 4).ToString(); meanLength = Math.Round(staResult.Mean, 4).ToString(); textBox2.Text = minLength; textBox3.Text = maxLength; textBox4.Text = meanLength; // If minimum length is smaller than 1 meter, set the minimum to the minimum value greater than 1 meter if (staResult.Minimum <= 1) { if (MessageBox.Show("The minimum length is shorter than 1 meter, change the minimum value greater than 1?", "Note", MessageBoxButtons.YesNo) == DialogResult.Yes) { IQueryFilter queryFilter = new QueryFilterClass(); queryFilter.WhereClause = "length > 1"; ISelectionSet pSelectionSet = fcCoastLineSplit.Select(queryFilter, esriSelectionType.esriSelectionTypeHybrid, esriSelectionOption.esriSelectionOptionNormal, null); IFeatureCursor pFCursor; ICursor pCursor; pSelectionSet.Search(null, true, out pCursor); pFCursor = pCursor as IFeatureCursor; dataStatistic = new DataStatisticsClass(); dataStatistic.Field = "length"; dataStatistic.Cursor = pCursor; staResult = dataStatistic.Statistics; minLength = Math.Round(staResult.Minimum, 4).ToString(); textBox2.Text = minLength; } } }
/// <summary> /// 获取当前版本信息(获取环境中数据库版本表中VERSION的最大值加1做为当前编辑生成版本) guozheng added /// </summary> /// <param name="ex"></param> /// <returns></returns> private static int GetVersion(IWorkspace pSDEWS, out Exception ex) { ex = null; int iVersion = -1; if (pSDEWS == null) { ex = new Exception("更新环境库尚未初始化"); return(-1); } try { ITable getTable = (pSDEWS as IFeatureWorkspace).OpenTable(ModData.m_sDBVersionTable); if (getTable.RowCount(null) == 0) { return(1); } else { int index = getTable.FindField("VERSION"); if (index < 0) { ex = new Exception("数据库版本表中未能找到VERSION字段"); return(-1); } ICursor TableCursor = getTable.Search(null, false); IDataStatistics dataStatistics = new DataStatisticsClass(); dataStatistics.Field = "VERSION"; dataStatistics.Cursor = TableCursor; ESRI.ArcGIS.esriSystem.IStatisticsResults statisticsResults = dataStatistics.Statistics; double getMaxVersion = statisticsResults.Maximum; iVersion = Convert.ToInt32(getMaxVersion); System.Runtime.InteropServices.Marshal.ReleaseComObject(TableCursor); } return(iVersion + 1); } catch (Exception eError) { //******************************************************************* //Exception Log if (ModData.SysLog == null) { ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog(); } ModData.SysLog.Write(eError, null, DateTime.Now); //******************************************************************** ex = new Exception("获取新数据库版本信息失败。\n原因:" + eError.Message); return(-1); } }