/// <summary>
        /// 获取CropCount
        /// </summary>
        /// <param name="plotid"></param>
        /// <returns></returns>
        public static int get_CropCount()
        {
            List <string> list   = new List <string>();
            string        strsql = "select count(distinct CropCode) from CROPINFO where DELFLAG=1";
            SqlConnection con    = DataBaseOperate.getSqlCon();
            SqlCommand    cmd    = DataBaseOperate.getSqlCmd(strsql, con);
            int           count  = Convert.ToInt32(cmd.ExecuteScalar());

            con.Close();
            return(count);
        }
        /// <summary>
        /// 获取NutrientCount
        /// </summary>
        /// <param name="plotid"></param>
        /// <returns></returns>
        public static int get_NutrientCount()
        {
            List <string> list   = new List <string>();
            string        strsql = "select count(distinct NUTRIENT_CODE) from SOILNUTRIENT_CODE where DELFLAG='1'";
            SqlConnection con    = DataBaseOperate.getSqlCon();
            SqlCommand    cmd    = DataBaseOperate.getSqlCmd(strsql, con);
            int           count  = Convert.ToInt32(cmd.ExecuteScalar());

            con.Close();
            return(count);
        }
        /// <summary>
        /// 数据入库
        /// </summary>
        /// <param name="strsql"></param>
        /// <param name="param"></param>
        public static int InsertDatabase(string sqlProcedure, SqlParameter[] param)
        {
            SqlConnection con = DataBaseOperate.getSqlCon();
            SqlCommand    cmd = DataBaseOperate.getSqlCmd(sqlProcedure, con);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddRange(param);
            int result = cmd.ExecuteNonQuery();

            con.Close();
            return(result);
        }
        /// <summary>
        /// 获取具体的时间列表
        /// </summary>
        /// <param name="time1">时间1</param>
        /// <param name="time2">时间2</param>
        /// <param name="corpName">具体表</param>
        /// <returns></returns>
        public static List <string> get_DateDetail(DateTime time1, DateTime time2, string corpName)
        {
            string str_datevalue = "select distinct MONITORTIME from " + corpName + " where MONITORTIME between @time1 and @time2";

            SqlParameter[] param_date = new SqlParameter[] {
                new SqlParameter("@time1", time1),
                new SqlParameter("@time2", time2)
            };
            List <string> date_list = DataBaseOperate.getIncludeTime(str_datevalue, param_date);

            return(date_list);
        }
        /// <summary>
        /// 处在选择的时间范围内的天数
        /// </summary>
        /// <param name="time1">时间1</param>
        /// <param name="time2">时间2</param>
        /// <param name="corpName">具体表</param>
        /// <returns></returns>
        public static int get_DateCount(DateTime time1, DateTime time2, string corpName)
        {
            string str_datecount = "select count(distinct MONITORTIME) from " + corpName + " where MONITORTIME between @time1 and @time2";

            SqlParameter[] param_date = new SqlParameter[] {
                new SqlParameter("@time1", time1),
                new SqlParameter("@time2", time2)
            };

            int count = DataBaseOperate.getIncludeTimeCount(str_datecount, param_date);

            return(count);
        }
        /// <summary>
        /// 获取处在某一时间段内的时间个数,用于循环汇总
        /// </summary>
        /// <param name="strsql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public static int getIncludeTimeCount(string strsql, SqlParameter[] param)
        {
            //string strsql = "select count(MONITORTIME) from MONITORTIME between @time1 and @time2";
            SqlConnection con = DataBaseOperate.getSqlCon();
            SqlCommand    cmd = DataBaseOperate.getSqlCmd(strsql, con);

            cmd.Parameters.AddRange(param);
            int count = Convert.ToInt32(cmd.ExecuteScalar());

            con.Close();
            cmd.Parameters.Clear();
            return(count);
        }
        /// <summary>
        /// 根据作物名称获取Nutrient_code
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static string get_NutrientCode(string name)
        {
            string        value  = "";
            string        strsql = "select NUTRIENT_CODE from SOILNUTRIENT_CODE where [NUTRIENT_NAME]='" + name + "'";
            SqlConnection con    = DataBaseOperate.getSqlCon();
            SqlCommand    cmd    = DataBaseOperate.getSqlCmd(strsql, con);
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                value = reader[0].ToString();
            }
            con.Close();
            return(value);
        }
        /// <summary>
        /// 获取NutrientCode
        /// </summary>
        /// <param name="plotid"></param>
        /// <returns></returns>
        public static List <string> get_NutrientCode()
        {
            List <string> list   = new List <string>();
            string        strsql = "select distinct NUTRIENT_CODE from SOILNUTRIENT_CODE where DELFLAG='1'";
            SqlConnection con    = DataBaseOperate.getSqlCon();
            SqlCommand    cmd    = DataBaseOperate.getSqlCmd(strsql, con);
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                list.Add(reader[0].ToString());
            }
            con.Close();
            return(list);
        }
        /// <summary>
        /// 根据作物名称获取crop_code
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static string get_CropCode(string name)
        {
            string        value  = "";
            string        strsql = "select CropCode from CROPINFO where [CropName]='" + name + "' and DELFLAG=1";
            SqlConnection con    = DataBaseOperate.getSqlCon();
            SqlCommand    cmd    = DataBaseOperate.getSqlCmd(strsql, con);
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                value = reader[0].ToString();
            }
            con.Close();
            return(value);
        }
        /// <summary>
        /// 获取CropCode
        /// </summary>
        /// <param name="plotid"></param>
        /// <returns></returns>
        public static List <string> get_CropCode()
        {
            List <string> list   = new List <string>();
            string        strsql = "select distinct CropCode from CROPINFO where DELFLAG=1";
            SqlConnection con    = DataBaseOperate.getSqlCon();
            SqlCommand    cmd    = DataBaseOperate.getSqlCmd(strsql, con);
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                list.Add(reader[0].ToString());
            }
            con.Close();
            return(list);
        }
        /// <summary>
        /// 获取作物代码和名称,并绑定数据源
        /// </summary>
        /// <returns></returns>
        public static Dictionary <string, string> setCropSource()
        {
            Dictionary <string, string> source = new Dictionary <string, string>();
            string        strsql = "select [CropCode],[CropName] from CROPINFO where DELFLAG=1";
            SqlConnection con    = DataBaseOperate.getSqlCon();
            SqlCommand    cmd    = DataBaseOperate.getSqlCmd(strsql, con);
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                source.Add(reader["CropCode"].ToString(), reader["CropName"].ToString());
            }
            con.Close();
            return(source);
        }
        /// <summary>
        /// 获取结果
        /// </summary>
        /// <param name="strsql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public static string getResult(string strsql, SqlParameter param)
        {
            string        result = "";
            SqlConnection con    = DataBaseOperate.getSqlCon();
            SqlCommand    cmd    = DataBaseOperate.getSqlCmd(strsql, con);

            cmd.Parameters.Add(param);
            SqlDataReader read = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            while (read.Read())
            {
                result = read[0].ToString();
            }
            con.Close();
            return(result);
        }
        /// <summary>
        /// 获取处在某一时间段内的具体时间,用于汇总传参
        /// </summary>
        /// <param name="strsql"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public static List <string> getIncludeTime(string strsql, SqlParameter[] param)
        {
            List <string> list = new List <string>();
            //string strsql = "select MONITORTIME from MONITORTIME between @time1 and @time2";
            SqlConnection con = DataBaseOperate.getSqlCon();
            SqlCommand    cmd = DataBaseOperate.getSqlCmd(strsql, con);

            cmd.Parameters.AddRange(param);
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                list.Add(reader[0].ToString());
            }
            con.Close();
            cmd.Parameters.Clear();
            return(list);
        }
Esempio n. 14
0
        private void btn_InDatabase_Click(object sender, EventArgs e)
        {
            int    result      = 0;
            string sVI_TYPE    = this.cbx_VIType.Text.Trim();
            string sVI_STATYPE = this.cbx_StaValueType.Text.Trim();
            float  fVI         = 0.00f;

            for (int i = 1; i < dtInfo.Rows.Count - 1; i++)
            {
                string str = dtInfo.Rows[i][5].ToString();
                bool   b   = float.TryParse(str, out fVI);
                if (!b || str.Contains("正"))
                {
                    str = "0.00";
                }
                string sSensorType = "1";
                if (this.cbx_sensortype.Text.Trim() == "WFV")
                {
                    sSensorType = "3";
                }
                SqlParameter[] param = new SqlParameter[] {
                    new SqlParameter("@PLOTID", dtInfo.Rows[i]["地块编号"]),
                    new SqlParameter("@MONITORTIME", dtInfo.Rows[i]["监测时间"]),
                    new SqlParameter("@CROP_CODE", 10),
                    new SqlParameter("@VI_TYPE", sVI_TYPE),
                    new SqlParameter("@VI_STATYPE", sVI_STATYPE),

                    new SqlParameter("@VI_VALUE", str),
                    new SqlParameter("@SENSORTYPE", sSensorType),
                    new SqlParameter("@RECORDTIME", DateTime.Now)
                };
                result = DataBaseOperate.InsertDatabase("insert_Plot_VI", param);
            }
            if (result > 0)
            {
                MessageBox.Show("入库成功!");
            }
        }
        private void btn_ok_Click(object sender, EventArgs e)
        {
            #region 输入与输出路径条件判断
            if (this.listViewImage.Items.Count <= 0)
            {
                MessageBox.Show("请选择输入影像!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (this.txt_ReferenceImage.Text.Equals(""))
            {
                MessageBox.Show("请输入统计单元文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            string txt_SHPFile = this.txt_ReferenceImage.Text.Trim();

            #endregion
            this.btn_ok.Enabled = false;

            #region 执行
            this.progressBar.Visible = true;
            try
            {
                foreach (ListViewItem item in this.listViewImage.Items)
                {
                    string    sFile    = item.SubItems[0].Text.Trim();
                    string    filename = Path.GetFileNameWithoutExtension(sFile);
                    string [] res      = filename.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
                    string    sMorTime = res[4];
                    string    sVIType  = res[res.Length - 1].ToString();
                    if (!sVIType.Contains("NDVI") && !sVIType.Contains("EVI") && !sVIType.Contains("Band1") && !sVIType.Contains("Band2") && !sVIType.Contains("Band3") && !sVIType.Contains("Band4"))
                    {
                        break;
                    }
                    string sSensorType = res[1];
                    sSensorType = sSensorType.ToUpper();
                    string sSensorCode = "1";
                    if (sSensorType.Contains("CCD"))
                    {
                        sSensorCode = "1";
                    }
                    else if (sSensorType.Contains("WFV"))
                    {
                        sSensorCode = "3";
                    }
                    else
                    {
                        break;
                    }
                    ProgressFunc pd  = new ProgressFunc(this.ProgressBarInfo);
                    IntPtr       pre = this.Handle;
                    int          ire = 0;
                    //string strInFile = @"D:\share\Hongxingtest\wxf\text_data\soil\soil_organic1.tif";
                    char[] strInFileList = sFile.ToCharArray();

                    string strRegionFile     = txt_SHPFile;
                    char[] strRegionFileList = strRegionFile.ToCharArray();

                    string strField     = "RASTERID";
                    char[] strFieldList = strField.ToCharArray();

                    int nCount = ReadShape.getShapeCount(strRegionFile);

                    int[] pRegionCodeList = new int[nCount];

                    double[] padfResultList = new double[nCount];
                    if (Path.GetExtension(txt_SHPFile).Contains("shp"))
                    {
                        for (int iStatisticType = 0; iStatisticType < 3; iStatisticType++)
                        {
                            ire = GdalAlgInterface.ImageStatisticalByVector(strInFileList, strRegionFileList, strFieldList, iStatisticType, pRegionCodeList, padfResultList, padfResultList.Length, pd, pre);
                            int   result = 0;
                            float fVI    = 0.00f;
                            for (int i = 0; i < nCount; i++)
                            {
                                string sRASTERID = pRegionCodeList[i].ToString();

                                string sPlotID = DataBaseOperate.getPlotId(sRASTERID);

                                string sStatisticResult = padfResultList[i].ToString("0.00");
                                bool   b = float.TryParse(sStatisticResult, out fVI);
                                if (!b || sStatisticResult.Contains("正"))
                                {
                                    sStatisticResult = "0.00";
                                }
                                string sVI_STATYPE = "Mean";
                                if (iStatisticType == 0)
                                {
                                    sVI_STATYPE = "Min";
                                }
                                else if (iStatisticType == 1)
                                {
                                    sVI_STATYPE = "Max";
                                }

                                SqlParameter[] param = new SqlParameter[] {
                                    new SqlParameter("@PLOTID", sPlotID),
                                    new SqlParameter("@MONITORTIME", sMorTime),
                                    new SqlParameter("@CROP_CODE", 10),
                                    new SqlParameter("@VI_TYPE", sVIType),
                                    new SqlParameter("@VI_STATYPE", sVI_STATYPE),

                                    new SqlParameter("@VI_VALUE", sStatisticResult),
                                    new SqlParameter("@SENSORTYPE", sSensorCode),
                                    new SqlParameter("@RECORDTIME", DateTime.Now)
                                };
                                result = DataBaseOperate.InsertDatabase("insert_Plot_VI", param);
                            }
                        }
                    }
                    else
                    {
                        for (int iStatisticType = 0; iStatisticType < 3; iStatisticType++)
                        {
                            ire = GdalAlgInterface.ImageStatisticalByVector(strInFileList, strRegionFileList, strFieldList, iStatisticType, pRegionCodeList, padfResultList, padfResultList.Length, pd, pre);
                        }
                    }
                }

                MessageBox.Show("统计入库完毕", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.btn_ok.Enabled = true;
                //this.btn_OpenOutPut.Visible = true;
                this.progressBar.Visible = false;
            }
            catch (Exception ex)
            {
                this.progressBar.Visible = false;
                MessageBox.Show(ex.Message);
                return;
            }
            #endregion
        }
Esempio n. 16
0
        private void btn_classstatis_Click(object sender, EventArgs e)
        {
            #region 输入与输出路径条件判断

            string sImageInput = this.txt_ImageInput.Text.Trim();
            if (sImageInput.Equals(""))
            {
                MessageBox.Show("请选择待统计影像!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            //string filename = sImageInput.Substring(sImageInput.LastIndexOf("\\") + 1);
            //res = filename.Split(new char[] { '_', '.' }, StringSplitOptions.RemoveEmptyEntries);
            string filename = Path.GetFileNameWithoutExtension(sImageInput);
            res = filename.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
            string sMorTime     = res[4];
            string sResultTitle = this.cbx_VIType.Text.Trim();
            string sSensorType  = this.cbx_sensortype.Text.Trim();
            string sStaType     = this.cbx_StaValueType.Text.Trim();
            #endregion

            //调用进度条界面线程
            //Thread t = new Thread(new ThreadStart(thread1));
            //t.Start();
            #region 执行统计

            try
            {
                ProgressFunc pd  = new ProgressFunc(this.ProgressBarInfo);
                IntPtr       pre = this.Handle;
                int          ire = 0;

                //string strInFile = @"D:\share\Hongxingtest\wxf\text_data\soil\soil_organic1.tif";
                char[] strInFileList = sImageInput.ToCharArray();

                string strRegionFile     = this.txt_SHPFile.Text.Trim();
                char[] strRegionFileList = strRegionFile.ToCharArray();

                string strField     = "RASTERID";
                char[] strFieldList = strField.ToCharArray();

                int nCount = ReadShape.getShapeCount(strRegionFile);

                int[] pRegionCodeList = new int[nCount];

                double[] padfResultList = new double[nCount];

                int iStatisticType = 2; //默认为平均值
                if (sStaType == "Max")
                {
                    iStatisticType = 1;
                }
                else if (sStaType == "Min")
                {
                    iStatisticType = 0;
                }

                ire = GdalAlgInterface.ImageStatisticalByVector(strInFileList, strRegionFileList, strFieldList, iStatisticType, pRegionCodeList, padfResultList, padfResultList.Length, pd, pre);
                //第三步
                //运行成功或失败,停止线程,即终止进度条。
                //t.Abort();
                string[,] arrStatistic = new string[nCount, 8];
                for (int i = 0; i < nCount; i++)
                {
                    string sRASTERID = pRegionCodeList[i].ToString();
                    arrStatistic[i, 0] = sMorTime;//文件名中的时间,从文件名中解析,此处获取的系统时间只为测试
                    arrStatistic[i, 1] = DataBaseOperate.getTownName(DataBaseOperate.getGLQ(sRASTERID));
                    //arrStatistic[i, 1] = sGLQName;
                    arrStatistic[i, 2] = DataBaseOperate.getVillName(DataBaseOperate.getJMZ(sRASTERID));
                    //arrStatistic[i, 2] = sJMZName;
                    //arrStatistic[i, 3] = sPlotName;
                    arrStatistic[i, 3] = DataBaseOperate.getPlotName(sRASTERID);
                    arrStatistic[i, 4] = DataBaseOperate.getPlotId(sRASTERID);
                    //arrStatistic[i, 4] = sRASTERID; "区域代码"
                    arrStatistic[i, 5] = padfResultList[i].ToString("0.00");
                    arrStatistic[i, 6] = sSensorType;
                    arrStatistic[i, 7] = sStaType;
                }
                //string sResultTitle = DataBaseOperate.getNUTRIENTTableTitleName(res[2]);

                //表头
                string[] arrName = { "监测时间", "作业区", "作业站", "地块名称", "地块编号", sResultTitle, "传感器类型", "统计类型" };
                //数组行按","拆分后转DataTable
                dtInfo = StringFormater.Convert(arrName, arrStatistic);
                InitDataSet();
                //dgvInfo.DataSource = dt;
            }
            catch (Exception ex)
            {
                //第三步
                //运行成功或失败,停止线程,即终止进度条。
                //t.Abort();
                MessageBox.Show(ex.Message);
            }
            #endregion
        }