protected void initialise(Condition isDone, ProgressFunc progress, Callback onComplete)
 {
     this.isDone     = isDone;
     this.progress   = progress;
     this.OnComplete = onComplete;
     GameManager.instance.StartCoroutine(start());
 }
Beispiel #2
0
        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_ImageOutPath.Text.Equals(""))
            {
                MessageBox.Show("请选择输出路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            #endregion
            this.btn_ok.Enabled = false;

            #region 界面参数获取
            string sFiles = "";
            foreach (ListViewItem item in this.listViewImage.Items)
            {
                string sFile = item.SubItems[0].Text.Trim();
                sFiles += sFile + "*";
            }
            sFiles = sFiles.Substring(0, sFiles.Length - 1);
            string sImageOutPath = this.txt_ImageOutPath.Text.Trim();
            #endregion

            #region 执行合成
            this.progressBar.Visible = true;
            try
            {
                ProgressFunc pd             = new ProgressFunc(this.ProgressBarInfo);
                IntPtr       pre            = this.Handle;
                int          ire            = 0;
                char[]       strInFileList  = sFiles.ToCharArray();
                char[]       strOutFileList = sImageOutPath.ToCharArray();
                ire = GdalAlgInterface.ImageLayerStack(strInFileList, strOutFileList, 0, false, "GTiff", 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
        }
        public static T TraceProgressOn <T>(ProgressFunc <T> func, ProgressProxy proxy)
        {
            var previousContext = SynchronizationContext.Current;

            try {
                var syncContext = new CurrentThreadSynchronizationContext();
                SynchronizationContext.SetSynchronizationContext(syncContext);

                proxy.progress = new Progress <ProgressValue>(v => proxy.Report(v));

                var task = Task.Run(() => func(proxy.progress));
                task.ContinueWith(delegate { syncContext.Complete(); }, TaskScheduler.Default);

                syncContext.RunOnCurrentThread();

                return(task.GetAwaiter().GetResult());
            } finally {
                SynchronizationContext.SetSynchronizationContext(previousContext);
            }
        }
Beispiel #4
0
    public AssetBundleData createAssetBundle(string path, ProgressFunc func, ClearOnSceneSwitch clearOnSceneSwitch)
    {
        LoggerHelper.Debug("createAssetBundle:" + path);
        AssetBundleRef ref2 = null;

        if (this.assetBundleMaps_.TryGetValue(path, out ref2))
        {
            ref2.AddRef();
            return(ref2.CreateData());
        }
        if (NoDoneAssetBundleDic.TryGetValue(path, out ref2))
        {
            NoDoneAssetBundleDic.Remove(path);
            ref2.AddRef();
            this.assetBundleMaps_[path] = ref2;
            return(ref2.CreateData());
        }
        ref2 = AssetBundleRef.Create(path, func, clearOnSceneSwitch);
        this.assetBundleMaps_[path] = ref2;
        ref2.AddRef();
        return(ref2.CreateData());
    }
Beispiel #5
0
        /// <summary>Called when building the line index completes (success or failure)</summary>
        private void MergeResults(State d, List <RangeI> n_line_index, bool reload, ProgressFunc progress)
        {
            // This method runs in the main thread, so if the build issue is the same at
            // the start of this method it can't be changed until after this function returns.
            if (!progress(0, n_line_index.Count))
            {
                return;
            }

            // Both old and new ranges are expected to be contiguous
            var old_rng   = Tools.GetRange(m_line_index);
            var new_rng   = Tools.GetRange(n_line_index);
            int row_delta = 0;

            // Replace 'm_line_index' with 'line_index'
            if (reload)
            {
                // Try to determine the row delta
                // Use any range overlap to work out the row delta.
                // If the ranges overlap, we can search for the start address of the intersection in both
                // ranges to get the row delta. If the don't overlap, the best we can do is say the direction.
                var intersect = old_rng.Intersect(new_rng);
                if (!intersect.Empty)
                {
                    var old_idx = FindIndex(m_line_index, intersect.Beg);
                    var new_idx = FindIndex(n_line_index, intersect.Beg);
                    row_delta = new_idx - old_idx;
                }
                else
                {
                    row_delta = intersect.Beg == old_rng.End ? -n_line_index.Count : n_line_index.Count;
                }

                // Replace the line index
                m_line_index.Assign(n_line_index);
            }

            // The new range is to the left of the old range
            else if (new_rng.Beg < old_rng.Beg && new_rng.End <= old_rng.End)
            {
                // Make sure there's no overlap by removing data from 'm_line_index'
                var trim = 0;
                for (; trim != m_line_index.Count && m_line_index[trim].Beg < new_rng.End; ++trim)
                {
                }
                m_line_index.RemoveRange(0, trim);
                row_delta -= trim;

                // Insert the new lines
                m_line_index.InsertRange(0, n_line_index);
                row_delta += n_line_index.Count;

                // Trim the tail
                if (m_line_index.Count > d.m_line_cache_count)
                {
                    m_line_index.RemoveRange(d.m_line_cache_count, m_line_index.Count - d.m_line_cache_count);
                }
            }

            // The new range is to the right of the old range
            else if (new_rng.Beg >= old_rng.Beg && new_rng.End > old_rng.End)
            {
                // Make sure there's no overlap by removing data from 'm_line_index'
                var trim = 0;
                for (; trim != m_line_index.Count && m_line_index.Back(trim).End > new_rng.Beg; ++trim)
                {
                }
                m_line_index.RemoveRange(m_line_index.Count - trim, trim);

                // Insert the new lines
                m_line_index.InsertRange(m_line_index.Count, n_line_index);

                // Trim the head
                if (m_line_index.Count > d.m_line_cache_count)
                {
                    row_delta -= m_line_index.Count - d.m_line_cache_count;
                    m_line_index.RemoveRange(0, m_line_index.Count - d.m_line_cache_count);
                }
            }

            // Save the new index state
            m_state = d;

            // Notify of update complete
            BuildComplete?.Invoke(this, new BuildCompleteEventArgs(new_rng, row_delta));
        }
Beispiel #6
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);
            if (filename.Contains("-"))
            {
                res = filename.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
            }
            else
            {
                res = filename.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
            }
            string sMorTime     = res[4];
            string sResultTitle = this.cbx_VIType.Text.Trim();
            string sField       = this.cbx_FieldName.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();

                char[] strFieldList = sField.ToCharArray();



                List <string> fielddatalist = ReadShape.getShapeFieldDataList(strRegionFile, sField);
                int           nCount        = fielddatalist.Count;

                List <int> intfdlist       = new List <int>(nCount);
                int[]      pRegionCodeList = new int[nCount];
                //for (int i = 0; i < nCount; i++)
                //{
                //    //转LIST出错
                //    intfdlist.Add(int.Parse(fielddatalist[i]));
                //}

                //int[] pRegionCodeList = intfdlist.ToArray();

                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, 4];
                for (int i = 0; i < nCount; i++)
                {
                    arrStatistic[i, 0] = sMorTime;//文件名中的时间,从文件名中解析,此处获取的系统时间只为测试
                    arrStatistic[i, 1] = pRegionCodeList[i].ToString();
                    arrStatistic[i, 2] = padfResultList[i].ToString("0.00");
                    arrStatistic[i, 3] = 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
        }
Beispiel #7
0
        /// <summary>Scan the file from 'filepos' adding whole lines to 'line_index' until 'length' bytes have been read or 'add_line' returns false</summary>
        /// <param name="file">The file to scan</param>
        /// <param name="filepos">The position in the file to start scanning from</param>
        /// <param name="fileend">The current known length of the file</param>
        /// <param name="backward">The direction to scan</param>
        /// <param name="length">The number of bytes to scan over</param>
        /// <param name="add_line">Callback function called with each detected line</param>
        /// <param name="encoding">The text file encoding</param>
        /// <param name="row_delim">The bytes that identify an end of line</param>
        /// <param name="buf">A buffer to use when buffering file data</param>
        /// <param name="progress">Callback function to report progress and allow the find to abort</param>
        private static void FindLines(IFileSource file, long filepos, long fileend, bool backward, long length, AddLineFunc add_line, Encoding encoding, byte[] row_delim, byte[] buf, ProgressFunc progress)
        {
            long scanned = 0, read_addr = filepos;

            for (;;)
            {
                // Progress update
                if (progress != null && !progress(scanned, length))
                {
                    return;
                }

                // Seek to the start position
                file.Stream.Seek(read_addr, SeekOrigin.Begin);

                // Buffer the contents of the file in 'buf'.
                long remaining = length - scanned; bool eof;
                int  read = Buffer(file, remaining, fileend, encoding, backward, buf, out eof);
                if (read == 0)
                {
                    break;
                }

                // Set iterator limits.
                // 'i' is where to start scanning from
                // 'iend' is the end of the range to scan
                // 'ilast' is the start of the last line found
                // 'base_addr' is the file offset from which buf was read
                int  i         = backward ? read - 1 : 0;
                int  iend      = backward ? -1 : read;
                int  lasti     = backward ? read : 0;
                long base_addr = backward ? file.Stream.Position : file.Stream.Position - read;

                // If we're searching backwards and 'i' is at the end of a line,
                // we don't want to count that as the first found line so adjust 'i'.
                // If not however, then 'i' is partway through a line or at the end
                // of a file without a row delimiter at the end and we want to include
                // this (possibly partial) line.
                if (backward && IsRowDelim(buf, read - row_delim.Length, row_delim))
                {
                    i -= row_delim.Length;
                }

                // Scan the buffer for lines
                for (i = Misc.FindNextDelim(buf, i, read, row_delim, backward); i != iend; i = Misc.FindNextDelim(buf, i, read, row_delim, backward))
                {
                    // 'i' points to the start of a line,
                    // 'lasti' points to the start of the last line we found
                    // Get the range in buf containing the line
                    RangeI line = backward
                                                ? new RangeI(i, lasti - row_delim.Length)
                                                : new RangeI(lasti, i - row_delim.Length);

                    // Pass the detected line to the callback
                    if (!add_line(line, base_addr, fileend, buf, encoding))
                    {
                        return;
                    }

                    lasti = i;
                    if (backward)
                    {
                        i -= row_delim.Length + 1;
                    }
                }

                // From 'lasti' to the end (or start in the backwards case) of the buffer represents
                // a (possibly partial) line. If we read a full buffer load last time, then we'll go
                // round again trying to read another buffer load, starting from 'lasti'.
                if (read == buf.Length)
                {
                    // Make sure we're always making progress
                    long scan_increment = backward ? (read - lasti) : lasti;
                    if (scan_increment == 0)                     // No lines detected in this block
                    {
                        throw new NoLinesException(read);
                    }

                    scanned  += scan_increment;
                    read_addr = filepos + (backward ? -scanned : +scanned);
                }
                // Otherwise, we're read to the end (or start) of the file, or to the limit 'length'.
                // What's left in the buffer may be a partial line.
                else
                {
                    // 'i' points to 'iend',
                    // 'lasti' points to the start of the last line we found
                    // Get the range in buf containing the line
                    RangeI line = backward
                                                ? new RangeI(i + 1, lasti - row_delim.Length)
                                                : new RangeI(lasti, i - (IsRowDelim(buf, i - row_delim.Length, row_delim) ? row_delim.Length : 0));

                    // ReSharper disable RedundantJumpStatement
                    // Pass the detected line to the callback
                    if (!add_line(line, base_addr, fileend, buf, encoding))
                    {
                        return;
                    }
                    // ReSharper restore RedundantJumpStatement

                    break;
                }
            }
        }
Beispiel #8
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();

            #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];
                ire = GdalAlgInterface.ImageStatisticalByVector(strInFileList, strRegionFileList, strFieldList, 2, pRegionCodeList, padfResultList, padfResultList.Length, pd, pre);
                //第三步
                //运行成功或失败,停止线程,即终止进度条。
                //t.Abort();
                string[,] arrStatistic = new string[nCount, 6];
                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");
                }
                //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
        }
Beispiel #9
0
        /// <summary>Scan the file from 'filepos' adding whole lines to 'line_index' until 'length' bytes have been read or 'add_line' returns false. Returns true if not interrupted</summary>
        private static bool FindLines(Stream src, long filepos, long fileend, bool backward, long length, AddLineFunc add_line, Encoding encoding, byte[] line_end, byte[] buf, ProgressFunc progress)
        {
            long scanned = 0, read_addr = filepos;

            for (; ;)
            {
                // Progress update
                if (!progress(scanned, length))
                {
                    return(false);
                }

                // Seek to the start position
                src.Seek(read_addr, SeekOrigin.Begin);

                // Buffer the contents of the file in 'buf'.
                var remaining = length - scanned;
                var read      = Buffer(src, remaining, fileend, encoding, backward, buf, out var eof);
                if (read == 0)
                {
                    break;
                }

                // Set iterator limits.
                // 'i' is where to start scanning from
                // 'iend' is the end of the range to scan
                // 'ilast' is the start of the last line found
                // 'base_addr' is the file offset from which buf was read
                var i         = backward ? read - 1 : 0;
                var iend      = backward ? -1 : read;
                var lasti     = backward ? read : 0;
                var base_addr = backward ? src.Position : src.Position - read;

                // If we're searching backwards and 'i' is at the end of a line,
                // we don't want to count that as the first found line so adjust 'i'.
                // If not however, then 'i' is partway through a line or at the end
                // of a file without a 'line_end' at the end and we want to include
                // this (possibly partial) line.
                if (backward && IsLineEnd(buf, read - line_end.Length, line_end))
                {
                    i -= line_end.Length;
                }

                // Scan the buffer for lines
                for (i = Tools.FindNextDelim(buf, i, read, line_end, backward); i != iend; i = Tools.FindNextDelim(buf, i, read, line_end, backward))
                {
                    // 'i' points to the start of a line,
                    // 'lasti' points to the start of the last line we found
                    // Get the range in buf containing the line
                    var line = backward
                                                ? new RangeI(i, lasti - line_end.Length)
                                                : new RangeI(lasti, i - line_end.Length);

                    // Pass the detected line to the callback
                    if (!add_line(line, base_addr, fileend, buf, encoding))
                    {
                        return(false);
                    }

                    lasti = i;
                    if (backward)
                    {
                        i -= line_end.Length + 1;
                    }
                }

                // From 'lasti' to the end (or start in the backwards case) of the buffer represents
                // a (possibly partial) line. If we read a full buffer load last time, then we'll go
                // round again trying to read another buffer load, starting from 'lasti'.
                if (read == buf.Length)
                {
                    // Make sure we're always making progress
                    var scan_increment = backward ? (read - lasti) : lasti;
                    if (scan_increment == 0)                     // No lines detected in this block
                    {
                        throw new NoLinesException(read);
                    }

                    scanned  += scan_increment;
                    read_addr = filepos + (backward ? -scanned : +scanned);
                }
                // Otherwise, we've read to the end (or start) of the file, or to the limit 'length'.
                // What's left in the buffer may be a partial line.
                else
                {
                    // 'i' points to 'iend',
                    // 'lasti' points to the start of the last line we found
                    // Get the range in buf containing the line
                    var line = backward
                                                ? new RangeI(i + 1, lasti - line_end.Length)
                                                : new RangeI(lasti, i - (IsLineEnd(buf, i - line_end.Length, line_end) ? line_end.Length : 0));

                    // Pass the detected line to the callback
                    if (!add_line(line, base_addr, fileend, buf, encoding))
                    {
                        return(false);
                    }

                    break;
                }
            }
            return(true);
        }
        private void btn_ok_Click(object sender, EventArgs e)
        { 
            #region 输入与输出路径条件判断
            if (this.txt_ImageInput.Text.Equals(""))
            {
                MessageBox.Show("请选择输入矢量文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            //if (this.cbx_FormatType.SelectedValue.ToString().Equals("请选择"))
            if (this.cbx_FormatType.Text.Equals(""))
            {
                MessageBox.Show("请选择转换字段!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            string sResolution = this.txt_resolution.Text;
            if (sResolution.Equals(""))
            {
                MessageBox.Show("请输入分辨率数值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            int NResolution = 30;
            bool BResolution = int.TryParse(sResolution, out NResolution);

            if (!BResolution)
            {
                MessageBox.Show("请输入数字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (this.txt_ImageOutPath.Text.Equals(""))
            {
                MessageBox.Show("请选择输出路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            
            #endregion
            this.btn_ok.Enabled = false;
            #region 界面参数获取
            string strVectorFile = txt_ImageInput.Text.Trim();
            //string strField = this.cbx_FormatType.SelectedValue.ToString();
            string strField = this.cbx_FormatType.Text.Trim();
            string strRasterFile = this.txt_ImageOutPath.Text.Trim();
            //string sFileName = FileManage.getFileName(strVectorFile);
            string sFileName = Path.GetFileNameWithoutExtension(strVectorFile);
            strRasterFile = strRasterFile + "\\" + sFileName+".tif";


            #endregion

            #region 调用转换算法
            //声明进度信息回调函数
            ProgressFunc pd = new ProgressFunc(this.ProgressBarInfo);
            IntPtr p = this.Handle;
            int ire = 0;
            this.progressBar.Visible = true;
            try
            {
                char[] strVectorFileList = strVectorFile.ToCharArray();

                char[] strRasterFileList = strRasterFile.ToCharArray();

                char[] strFieldList = strField.ToCharArray();

                ire = GdalAlgInterface.ShpRasterize(strVectorFileList, strRasterFileList, NResolution, 2, 0, strFieldList, "GTiff", pd, p);

                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

        }
Beispiel #11
0
        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 strMskFile = this.txt_ReferenceImage.Text.Trim();
            if (this.txt_ImageOutPath.Text.Equals(""))
            {
                MessageBox.Show("请选择输出路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            string sImageOutPath = this.txt_ImageOutPath.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 sOutFileName = sImageOutPath + "\\" + Path.GetFileNameWithoutExtension(sFile);
                    sOutFileName = sOutFileName.Replace("\\\\", "\\");
                    sOutFileName = sOutFileName + "_Clip.tif";
                    ProgressFunc pd             = new ProgressFunc(this.ProgressBarInfo);
                    IntPtr       pre            = this.Handle;
                    int          ire            = 0;
                    char[]       strInFileList  = sFile.ToCharArray();
                    char[]       strOutFileList = sOutFileName.ToCharArray();
                    char[]       pszMskFileList = strMskFile.ToCharArray();

                    //int[] nBand = new int[1];
                    //nBand[0] = 1;

                    if (Path.GetExtension(strMskFile).Contains("shp"))
                    {
                        ire = GdalAlgInterface.ImageSubsetAoi(strInFileList, strOutFileList, pszMskFileList, null, null, 0, "GTiff", pd, pre);
                    }
                    else
                    {
                        ire = GdalAlgInterface.ImageSubsetMask(strInFileList, strOutFileList, pszMskFileList, null, 0, "GTiff", 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
        }
Beispiel #12
0
        public static ClipperLib.PolyTree ExecuteClipper(TmxMap tmxMap, TmxLayer tmxLayer, TransformPointFunc xfFunc, ProgressFunc progFunc)
        {
            // The "fullClipper" combines the clipper results from the smaller pieces
            ClipperLib.Clipper fullClipper = new ClipperLib.Clipper();

            // From the perspective of Clipper lines are polygons too
            // Closed paths == polygons
            // Open paths == lines
            var polygonGroups = from y in Enumerable.Range(0, tmxLayer.Height)
                                from x in Enumerable.Range(0, tmxLayer.Width)
                                let rawTileId = tmxLayer.GetRawTileIdAt(x, y)
                                let tileId = TmxMath.GetTileIdWithoutFlags(rawTileId)
                                where tileId != 0
                                let tile = tmxMap.Tiles[tileId]
                                from polygon in tile.ObjectGroup.Objects
                                where (polygon as TmxHasPoints) != null
                                let groupX = x / LayerClipper.GroupBySize
                                let groupY = y / LayerClipper.GroupBySize
                                group new
                                {
                                    PositionOnMap = tmxMap.GetMapPositionAt(x, y, tile),
                                    HasPointsInterface = polygon as TmxHasPoints,
                                    TmxObjectInterface = polygon,
                                    IsFlippedDiagnoally = TmxMath.IsTileFlippedDiagonally(rawTileId),
                                    IsFlippedHorizontally = TmxMath.IsTileFlippedHorizontally(rawTileId),
                                    IsFlippedVertically = TmxMath.IsTileFlippedVertically(rawTileId),
                                    TileCenter = new PointF(tile.TileSize.Width * 0.5f, tile.TileSize.Height * 0.5f),
                                }
                                by Tuple.Create(groupX, groupY);

            int groupIndex = 0;
            int groupCount = polygonGroups.Count();

            foreach (var polyGroup in polygonGroups)
            {
                if (groupIndex % 5 == 0)
                {
                    progFunc(String.Format("Clipping '{0}' polygons: {1}%", tmxLayer.Name, (groupIndex / (float)groupCount) * 100));
                }
                groupIndex++;

                // The "groupClipper" clips the polygons in a smaller part of the world
                ClipperLib.Clipper groupClipper = new ClipperLib.Clipper();

                // Add all our polygons to the Clipper library so it can reduce all the polygons to a (hopefully small) number of paths
                foreach (var poly in polyGroup)
                {
                    // Create a clipper library polygon out of each and add it to our collection
                    ClipperPolygon clipperPolygon = new ClipperPolygon();

                    // Our points may be transformed due to tile flipping/rotation
                    // Before we transform them we put all the points into local space relative to the tile
                    SizeF offset = new SizeF(poly.TmxObjectInterface.Position);
                    PointF[] transformedPoints = poly.HasPointsInterface.Points.Select(pt => PointF.Add(pt, offset)).ToArray();

                    // Now transform the points relative to the tile
                    TmxMath.TransformPoints(transformedPoints, poly.TileCenter, poly.IsFlippedDiagnoally, poly.IsFlippedHorizontally, poly.IsFlippedVertically);

                    foreach (var pt in transformedPoints)
                    {
                        float x = poly.PositionOnMap.X + pt.X;
                        float y = poly.PositionOnMap.Y + pt.Y;

                        ClipperLib.IntPoint point = xfFunc(x, y);
                        clipperPolygon.Add(point);
                    }

                    // Because of Unity's cooridnate system, the winding order of the polygons must be reversed
                    clipperPolygon.Reverse();

                    // Add the "subject"
                    groupClipper.AddPath(clipperPolygon, ClipperLib.PolyType.ptSubject, poly.HasPointsInterface.ArePointsClosed());
                }

                // Get a solution for this group
                ClipperLib.PolyTree solution = new ClipperLib.PolyTree();
                groupClipper.Execute(ClipperLib.ClipType.ctUnion, solution, LayerClipper.SubjectFillRule, LayerClipper.ClipFillRule);

                // Combine the solutions into the full clipper
                fullClipper.AddPaths(ClipperLib.Clipper.ClosedPathsFromPolyTree(solution), ClipperLib.PolyType.ptSubject, true);
                fullClipper.AddPaths(ClipperLib.Clipper.OpenPathsFromPolyTree(solution), ClipperLib.PolyType.ptSubject, false);
            }
            progFunc(String.Format("Clipping '{0}' polygons: 100%", tmxLayer.Name));

            ClipperLib.PolyTree fullSolution = new ClipperLib.PolyTree();
            fullClipper.Execute(ClipperLib.ClipType.ctUnion, fullSolution, LayerClipper.SubjectFillRule, LayerClipper.ClipFillRule);

            return fullSolution;
        }
Beispiel #13
0
 public AssetBundleData CreateAssetBundleThatDoNotClearOnSceneSwitch(string path, ProgressFunc func)
 {
     return(this.createAssetBundle(path, func, ClearOnSceneSwitch.No));
 }
Beispiel #14
0
        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 strMskFile = this.txt_ReferenceImage.Text.Trim();
            if (this.txt_ImageOutPath.Text.Equals(""))
            {
                MessageBox.Show("请选择输出路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            string sImageOutPath = this.txt_ImageOutPath.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 sOutFileName = sImageOutPath + "\\" + Path.GetFileNameWithoutExtension(sFile);
                    sOutFileName = sOutFileName.Replace("\\\\", "\\");
                    sOutFileName = sOutFileName + "_Clip.tif";
                    ProgressFunc pd = new ProgressFunc(this.ProgressBarInfo);
                    IntPtr pre = this.Handle;
                    int ire = 0;
                    char[] strInFileList = sFile.ToCharArray();
                    char[] strOutFileList = sOutFileName.ToCharArray();
                    char[] pszMskFileList = strMskFile.ToCharArray();

                    //int[] nBand = new int[1];
                    //nBand[0] = 1;

                    if (Path.GetExtension(strMskFile).Contains("shp"))
                    {
                        ire = GdalAlgInterface.ImageSubsetAoi(strInFileList, strOutFileList, pszMskFileList, null,null, 0, "GTiff", pd, pre);
                    }
                    else
                    {
                        ire = GdalAlgInterface.ImageSubsetMask(strInFileList, strOutFileList, pszMskFileList, null, 0, "GTiff", 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

        }
 public CustomAsyncOperation(Condition isDone, ProgressFunc progress, Callback onComplete)
 {
     initialise(isDone, progress, onComplete);
 }
 public CustomAsyncOperation(Condition isDone, ProgressFunc progress) : this(isDone, progress, op => {})
 {
 }
        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
        }
Beispiel #18
0
        /// <summary>Update the line index</summary>
        private static List <RangeI> BuildAsync(ref State d, Stream src, bool reload, ProgressFunc progress)        // Worker thread context
        {
            // This method runs in a background thread
            // All we're doing here is loading data around 'd.filepos' so that there are an equal number
            // of lines on either side. This can be optimised however because the existing range of
            // cached data probably overlaps the range we want loaded.
            if (!progress(0, d.m_fileend))
            {
                return(new List <RangeI>());
            }

            // A temporary buffer for reading sections of the file
            var buf = new byte[d.m_max_line_length];

            // Seek to the first line that starts immediately before 'filepos'
            d.m_filepos = FindLineStart(src, d.m_filepos, d.m_fileend, d.m_line_end, d.m_encoding, buf);

            // Determine the range to scan and the number of lines in each direction
            var bwd_first  = (d.m_fileend - d.m_filepos) > (d.m_filepos - 0);            // scan in the most bound direction first
            var scan_range = CalcBufferRange(d.m_filepos, d.m_fileend, d.m_file_buffer_size);
            var line_range = CalcLineRange(d.m_line_cache_count);
            var bwd_lines  = line_range.Begi;
            var fwd_lines  = line_range.Endi;

            // Incremental loading - only load what isn't already cached.
            // If the 'filepos' is left of the cache centre, try to extent in left direction first.
            // If the scan range in that direction is empty, try extending at the other end. The
            // aim is to try to get d.line_index_count as close to d.line_cache_count as possible
            // without loading data that is already cached.
            if (!reload && !d.m_line_start_range.Empty)
            {
                AdjustForIncrementalBuild(d, ref bwd_first, ref scan_range, ref bwd_lines, ref fwd_lines);
            }

            // Check the number of lines does not exceed the settings value
            Debug.Assert(bwd_lines + fwd_lines <= d.m_line_cache_count);

            // Build the collection of line byte ranges to add to the cache
            var line_index = ScanForLines(src, d, bwd_first, scan_range, bwd_lines, fwd_lines, buf, progress);

            return(line_index);
        }
        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_ImageOutPath.Text.Equals(""))
            {
                MessageBox.Show("请选择输出路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            string sImageOutPath = this.txt_ImageOutPath.Text.Trim();
            #endregion
            this.btn_ok.Enabled = false;

            #region 界面参数获取

            

            #endregion

            #region 执行合成
            this.progressBar.Visible = true;
            try
            {
                
                foreach (ListViewItem item in this.listViewImage.Items)
                {
                    string sFile = item.SubItems[0].Text.Trim();

                    if (!sFile.Contains("WFV") && !sFile.Contains("PMS") && !sFile.Contains("wfv") && !sFile.Contains("pms"))
                    {
                        MessageBox.Show("请输入包含传感器名称WFV或者PMS的影像!");
                        return;
                    }

                    string sFileName = Path.GetFileNameWithoutExtension(sFile);

                    string sSensorType = sFileName.Substring(4, 4);
                    sSensorType = sSensorType.ToUpper();
                    string[] BandCoefficients = new string[4];
                    switch (sSensorType)
                    {
                        case "PMS1":
                            BandCoefficients[0] = "*0.2082+4.6186";//第一波段定标系数
                            BandCoefficients[1] = "*0.1672+4.8768";//第二波段定标系数
                            BandCoefficients[2] = "*0.1748+4.8924";//第三波段定标系数
                            BandCoefficients[3] = "*0.1883-9.4771";//第四波段定标系数
                            break;
                        case "PMS2":
                            BandCoefficients[0] = "*0.2072+7.5348";//第一波段定标系数
                            BandCoefficients[1] = "*0.1776+3.9395";//第二波段定标系数
                            BandCoefficients[2] = "*0.177-1.7445";//第三波段定标系数
                            BandCoefficients[3] = "*0.1909-7.2053";//第四波段定标系数
                            break;
                        case "WFV1":
                            BandCoefficients[0] = "*0.1709-0.0039";//第一波段定标系数
                            BandCoefficients[1] = "*0.1398-0.0047";//第二波段定标系数
                            BandCoefficients[2] = "*0.1195-0.0030";//第三波段定标系数
                            BandCoefficients[3] = "*0.1338-0.0274";//第四波段定标系数
                            break;
                        case "WFV2":
                            BandCoefficients[0] = "*0.1588+5.5303";//第一波段定标系数
                            BandCoefficients[1] = "*0.1515-13.642";//第二波段定标系数
                            BandCoefficients[2] = "*0.1251-15.382";//第三波段定标系数
                            BandCoefficients[3] = "*0.1209-7.985";//第四波段定标系数
                            break;
                        case "WFV3":
                            BandCoefficients[0] = "*0.1556+12.28";//第一波段定标系数
                            BandCoefficients[1] = "*0.1700-7.9336";//第二波段定标系数
                            BandCoefficients[2] = "*0.1392-7.031";//第三波段定标系数
                            BandCoefficients[3] = "*0.1354-4.3578";//第四波段定标系数
                            break;
                        case "WFV4":
                            BandCoefficients[0] = "*0.1819+3.6469";//第一波段定标系数
                            BandCoefficients[1] = "*0.1762-13.54";//第二波段定标系数
                            BandCoefficients[2] = "*0.1463-10.998";//第三波段定标系数
                            BandCoefficients[3] = "*0.1522-12.142";//第四波段定标系数
                            break;
                    }
                    //默认为NDVI计算输入波段数组
                    int[] nBand = new int[1];
                    string sOutFilePath = sImageOutPath + "\\" + sFileName;
                    sOutFilePath = sOutFilePath.Replace("\\\\", "\\");

                    //波段组合文件名组合参数
                    string sLayerStackName = "";
                    List<string> filelist = new List<string>();

                    for (int i = 1; i <= 4; i++)
                    {
                        string strFormula = "b" + i + "*1" + BandCoefficients[i-1];//默认为NDVI计算公式
                        nBand[0] = i;
                        
                        string sOutFileName = sOutFilePath + "_Band" + i + ".tif";
                        //组装波段组合的输入参数名,所有文件名组成一个字符串,中间用*连接
                        sLayerStackName += sOutFileName + "*";
                        filelist.Add(Path.GetFileName(sOutFileName));
                        ProgressFunc pd = new ProgressFunc(this.ProgressBarInfo);
                        IntPtr pre = this.Handle;
                        int ire = 0;
                        char[] strInFileList = sFile.ToCharArray();
                        char[] strOutFileList = sOutFileName.ToCharArray();

                        ire = GdalAlgInterface.ImageCalculate(strInFileList, strOutFileList, strFormula, nBand, "GTiff", pd, pre);
                        //Console.Write(ire.ToString());
                    }

                    //波段叠加输入波段影像
                    sLayerStackName = sLayerStackName.Substring(0, sLayerStackName.Length - 1);
                    //波段组合后输出影像文件名
                    string sLayerStackResult = sImageOutPath + "\\" + sFileName+"_radiocorrect.tif";
                    


                    ProgressFunc pd2 = new ProgressFunc(this.ProgressBarInfo);
                    IntPtr pre2 = this.Handle;
                    int ire2 = 0;
                    char[] strLayerInFileList = sLayerStackName.ToCharArray();
                    char[] strLayerOutFileList = sLayerStackResult.ToCharArray();
                    ire2 = GdalAlgInterface.ImageLayerStack(strLayerInFileList, strLayerOutFileList, 0, false, "GTiff", pd2, pre2);
                    //MessageBox.Show("波段合成完毕", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.btn_ok.Enabled = true;
                    //this.btn_OpenOutPut.Visible = true;
                    //this.progressBar.Visible = false;
                    FileManage pFileManage = new FileManage();
                    pFileManage.DeteleFiles(filelist,sImageOutPath+"\\");

                }
                
            }
            catch (Exception ex)
            {
                this.progressBar.Visible = false;
                MessageBox.Show(ex.Message);
                return;
            }
            finally
            {
                MessageBox.Show("波段提取并辐射定标完毕", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.btn_ok.Enabled = true;
                //this.btn_OpenOutPut.Visible = true;
                this.progressBar.Visible = false;
            }
            
            #endregion

        }
Beispiel #20
0
        /// <summary>Scan over the given range for lines</summary>
        private static List <RangeI> ScanForLines(Stream src, State d, bool bwd_first, RangeI scan_range, int bwd_lines, int fwd_lines, byte[] buf, ProgressFunc progress)
        {
            var line_index = new List <RangeI>();

            if (bwd_lines == 0 && fwd_lines == 0)
            {
                return(line_index);
            }

            // Line index buffers for collecting the results
            var fwd_line_buf = new List <RangeI>(fwd_lines);
            var bwd_line_buf = new List <RangeI>(bwd_lines);

            // Data used in the 'add_line' callback. Updated for forward and backward passes
            var lbd = new LineBufferData
            {
                line_buf   = null,               // pointer to either 'fwd_line_buf' or 'bwd_line_buf'
                line_limit = 0,                  // Caps the number of lines read for each of the forward and backward searches
            };

            // Callback for adding line byte ranges to a line buffer
            bool AddLine(RangeI line, long baddr, long fend, byte[] bf, Encoding enc)
            {
                if (line.Empty && d.m_ignore_blanks)
                {
                    return(true);
                }

                // Test 'text' against each filter to see if it's included
                // Note: not caching this string because we want to read immediate data
                // from the file to pick up file changes.
                string text = d.m_encoding.GetString(buf, (int)line.Beg, (int)line.Size);

                if (!PassesFilters(text, d.m_filters))
                {
                    return(true);
                }

                // Convert the byte range to a file range
                line = line.Shift(baddr);
                Debug.Assert(new RangeI(0, d.m_fileend).Contains(line));
                lbd.line_buf.Add(line);
                Debug.Assert(lbd.line_buf.Count <= lbd.line_limit);
                return((fwd_line_buf.Count + bwd_line_buf.Count) < lbd.line_limit);
            }

            // Callback for updating progress
            bool Progress(long _, long __)
            {
                var scanned = fwd_line_buf.Count + bwd_line_buf.Count;

                return(progress(scanned, lbd.line_limit));
            }

            // Scan twice, starting in the direction of the smallest range so that any
            // unused cache space is used by the search in the other direction.
            var scan_from = Math_.Clamp(d.m_filepos, scan_range.Beg, scan_range.End);

            for (int a = 0; a != 2; ++a, bwd_first = !bwd_first)
            {
                lbd.line_buf    = bwd_first ? bwd_line_buf : fwd_line_buf;
                lbd.line_limit += bwd_first ? bwd_lines : fwd_lines;
                if ((bwd_line_buf.Count + fwd_line_buf.Count) < lbd.line_limit)
                {
                    var length = bwd_first ? scan_from - scan_range.Beg : scan_range.End - scan_from;
                    if (!FindLines(src, scan_from, d.m_fileend, bwd_first, length, AddLine, d.m_encoding, d.m_line_end, buf, Progress))
                    {
                        break;
                    }
                }
            }

            // Scanning backward adds lines to the line index in reverse order.
            bwd_line_buf.Reverse();

            // 'line_index' should be a contiguous block of byte offset ranges for
            // the lines around 'd.m_filepos'. If 'reload' is false, then the line
            // index will only contain byte offset ranges that are not currently cached.
            line_index.Capacity = bwd_line_buf.Count + fwd_line_buf.Count;
            line_index.AddRange(bwd_line_buf);
            line_index.AddRange(fwd_line_buf);

            // Return the found line ranges
            return(line_index);
        }
        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_ImageOutPath.Text.Equals(""))
            {
                MessageBox.Show("请选择输出路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            string sImageOutPath = this.txt_ImageOutPath.Text.Trim();
            #endregion
            this.btn_ok.Enabled = false;

            #region 界面参数获取

            #endregion

            #region 执行合成
            this.progressBar.Visible = true;
            try
            {

                foreach (ListViewItem item in this.listViewImage.Items)
                {
                    string sFile = item.SubItems[0].Text.Trim();
                    string strFormula = "(b4-b3)/(b4+b3)*1.0";//默认为NDVI计算公式
                    string sFiles = sFile + "*" + sFile;//默认为NDVI计算输入数据个数,只用到2个波段,所以输入2遍,中间用*隔开
                    //默认为NDVI计算输入波段数组
                    int[] nBand = new int[2];
                    nBand[0] = 3;
                    nBand[1] = 4;
                    string sOutFileName = sImageOutPath +"\\"+ Path.GetFileNameWithoutExtension(sFile);
                    sOutFileName = sOutFileName.Replace("\\\\","\\");
                    switch (this.cbx_VIType.Text.Trim())
                    {
                        case "NDVI":
                            //sFiles = sFile + "*" + sFile;
                            //strFormula = "(b4-b3)/(b4+b3)*1.0";
                            //nBand = new int[2];
                            //nBand[0] = 3;
                            //nBand[1] = 4;
                            sOutFileName = sOutFileName + "_NDVI.tif";
                            break;
                        case "EVI":
                            sFiles = sFile + "*" + sFile + "*" + sFile;
                            strFormula = "2.5*(b4-b3)/(b4+6*b3-7.5*b1+1)";
                            nBand = new int[3];
                            nBand[0] = 1;
                            nBand[1] = 3;
                            nBand[2] = 4;
                            sOutFileName = sOutFileName + "_EVI.tif";
                            break;
                        case "Band1":
                            sFiles = sFile;
                            strFormula = "b1*1.0";
                            nBand = new int[1];
                            nBand[0] = 1;
                            sOutFileName = sOutFileName + "_Band1.tif";
                            break;
                        case "Band2":
                            sFiles = sFile;
                            strFormula = "b2*1.0";
                            nBand = new int[1];
                            nBand[0] = 2;
                            sOutFileName = sOutFileName + "_Band2.tif";
                            break;
                        case "Band3":
                            sFiles = sFile;
                            strFormula = "b3*1.0";
                            nBand = new int[1];
                            nBand[0] = 3;
                            sOutFileName = sOutFileName + "_Band3.tif";
                            break;
                        case "Band4":
                            sFiles = sFile;
                            strFormula = "b4*1.0";
                            nBand = new int[1];
                            nBand[0] = 4;
                            sOutFileName = sOutFileName + "_Band4.tif";
                            break;
                    }

                    ProgressFunc pd = new ProgressFunc(this.ProgressBarInfo);
                    IntPtr pre = this.Handle;
                    int ire = 0;
                    char[] strInFileList = sFiles.ToCharArray();
                    char[] strOutFileList = sOutFileName.ToCharArray();

                    ire = GdalAlgInterface.ImageCalculate(strInFileList, strOutFileList, strFormula, nBand, "GTiff", pd, pre);
                    //Console.Write(ire.ToString());
                }

            }
            catch (Exception ex)
            {
                this.progressBar.Visible = false;
                MessageBox.Show(ex.Message);
                return;
            }
            finally
            {
                MessageBox.Show("指数计算完毕", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.btn_ok.Enabled = true;
                //this.btn_OpenOutPut.Visible = true;
                this.progressBar.Visible = false;
            }

            #endregion
        }
        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

        }
        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);
            if (filename.Contains("-"))
            {
                res = filename.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
            }
            else
            {
                res = filename.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
            }
            string sMorTime = res[4];
            string sResultTitle = this.cbx_VIType.Text.Trim();
            string sField = this.cbx_FieldName.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();

                char[] strFieldList = sField.ToCharArray();



                List<string> fielddatalist = ReadShape.getShapeFieldDataList(strRegionFile, sField);
                int nCount = fielddatalist.Count;

                List<int> intfdlist = new List<int>(nCount);
                int[] pRegionCodeList = new int[nCount];
                //for (int i = 0; i < nCount; i++)
                //{
                //    //转LIST出错
                //    intfdlist.Add(int.Parse(fielddatalist[i]));
                //}

                //int[] pRegionCodeList = intfdlist.ToArray();

                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, 4];
                for (int i = 0; i < nCount; i++)
                {
                    arrStatistic[i, 0] = sMorTime;//文件名中的时间,从文件名中解析,此处获取的系统时间只为测试
                    arrStatistic[i, 1] = pRegionCodeList[i].ToString();
                    arrStatistic[i, 2] = padfResultList[i].ToString("0.00");
                    arrStatistic[i, 3] = 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
        }
Beispiel #24
0
        public static ClipperLib.PolyTree ExecuteClipper(TmxMap tmxMap, TmxLayer tmxLayer, TransformPointFunc xfFunc, ProgressFunc progFunc)
        {
            // The "fullClipper" combines the clipper results from the smaller pieces
            ClipperLib.Clipper fullClipper = new ClipperLib.Clipper();

            // Limit to polygon "type" that matches the collision layer name (unless we are overriding the whole layer to a specific Unity Layer Name)
            bool usingUnityLayerOverride = !String.IsNullOrEmpty(tmxLayer.UnityLayerOverrideName);

            // From the perspective of Clipper lines are polygons too
            // Closed paths == polygons
            // Open paths == lines
            Dictionary <TupleInt2, List <PolygonGroup> > polygonGroups = new Dictionary <TupleInt2, List <PolygonGroup> >();

            foreach (int y in Enumerable.Range(0, tmxLayer.Height))
            {
                foreach (int x in Enumerable.Range(0, tmxLayer.Width))
                {
                    uint rawTileId = tmxLayer.GetRawTileIdAt(x, y);
                    if (rawTileId == 0)
                    {
                        continue;
                    }

                    uint    tileId = TmxMath.GetTileIdWithoutFlags(rawTileId);
                    TmxTile tile   = tmxMap.Tiles[tileId];

                    foreach (TmxObject polygon in tile.ObjectGroup.Objects)
                    {
                        if (typeof(TmxHasPoints).IsAssignableFrom(polygon.GetType()) &&
                            (usingUnityLayerOverride || String.Compare(polygon.Type, tmxLayer.Name, true) == 0))
                        {
                            int groupX = x / LayerClipper.GroupBySize;
                            int groupY = y / LayerClipper.GroupBySize;

                            PolygonGroup poly = new PolygonGroup();
                            poly.PositionOnMap         = tmxMap.GetMapPositionAt(x, y, tile);
                            poly.HasPointsInterface    = polygon as TmxHasPoints;
                            poly.TmxObjectInterface    = polygon;
                            poly.IsFlippedDiagnoally   = TmxMath.IsTileFlippedDiagonally(rawTileId);
                            poly.IsFlippedHorizontally = TmxMath.IsTileFlippedHorizontally(rawTileId);
                            poly.IsFlippedVertically   = TmxMath.IsTileFlippedVertically(rawTileId);
                            poly.TileCenter            = new PointF(tile.TileSize.Width * 0.5f, tile.TileSize.Height * 0.5f);

                            TupleInt2 key = new TupleInt2(groupX, groupY);
                            if (!polygonGroups.ContainsKey(key))
                            {
                                polygonGroups[key] = new List <PolygonGroup>();
                            }
                            polygonGroups[key].Add(poly);
                        }
                    }
                }
            }
            // Tuple not supported in Mono 2.0 so doing this the old fashioned way, sorry
            //var polygonGroups = from y in Enumerable.Range(0, tmxLayer.Height)
            //                    from x in Enumerable.Range(0, tmxLayer.Width)
            //                    let rawTileId = tmxLayer.GetRawTileIdAt(x, y)
            //                    where rawTileId != 0
            //                    let tileId = TmxMath.GetTileIdWithoutFlags(rawTileId)
            //                    let tile = tmxMap.Tiles[tileId]
            //                    from polygon in tile.ObjectGroup.Objects
            //                    where (polygon as TmxHasPoints) != null
            //                    where  usingUnityLayerOverride || String.Compare(polygon.Type, tmxLayer.Name, true) == 0
            //                    let groupX = x / LayerClipper.GroupBySize
            //                    let groupY = y / LayerClipper.GroupBySize
            //                    group new
            //                    {
            //                        PositionOnMap = tmxMap.GetMapPositionAt(x, y, tile),
            //                        HasPointsInterface = polygon as TmxHasPoints,
            //                        TmxObjectInterface = polygon,
            //                        IsFlippedDiagnoally = TmxMath.IsTileFlippedDiagonally(rawTileId),
            //                        IsFlippedHorizontally = TmxMath.IsTileFlippedHorizontally(rawTileId),
            //                        IsFlippedVertically = TmxMath.IsTileFlippedVertically(rawTileId),
            //                        TileCenter = new PointF(tile.TileSize.Width * 0.5f, tile.TileSize.Height * 0.5f),
            //                    }
            //                    by Tuple.Create(groupX, groupY);

            int groupIndex = 0;
            int groupCount = polygonGroups.Count();

            foreach (TupleInt2 key in polygonGroups.Keys)
            {
                if (groupIndex % 5 == 0)
                {
                    progFunc(String.Format("Clipping '{0}' polygons: {1}%", tmxLayer.Name, (groupIndex / (float)groupCount) * 100));
                }
                groupIndex++;

                // The "groupClipper" clips the polygons in a smaller part of the world
                ClipperLib.Clipper groupClipper = new ClipperLib.Clipper();

                // Add all our polygons to the Clipper library so it can reduce all the polygons to a (hopefully small) number of paths
                foreach (PolygonGroup poly in polygonGroups[key])
                {
                    // Create a clipper library polygon out of each and add it to our collection
                    ClipperPolygon clipperPolygon = new ClipperPolygon();

                    // Our points may be transformed due to tile flipping/rotation
                    // Before we transform them we put all the points into local space relative to the tile
                    SizeF    offset            = new SizeF(poly.TmxObjectInterface.Position);
                    PointF[] transformedPoints = poly.HasPointsInterface.Points.Select(pt => PointF.Add(pt, offset)).ToArray();

                    // Now transform the points relative to the tile
                    TmxMath.TransformPoints(transformedPoints, poly.TileCenter, poly.IsFlippedDiagnoally, poly.IsFlippedHorizontally, poly.IsFlippedVertically);

                    foreach (var pt in transformedPoints)
                    {
                        float x = poly.PositionOnMap.X + pt.X;
                        float y = poly.PositionOnMap.Y + pt.Y;

                        ClipperLib.IntPoint point = xfFunc(x, y);
                        clipperPolygon.Add(point);
                    }

                    // Because of Unity's cooridnate system, the winding order of the polygons must be reversed
                    clipperPolygon.Reverse();

                    // Add the "subject"
                    groupClipper.AddPath(clipperPolygon, ClipperLib.PolyType.ptSubject, poly.HasPointsInterface.ArePointsClosed());
                }

                // Get a solution for this group
                ClipperLib.PolyTree solution = new ClipperLib.PolyTree();
                groupClipper.Execute(ClipperLib.ClipType.ctUnion, solution, LayerClipper.SubjectFillRule, LayerClipper.ClipFillRule);

                // Combine the solutions into the full clipper
                fullClipper.AddPaths(ClipperLib.Clipper.ClosedPathsFromPolyTree(solution), ClipperLib.PolyType.ptSubject, true);
                fullClipper.AddPaths(ClipperLib.Clipper.OpenPathsFromPolyTree(solution), ClipperLib.PolyType.ptSubject, false);
            }
            progFunc(String.Format("Clipping '{0}' polygons: 100%", tmxLayer.Name));

            ClipperLib.PolyTree fullSolution = new ClipperLib.PolyTree();
            fullClipper.Execute(ClipperLib.ClipType.ctUnion, fullSolution, LayerClipper.SubjectFillRule, LayerClipper.ClipFillRule);

            return(fullSolution);
        }
Beispiel #25
0
        /// <summary>The grunt work of building the new line index.</summary>
        private static void BuildLineIndexAsync(BLIData d, Action <BLIData, RangeI, List <RangeI>, Exception> on_complete)
        {
            // This method runs in a background thread
            // All we're doing here is loading data around 'd.filepos' so that there are an equal number
            // of lines on either side. This can be optimised however because the existing range of
            // cached data probably overlaps the range we want loaded.
            try
            {
                Log.Write(ELogLevel.Info, "BLIAsync", $"build started. (id {d.build_issue}, reload {d.reload})");
                if (BuildCancelled(d.build_issue))
                {
                    return;
                }
                using (d.file)
                {
                    // A temporary buffer for reading sections of the file
                    var buf = new byte[d.max_line_length];

                    // Seek to the first line that starts immediately before 'filepos'
                    d.filepos = FindLineStart(d.file, d.filepos, d.fileend, d.row_delim, d.encoding, buf);
                    if (BuildCancelled(d.build_issue))
                    {
                        return;
                    }

                    // Determine the range to scan and the number of lines in each direction
                    var scan_backward = (d.fileend - d.filepos) > (d.filepos - 0);                     // scan in the most bound direction first
                    var scan_range    = CalcBufferRange(d.filepos, d.fileend, d.file_buffer_size);
                    var line_range    = CalcLineRange(d.line_cache_count);
                    var bwd_lines     = line_range.Begi;
                    var fwd_lines     = line_range.Endi;

                    // Incremental loading - only load what isn't already cached.
                    // If the 'filepos' is left of the cache centre, try to extent in left direction first.
                    // If the scan range in that direction is empty, try extending at the other end. The
                    // aim is to try to get d.line_index_count as close to d.line_cache_count as possible
                    // without loading data that is already cached.
                    #region Incremental loading
                    if (!d.reload && !d.cached_whole_line_range.Empty)
                    {
                        // Determine the direction the cached range is moving based on where 'filepos' is relative
                        // to the current cache centre and which range contains an valid area to be scanned.
                        // With incremental scans we can only update one side of the cache because the returned line index has to
                        // be a contiguous block of lines. This means one of 'bwd_lines' or 'fwd_lines' must be zero.
                        var Lrange = new RangeI(scan_range.Beg, d.cached_whole_line_range.Beg);
                        var Rrange = new RangeI(d.cached_whole_line_range.End, scan_range.End);
                        var dir    =
                            (!Lrange.Empty && !Rrange.Empty) ? Math.Sign(2 * d.filepos_line_index - d.line_cache_count) :
                            (!Lrange.Empty) ? -1 :
                            (!Rrange.Empty) ? +1 :
                            0;

                        // Determine the number of lines to scan, based on direction
                        if (dir < 0)
                        {
                            scan_backward = true;
                            scan_range    = Lrange;
                            bwd_lines    -= Math_.Clamp(d.filepos_line_index - 0, 0, bwd_lines);
                            fwd_lines     = 0;
                        }
                        else if (dir > 0)
                        {
                            scan_backward = false;
                            scan_range    = Rrange;
                            bwd_lines     = 0;
                            fwd_lines    -= Math_.Clamp(d.line_index_count - d.filepos_line_index - 1, 0, fwd_lines);
                        }
                        else if (dir == 0)
                        {
                            bwd_lines  = 0;
                            fwd_lines  = 0;
                            scan_range = RangeI.Zero;
                        }
                    }
                    #endregion

                    Debug.Assert(bwd_lines + fwd_lines <= d.line_cache_count);

                    // Build the collection of line byte ranges to add to the cache
                    var line_index = new List <RangeI>();
                    if (bwd_lines != 0 || fwd_lines != 0)
                    {
                        // Line index buffers for collecting the results
                        var fwd_line_buf = new List <RangeI>();
                        var bwd_line_buf = new List <RangeI>();

                        // Data used in the 'add_line' callback. Updated for forward and backward passes
                        var lbd = new LineBufferData
                        {
                            line_buf   = null,                           // pointer to either 'fwd_line_buf' or 'bwd_line_buf'
                            line_limit = 0,                              // Caps the number of lines read for each of the forward and backward searches
                        };

                        // Callback for adding line byte ranges to a line buffer
                        AddLineFunc add_line = (line, baddr, fend, bf, enc) =>
                        {
                            if (line.Empty && d.ignore_blanks)
                            {
                                return(true);
                            }

                            // Test 'text' against each filter to see if it's included
                            // Note: not caching this string because we want to read immediate data
                            // from the file to pick up file changes.
                            string text = d.encoding.GetString(buf, (int)line.Beg, (int)line.Size);
                            if (!PassesFilters(text, d.filters))
                            {
                                return(true);
                            }

                            // Convert the byte range to a file range
                            line = line.Shift(baddr);
                            Debug.Assert(new RangeI(0, d.fileend).Contains(line));
                            lbd.line_buf.Add(line);
                            Debug.Assert(lbd.line_buf.Count <= lbd.line_limit);
                            return((fwd_line_buf.Count + bwd_line_buf.Count) < lbd.line_limit);
                        };

                        // Callback for updating progress
                        ProgressFunc progress = (scanned, length) =>
                        {
                            int numer = fwd_line_buf.Count + bwd_line_buf.Count, denom = lbd.line_limit;
                            return(d.progress(numer, denom) && !BuildCancelled(d.build_issue));
                        };

                        // Scan twice, starting in the direction of the smallest range so that any
                        // unused cache space is used by the search in the other direction
                        var scan_from = Math_.Clamp(d.filepos, scan_range.Beg, scan_range.End);
                        for (int a = 0; a != 2; ++a, scan_backward = !scan_backward)
                        {
                            if (BuildCancelled(d.build_issue))
                            {
                                return;
                            }

                            lbd.line_buf    = scan_backward ? bwd_line_buf : fwd_line_buf;
                            lbd.line_limit += scan_backward ? bwd_lines : fwd_lines;
                            if ((bwd_line_buf.Count + fwd_line_buf.Count) < lbd.line_limit)
                            {
                                var length = scan_backward ? scan_from - scan_range.Beg : scan_range.End - scan_from;
                                FindLines(d.file, scan_from, d.fileend, scan_backward, length, add_line, d.encoding, d.row_delim, buf, progress);
                            }
                        }

                        // Scanning backward adds lines to the line index in reverse order.
                        bwd_line_buf.Reverse();

                        // 'line_index' should be a contiguous block of byte offset ranges for
                        // the lines around 'd.filepos'. If 'd.reload' is false, then the line
                        // index will only contain byte offset ranges that are not currently cached.
                        line_index.Capacity = bwd_line_buf.Count + fwd_line_buf.Count;
                        line_index.AddRange(bwd_line_buf);
                        line_index.AddRange(fwd_line_buf);
                    }

                    // Job done
                    on_complete(d, scan_range, line_index, null);
                }
            }
            catch (Exception ex)
            {
                on_complete(d, RangeI.Zero, null, ex);
            }
        }
Beispiel #26
0
        private void btn_ok_Click(object sender, EventArgs e)
        {
            #region 输入与输出路径条件判断
            if (this.txt_ImageInput.Text.Equals(""))
            {
                MessageBox.Show("请选择输入影像文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            string sX = this.txt_X.Text;
            if (sX.Equals(""))
            {
                MessageBox.Show("请输入X方向采样比!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            double NX = 1.0;
            bool BX = double.TryParse(sX, out NX);

            if (!BX)
            {
                MessageBox.Show("请输入数字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            string sY = this.txt_Y.Text;
            if (sY.Equals(""))
            {
                MessageBox.Show("请输入Y方向采样比!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            double NY = 1.0;
            bool BY = double.TryParse(sY, out NY);

            if (!BY)
            {
                MessageBox.Show("请输入数字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (this.txt_ImageOutPath.Text.Equals(""))
            {
                MessageBox.Show("请选择输出路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            #endregion
            this.btn_ok.Enabled = false;
            #region 界面参数获取
            string strInFile = txt_ImageInput.Text.Trim();
            //string strField = this.cbx_FormatType.SelectedValue.ToString();
            string strX = this.txt_X.Text.Trim();
            string strY = this.txt_Y.Text.Trim();
            string strOutFile = this.txt_ImageOutPath.Text.Trim();
            //string sFileName = FileManage.getFileName(strVectorFile);
            string sFileName = Path.GetFileNameWithoutExtension(strInFile);
            strOutFile = strOutFile + "\\" + sFileName +"_"+ strX +"_"+ strY+ ".tif";

            #endregion

            #region 调用转换算法
            //声明进度信息回调函数
            ProgressFunc pd = new ProgressFunc(this.ProgressBarInfo);
            IntPtr p = this.Handle;
            int ire = 0;
            this.progressBar.Visible = true;
            try
            {
                char[] strInFileList = strInFile.ToCharArray();

                char[] strOutFileList = strOutFile.ToCharArray();

                double DX = double.Parse(strX);
                double DY = double.Parse(strY);
                ire = GdalAlgInterface.ImageResample(strInFileList, strOutFileList, DX, DY, 0, "GTiff", pd, p);

                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
        }
        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_ImageOutPath.Text.Equals(""))
            {
                MessageBox.Show("请选择输出路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            string sImageOutPath = this.txt_ImageOutPath.Text.Trim();
            #endregion
            this.btn_ok.Enabled = false;

            #region 界面参数获取



            #endregion

            #region 执行合成
            this.progressBar.Visible = true;
            try
            {
                foreach (ListViewItem item in this.listViewImage.Items)
                {
                    string sFile      = item.SubItems[0].Text.Trim();
                    string strFormula = "(b4-b3)/(b4+b3)*1.0"; //默认为NDVI计算公式
                    string sFiles     = sFile + "*" + sFile;   //默认为NDVI计算输入数据个数,只用到2个波段,所以输入2遍,中间用*隔开
                    //默认为NDVI计算输入波段数组
                    int[] nBand = new int[2];
                    nBand[0] = 3;
                    nBand[1] = 4;
                    string sOutFileName = sImageOutPath + "\\" + Path.GetFileNameWithoutExtension(sFile);
                    sOutFileName = sOutFileName.Replace("\\\\", "\\");
                    switch (this.cbx_VIType.Text.Trim())
                    {
                    case "NDVI":
                        //sFiles = sFile + "*" + sFile;
                        //strFormula = "(b4-b3)/(b4+b3)*1.0";
                        //nBand = new int[2];
                        //nBand[0] = 3;
                        //nBand[1] = 4;
                        sOutFileName = sOutFileName + "_NDVI.tif";
                        break;

                    case "EVI":
                        sFiles       = sFile + "*" + sFile + "*" + sFile;
                        strFormula   = "2.5*(b4-b3)/(b4+6*b3-7.5*b1+1)";
                        nBand        = new int[3];
                        nBand[0]     = 1;
                        nBand[1]     = 3;
                        nBand[2]     = 4;
                        sOutFileName = sOutFileName + "_EVI.tif";
                        break;

                    case "Band1":
                        sFiles       = sFile;
                        strFormula   = "b1*1.0";
                        nBand        = new int[1];
                        nBand[0]     = 1;
                        sOutFileName = sOutFileName + "_Band1.tif";
                        break;

                    case "Band2":
                        sFiles       = sFile;
                        strFormula   = "b2*1.0";
                        nBand        = new int[1];
                        nBand[0]     = 2;
                        sOutFileName = sOutFileName + "_Band2.tif";
                        break;

                    case "Band3":
                        sFiles       = sFile;
                        strFormula   = "b3*1.0";
                        nBand        = new int[1];
                        nBand[0]     = 3;
                        sOutFileName = sOutFileName + "_Band3.tif";
                        break;

                    case "Band4":
                        sFiles       = sFile;
                        strFormula   = "b4*1.0";
                        nBand        = new int[1];
                        nBand[0]     = 4;
                        sOutFileName = sOutFileName + "_Band4.tif";
                        break;
                    }


                    ProgressFunc pd             = new ProgressFunc(this.ProgressBarInfo);
                    IntPtr       pre            = this.Handle;
                    int          ire            = 0;
                    char[]       strInFileList  = sFiles.ToCharArray();
                    char[]       strOutFileList = sOutFileName.ToCharArray();

                    ire = GdalAlgInterface.ImageCalculate(strInFileList, strOutFileList, strFormula, nBand, "GTiff", pd, pre);
                    //Console.Write(ire.ToString());
                }
            }
            catch (Exception ex)
            {
                this.progressBar.Visible = false;
                MessageBox.Show(ex.Message);
                return;
            }
            finally
            {
                MessageBox.Show("指数计算完毕", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.btn_ok.Enabled = true;
                //this.btn_OpenOutPut.Visible = true;
                this.progressBar.Visible = false;
            }

            #endregion
        }
        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();

            #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];
                ire = GdalAlgInterface.ImageStatisticalByVector(strInFileList, strRegionFileList, strFieldList, 2, pRegionCodeList, padfResultList, padfResultList.Length, pd, pre);
                //第三步
                //运行成功或失败,停止线程,即终止进度条。
                //t.Abort();
                string[,] arrStatistic = new string[nCount, 6];
                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");
                }
                //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
        }
Beispiel #29
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);
            #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 = System.Windows.Forms.Application.StartupPath + "\\BaseData\\hongxing_plot.shp";
                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];
                ire = GdalAlgInterface.ImageStatisticalByVector(strInFileList, strRegionFileList, strFieldList, 2, pRegionCodeList, padfResultList, padfResultList.Length, pd, pre);
                //第三步
                //运行成功或失败,停止线程,即终止进度条。
                //t.Abort();
                string[,] arrStatistic = new string[nCount, 6];
                for (int i = 0; i < nCount; i++)
                {
                    string sRASTERID = pRegionCodeList[i].ToString();
                    //获得后,到PLOT_DKINFO中找到用sRASTERID找到对应PlotID
                    //string sPlotID = sRASTERID;///此处为测试
                    ///到PLOT_DKINFO中找到用sRASTERID找到对应GLQ,再用GLQ到TOWN表里找到对应的[TownName]进行显示到这里(PLOT_DKINFO.GLQ=TOWN.TowCode);
                    //string sGLQName = "作业区_TOWN.TownName";
                    ///到PLOT_DKINFO中找到用sRASTERID找到对应JMZ,再用GLQ到VILLAGE表里找到对应的VillName进行显示到这里(PLOT_DKINFO.JMZ=VILLAGE.[VillCode]);
                    ///string sJMZName = "作业站_VILLAGE.VillName";
                    ///到PLOT_DKINFO中找到用sRASTERID找到对应FULLNAME,显示到这里;
                    //string sPlotName = "地块名称_[PLOT_DKINFO].[FULLNAME]";

                    arrStatistic[i, 0] = res[2];//文件名中的时间,从文件名中解析,此处获取的系统时间只为测试
                    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; "区域代码"

                    if (res[0].Contains("RETRIEVAL"))
                    {
                        //int result = (int)(padfResultList[i]*100);
                        arrStatistic[i, 5] =Math.Round(padfResultList[i]).ToString();
                    }
                    else
                    {
                        arrStatistic[i, 5] = padfResultList[i].ToString("0.00");
                    }
                }

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

            }
            #endregion
        }
Beispiel #30
0
        public static ClipperLib.PolyTree ExecuteClipper(TmxMap tmxMap, TmxLayer tmxLayer, TransformPointFunc xfFunc, ProgressFunc progFunc)
        {
            // The "fullClipper" combines the clipper results from the smaller pieces
            ClipperLib.Clipper fullClipper = new ClipperLib.Clipper();

            // From the perspective of Clipper lines are polygons too
            // Closed paths == polygons
            // Open paths == lines
            var polygonGroups = from y in Enumerable.Range(0, tmxLayer.Height)
                                from x in Enumerable.Range(0, tmxLayer.Width)
                                let rawTileId = tmxLayer.GetRawTileIdAt(x, y)
                                                let tileId = TmxMath.GetTileIdWithoutFlags(rawTileId)
                                                             where tileId != 0
                                                             let tile = tmxMap.Tiles[tileId]
                                                                        from polygon in tile.ObjectGroup.Objects
                                                                        where (polygon as TmxHasPoints) != null
                                                                        let groupX = x / LayerClipper.GroupBySize
                                                                                     let groupY = y / LayerClipper.GroupBySize
                                                                                                  group new
            {
                PositionOnMap         = tmxMap.GetMapPositionAt(x, y, tile),
                HasPointsInterface    = polygon as TmxHasPoints,
                TmxObjectInterface    = polygon,
                IsFlippedDiagnoally   = TmxMath.IsTileFlippedDiagonally(rawTileId),
                IsFlippedHorizontally = TmxMath.IsTileFlippedHorizontally(rawTileId),
                IsFlippedVertically   = TmxMath.IsTileFlippedVertically(rawTileId),
                TileCenter            = new PointF(tile.TileSize.Width * 0.5f, tile.TileSize.Height * 0.5f),
            }
            by Tuple.Create(groupX, groupY);

            int groupIndex = 0;
            int groupCount = polygonGroups.Count();

            foreach (var polyGroup in polygonGroups)
            {
                if (groupIndex % 5 == 0)
                {
                    progFunc(String.Format("Clipping '{0}' polygons: {1}%", tmxLayer.Name, (groupIndex / (float)groupCount) * 100));
                }
                groupIndex++;

                // The "groupClipper" clips the polygons in a smaller part of the world
                ClipperLib.Clipper groupClipper = new ClipperLib.Clipper();

                // Add all our polygons to the Clipper library so it can reduce all the polygons to a (hopefully small) number of paths
                foreach (var poly in polyGroup)
                {
                    // Create a clipper library polygon out of each and add it to our collection
                    ClipperPolygon clipperPolygon = new ClipperPolygon();

                    // Our points may be transformed due to tile flipping/rotation
                    // Before we transform them we put all the points into local space relative to the tile
                    SizeF    offset            = new SizeF(poly.TmxObjectInterface.Position);
                    PointF[] transformedPoints = poly.HasPointsInterface.Points.Select(pt => PointF.Add(pt, offset)).ToArray();

                    // Now transform the points relative to the tile
                    TmxMath.TransformPoints(transformedPoints, poly.TileCenter, poly.IsFlippedDiagnoally, poly.IsFlippedHorizontally, poly.IsFlippedVertically);

                    foreach (var pt in transformedPoints)
                    {
                        float x = poly.PositionOnMap.X + pt.X;
                        float y = poly.PositionOnMap.Y + pt.Y;

                        ClipperLib.IntPoint point = xfFunc(x, y);
                        clipperPolygon.Add(point);
                    }

                    // Because of Unity's cooridnate system, the winding order of the polygons must be reversed
                    clipperPolygon.Reverse();

                    // Add the "subject"
                    groupClipper.AddPath(clipperPolygon, ClipperLib.PolyType.ptSubject, poly.HasPointsInterface.ArePointsClosed());
                }

                // Get a solution for this group
                ClipperLib.PolyTree solution = new ClipperLib.PolyTree();
                groupClipper.Execute(ClipperLib.ClipType.ctUnion, solution, LayerClipper.SubjectFillRule, LayerClipper.ClipFillRule);

                // Combine the solutions into the full clipper
                fullClipper.AddPaths(ClipperLib.Clipper.ClosedPathsFromPolyTree(solution), ClipperLib.PolyType.ptSubject, true);
                fullClipper.AddPaths(ClipperLib.Clipper.OpenPathsFromPolyTree(solution), ClipperLib.PolyType.ptSubject, false);
            }
            progFunc(String.Format("Clipping '{0}' polygons: 100%", tmxLayer.Name));

            ClipperLib.PolyTree fullSolution = new ClipperLib.PolyTree();
            fullClipper.Execute(ClipperLib.ClipType.ctUnion, fullSolution, LayerClipper.SubjectFillRule, LayerClipper.ClipFillRule);

            return(fullSolution);
        }
        private void btn_ok_Click(object sender, EventArgs e)
        {
            #region 输入与输出路径条件判断
            if (this.txt_ImageInput.Text.Equals(""))
            {
                MessageBox.Show("请选择输入影像文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            string sX = this.txt_X.Text;
            if (sX.Equals(""))
            {
                MessageBox.Show("请输入X方向采样比!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            double NX = 1.0;
            bool   BX = double.TryParse(sX, out NX);

            if (!BX)
            {
                MessageBox.Show("请输入数字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            string sY = this.txt_Y.Text;
            if (sY.Equals(""))
            {
                MessageBox.Show("请输入Y方向采样比!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            double NY = 1.0;
            bool   BY = double.TryParse(sY, out NY);

            if (!BY)
            {
                MessageBox.Show("请输入数字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (this.txt_ImageOutPath.Text.Equals(""))
            {
                MessageBox.Show("请选择输出路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            #endregion
            this.btn_ok.Enabled = false;
            #region 界面参数获取
            string strInFile = txt_ImageInput.Text.Trim();
            //string strField = this.cbx_FormatType.SelectedValue.ToString();
            string strX       = this.txt_X.Text.Trim();
            string strY       = this.txt_Y.Text.Trim();
            string strOutFile = this.txt_ImageOutPath.Text.Trim();
            //string sFileName = FileManage.getFileName(strVectorFile);
            string sFileName = Path.GetFileNameWithoutExtension(strInFile);
            strOutFile = strOutFile + "\\" + sFileName + "_" + strX + "_" + strY + ".tif";


            #endregion

            #region 调用转换算法
            //声明进度信息回调函数
            ProgressFunc pd  = new ProgressFunc(this.ProgressBarInfo);
            IntPtr       p   = this.Handle;
            int          ire = 0;
            this.progressBar.Visible = true;
            try
            {
                char[] strInFileList = strInFile.ToCharArray();

                char[] strOutFileList = strOutFile.ToCharArray();

                double DX = double.Parse(strX);
                double DY = double.Parse(strY);
                ire = GdalAlgInterface.ImageResample(strInFileList, strOutFileList, DX, DY, 0, "GTiff", pd, p);

                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
        }
        private void btn_ok_Click(object sender, EventArgs e)
        {
            #region 输入与输出路径条件判断
            if (this.txt_ImageInput.Text.Equals(""))
            {
                MessageBox.Show("请选择输入矢量文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            //if (this.cbx_FormatType.SelectedValue.ToString().Equals("请选择"))
            if (this.cbx_FormatType.Text.Equals(""))
            {
                MessageBox.Show("请选择转换字段!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            string sResolution = this.txt_resolution.Text;
            if (sResolution.Equals(""))
            {
                MessageBox.Show("请输入分辨率数值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            int  NResolution = 30;
            bool BResolution = int.TryParse(sResolution, out NResolution);

            if (!BResolution)
            {
                MessageBox.Show("请输入数字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (this.txt_ImageOutPath.Text.Equals(""))
            {
                MessageBox.Show("请选择输出路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            #endregion
            this.btn_ok.Enabled = false;
            #region 界面参数获取
            string strVectorFile = txt_ImageInput.Text.Trim();
            //string strField = this.cbx_FormatType.SelectedValue.ToString();
            string strField      = this.cbx_FormatType.Text.Trim();
            string strRasterFile = this.txt_ImageOutPath.Text.Trim();
            //string sFileName = FileManage.getFileName(strVectorFile);
            string sFileName = Path.GetFileNameWithoutExtension(strVectorFile);
            strRasterFile = strRasterFile + "\\" + sFileName + ".tif";


            #endregion

            #region 调用转换算法
            //声明进度信息回调函数
            ProgressFunc pd  = new ProgressFunc(this.ProgressBarInfo);
            IntPtr       p   = this.Handle;
            int          ire = 0;
            this.progressBar.Visible = true;
            try
            {
                char[] strVectorFileList = strVectorFile.ToCharArray();

                char[] strRasterFileList = strRasterFile.ToCharArray();

                char[] strFieldList = strField.ToCharArray();

                ire = GdalAlgInterface.ShpRasterize(strVectorFileList, strRasterFileList, NResolution, 2, 0, strFieldList, "GTiff", pd, p);

                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
        }
        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_ImageOutPath.Text.Equals(""))
            {
                MessageBox.Show("请选择输出路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            #endregion
            this.btn_ok.Enabled = false;

            #region 界面参数获取
            string sFiles = "";
            foreach (ListViewItem item in this.listViewImage.Items)
            {
                string sFile = item.SubItems[0].Text.Trim();
                sFiles += sFile + "*";
            }
            sFiles = sFiles.Substring(0, sFiles.Length-1);
            string sImageOutPath = this.txt_ImageOutPath.Text.Trim();
            #endregion

            #region 执行合成
            this.progressBar.Visible = true;
            try
            {
                ProgressFunc pd = new ProgressFunc(this.ProgressBarInfo);
                IntPtr pre = this.Handle;
                int ire = 0;
                char[] strInFileList = sFiles.ToCharArray();
                char[] strOutFileList = sImageOutPath.ToCharArray();
                ire = GdalAlgInterface.ImageLayerStack(strInFileList, strOutFileList, 0, false, "GTiff", 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

        }
Beispiel #34
0
        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_ImageOutPath.Text.Equals(""))
            {
                MessageBox.Show("请选择输出路径!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            string sImageOutPath = this.txt_ImageOutPath.Text.Trim();
            #endregion
            this.btn_ok.Enabled = false;

            #region 界面参数获取



            #endregion

            #region 执行合成
            this.progressBar.Visible = true;
            try
            {
                foreach (ListViewItem item in this.listViewImage.Items)
                {
                    string sFile = item.SubItems[0].Text.Trim();

                    if (!sFile.Contains("WFV") && !sFile.Contains("PMS") && !sFile.Contains("wfv") && !sFile.Contains("pms"))
                    {
                        MessageBox.Show("请输入包含传感器名称WFV或者PMS的影像!");
                        return;
                    }

                    string sFileName = Path.GetFileNameWithoutExtension(sFile);

                    string sSensorType = sFileName.Substring(4, 4);
                    sSensorType = sSensorType.ToUpper();
                    string[] BandCoefficients = new string[4];
                    switch (sSensorType)
                    {
                    case "PMS1":
                        BandCoefficients[0] = "*0.2082+4.6186";    //第一波段定标系数
                        BandCoefficients[1] = "*0.1672+4.8768";    //第二波段定标系数
                        BandCoefficients[2] = "*0.1748+4.8924";    //第三波段定标系数
                        BandCoefficients[3] = "*0.1883-9.4771";    //第四波段定标系数
                        break;

                    case "PMS2":
                        BandCoefficients[0] = "*0.2072+7.5348";   //第一波段定标系数
                        BandCoefficients[1] = "*0.1776+3.9395";   //第二波段定标系数
                        BandCoefficients[2] = "*0.177-1.7445";    //第三波段定标系数
                        BandCoefficients[3] = "*0.1909-7.2053";   //第四波段定标系数
                        break;

                    case "WFV1":
                        BandCoefficients[0] = "*0.1709-0.0039";    //第一波段定标系数
                        BandCoefficients[1] = "*0.1398-0.0047";    //第二波段定标系数
                        BandCoefficients[2] = "*0.1195-0.0030";    //第三波段定标系数
                        BandCoefficients[3] = "*0.1338-0.0274";    //第四波段定标系数
                        break;

                    case "WFV2":
                        BandCoefficients[0] = "*0.1588+5.5303";   //第一波段定标系数
                        BandCoefficients[1] = "*0.1515-13.642";   //第二波段定标系数
                        BandCoefficients[2] = "*0.1251-15.382";   //第三波段定标系数
                        BandCoefficients[3] = "*0.1209-7.985";    //第四波段定标系数
                        break;

                    case "WFV3":
                        BandCoefficients[0] = "*0.1556+12.28";    //第一波段定标系数
                        BandCoefficients[1] = "*0.1700-7.9336";   //第二波段定标系数
                        BandCoefficients[2] = "*0.1392-7.031";    //第三波段定标系数
                        BandCoefficients[3] = "*0.1354-4.3578";   //第四波段定标系数
                        break;

                    case "WFV4":
                        BandCoefficients[0] = "*0.1819+3.6469";   //第一波段定标系数
                        BandCoefficients[1] = "*0.1762-13.54";    //第二波段定标系数
                        BandCoefficients[2] = "*0.1463-10.998";   //第三波段定标系数
                        BandCoefficients[3] = "*0.1522-12.142";   //第四波段定标系数
                        break;
                    }
                    //默认为NDVI计算输入波段数组
                    int[]  nBand        = new int[1];
                    string sOutFilePath = sImageOutPath + "\\" + sFileName;
                    sOutFilePath = sOutFilePath.Replace("\\\\", "\\");

                    //波段组合文件名组合参数
                    string        sLayerStackName = "";
                    List <string> filelist        = new List <string>();

                    for (int i = 1; i <= 4; i++)
                    {
                        string strFormula = "b" + i + "*1" + BandCoefficients[i - 1];//默认为NDVI计算公式
                        nBand[0] = i;

                        string sOutFileName = sOutFilePath + "_Band" + i + ".tif";
                        //组装波段组合的输入参数名,所有文件名组成一个字符串,中间用*连接
                        sLayerStackName += sOutFileName + "*";
                        filelist.Add(Path.GetFileName(sOutFileName));
                        ProgressFunc pd             = new ProgressFunc(this.ProgressBarInfo);
                        IntPtr       pre            = this.Handle;
                        int          ire            = 0;
                        char[]       strInFileList  = sFile.ToCharArray();
                        char[]       strOutFileList = sOutFileName.ToCharArray();

                        ire = GdalAlgInterface.ImageCalculate(strInFileList, strOutFileList, strFormula, nBand, "GTiff", pd, pre);
                        //Console.Write(ire.ToString());
                    }

                    //波段叠加输入波段影像
                    sLayerStackName = sLayerStackName.Substring(0, sLayerStackName.Length - 1);
                    //波段组合后输出影像文件名
                    string sLayerStackResult = sImageOutPath + "\\" + sFileName + "_radiocorrect.tif";



                    ProgressFunc pd2  = new ProgressFunc(this.ProgressBarInfo);
                    IntPtr       pre2 = this.Handle;
                    int          ire2 = 0;
                    char[]       strLayerInFileList  = sLayerStackName.ToCharArray();
                    char[]       strLayerOutFileList = sLayerStackResult.ToCharArray();
                    ire2 = GdalAlgInterface.ImageLayerStack(strLayerInFileList, strLayerOutFileList, 0, false, "GTiff", pd2, pre2);
                    //MessageBox.Show("波段合成完毕", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.btn_ok.Enabled = true;
                    //this.btn_OpenOutPut.Visible = true;
                    //this.progressBar.Visible = false;
                    FileManage pFileManage = new FileManage();
                    pFileManage.DeteleFiles(filelist, sImageOutPath + "\\");
                }
            }
            catch (Exception ex)
            {
                this.progressBar.Visible = false;
                MessageBox.Show(ex.Message);
                return;
            }
            finally
            {
                MessageBox.Show("波段提取并辐射定标完毕", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.btn_ok.Enabled = true;
                //this.btn_OpenOutPut.Visible = true;
                this.progressBar.Visible = false;
            }

            #endregion
        }
Beispiel #35
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);
            #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     = System.Windows.Forms.Application.StartupPath + "\\BaseData\\hongxing_plot.shp";
                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];
                ire = GdalAlgInterface.ImageStatisticalByVector(strInFileList, strRegionFileList, strFieldList, 2, pRegionCodeList, padfResultList, padfResultList.Length, pd, pre);
                //第三步
                //运行成功或失败,停止线程,即终止进度条。
                //t.Abort();
                string[,] arrStatistic = new string[nCount, 6];
                for (int i = 0; i < nCount; i++)
                {
                    string sRASTERID = pRegionCodeList[i].ToString();
                    //获得后,到PLOT_DKINFO中找到用sRASTERID找到对应PlotID
                    //string sPlotID = sRASTERID;///此处为测试
                    ///到PLOT_DKINFO中找到用sRASTERID找到对应GLQ,再用GLQ到TOWN表里找到对应的[TownName]进行显示到这里(PLOT_DKINFO.GLQ=TOWN.TowCode);
                    //string sGLQName = "作业区_TOWN.TownName";
                    ///到PLOT_DKINFO中找到用sRASTERID找到对应JMZ,再用GLQ到VILLAGE表里找到对应的VillName进行显示到这里(PLOT_DKINFO.JMZ=VILLAGE.[VillCode]);
                    ///string sJMZName = "作业站_VILLAGE.VillName";
                    ///到PLOT_DKINFO中找到用sRASTERID找到对应FULLNAME,显示到这里;
                    //string sPlotName = "地块名称_[PLOT_DKINFO].[FULLNAME]";

                    arrStatistic[i, 0] = res[2];//文件名中的时间,从文件名中解析,此处获取的系统时间只为测试
                    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; "区域代码"

                    if (res[0].Contains("RETRIEVAL"))
                    {
                        //int result = (int)(padfResultList[i]*100);
                        arrStatistic[i, 5] = Math.Round(padfResultList[i]).ToString();
                    }
                    else
                    {
                        arrStatistic[i, 5] = padfResultList[i].ToString("0.00");
                    }
                }

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