Ejemplo n.º 1
0
 /// <summary>
 /// visit band
 /// </summary>
 /// <param name="pBand"></param>
 public void Visit(GRasterBand pBand)
 {
     _width      = pBand.Width;
     _height     = pBand.Height;
     _normalData = pBand.NormalData;
     _rawData    = pBand.RawData;
 }
Ejemplo n.º 2
0
 public Bitmap2(Bitmap bmp = null, string name = "", string dec = "", GLayer.GRasterLayer.GRasterLayer gdalLayer = null, GRasterBand gdalBand = null)
 {
     _bitmap    = bmp;
     _name      = name;
     _dec       = dec;
     _gdalBand  = gdalBand;
     _gdalLayer = gdalLayer;
 }
Ejemplo n.º 3
0
        public double[] PickRawValue(int x, int y)
        {
            IRasterBandCursorTool pBandCursorTool = new GRasterBandCursorTool();

            double[] normalValueArray = new double[_pLayer.BandCollection.Count];
            for (int i = 0; i < _pLayer.BandCollection.Count; i++)
            {
                GRasterBand pBand = _pLayer.BandCollection[i];
                pBandCursorTool.Visit(pBand);
                normalValueArray[i] = pBandCursorTool.PickRawValue(x, y);
            }
            return(normalValueArray);
        }
Ejemplo n.º 4
0
        public void Output(string outputDir)
        {
            Dataset readDs = _rasterLayer.PDataSet;
            Driver  drv    = Gdal.GetDriverByName("GTiff");

            string[] options = new string[] { "BLOCKXSIZE=" + readDs.RasterXSize, "BLOCKYSIZE=" + readDs.RasterYSize };
            Dataset  writeDs = drv.Create(outputDir, readDs.RasterXSize, readDs.RasterYSize, 1, _rasterLayer.PDataType, options);

            for (int i = 1; i <= _rasterLayer.BandCount; i++)
            {
                GRasterBand readBand  = _rasterLayer.BandCollection[i - 1];
                Band        writeBand = writeDs.GetRasterBand(i);
                writeBand.WriteRaster(0, 0, readDs.RasterXSize, readDs.RasterYSize, readBand.GetRawBuffer(), readDs.RasterXSize, readDs.RasterYSize, 0, 0);
            }
            writeDs.FlushCache();
        }
Ejemplo n.º 5
0
        public double[] PickRagneNormalValue(int x, int y, int row = 5, int col = 5)
        {
            IRasterBandCursorTool pBandCursorTool = new GRasterBandCursorTool();

            double[] rangeNormalValueArray = new double[row * col * _pLayer.BandCollection.Count];
            int      offset = 0;

            for (int i = 0; i < _pLayer.BandCollection.Count; i++)
            {
                GRasterBand pBand = _pLayer.BandCollection[i];
                pBandCursorTool.Visit(pBand);
                double[] singleBandRangeNormalValue = pBandCursorTool.PickRangeNormalValue(x, y, row, col);
                Array.ConstrainedCopy(singleBandRangeNormalValue, 0, rangeNormalValueArray, offset, row * col);
                offset += row * col;
            }
            return(rangeNormalValueArray);
        }
Ejemplo n.º 6
0
        private void UpdateBands()
        {
            _bandIndexSave = new List <int>();
            ImageList imageList = new ImageList();

            for (int i = 0; i < _gdalLayer.BandCollection.Count; i++)
            {
                GRasterBand  band = _gdalLayer.BandCollection[i];
                ListViewItem lvi  = new ListViewItem
                {
                    ImageIndex = i
                };
                lvi.SubItems.Add(band.BandName);
                lvi.SubItems.Add(band.Width + "x" + band.Height);
                band_listView.Items.Add(lvi);
                imageList.Images.Add(band.GrayscaleImage);
            }
            band_listView.SmallImageList = imageList;
            band_listView.LargeImageList = imageList;
        }
Ejemplo n.º 7
0
 public JobCOVRaster(GRasterBand target1band, GRasterBand target2band)
 {
     _t = new Thread(() => {
         IRasterBandCursorTool pRasterBandCursorTool1 = new GRasterBandCursorTool();
         IRasterBandCursorTool pRasterBandCursorTool2 = new GRasterBandCursorTool();
         pRasterBandCursorTool1.Visit(target1band);
         pRasterBandCursorTool2.Visit(target2band);
         //
         int seed        = 0;
         int totalPixels = target1band.Width * target1band.Height;
         Bitmap bitmap   = new Bitmap(target1band.Width, target1band.Height);
         Graphics g      = Graphics.FromImage(bitmap);
         //
         for (int i = 0; i < target1band.Width; i++)
         {
             for (int j = 0; j < target1band.Height; j++)
             {
                 double[] raw1 = pRasterBandCursorTool1.PickRangeRawValue(i, j, 3, 3);
                 double[] raw2 = pRasterBandCursorTool2.PickRangeRawValue(i, j, 3, 3);
                 double cov    = ConvarianceIndex.CalcuteConvarianceIndex(raw1, raw2);
                 //拉伸-1 - 1
                 int gray         = Convert.ToInt32((cov + 1.0) * 20);
                 Color c          = Color.FromArgb(gray, gray, gray);
                 Pen p            = new Pen(c);
                 SolidBrush brush = new SolidBrush(c);
                 g.FillRectangle(brush, new Rectangle(i, j, 1, 1));
                 Process = (double)(seed++) / totalPixels;
             }
         }
         //save result
         string fullFileName = Directory.GetCurrentDirectory() + @"\tmp\" + DateTime.Now.ToFileTimeUtc() + ".png";
         bitmap.Save(fullFileName);
         //
         Summary  = "计算完成";
         Complete = true;
         OnTaskComplete?.Invoke(Name, fullFileName);
     });
 }
Ejemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="fullFilename"></param>
 public JobReadRaster(string fullFilename)
 {
     _t = new Thread(() =>
     {
         Dictionary <string, Bitmap2> dict = new Dictionary <string, Bitmap2>();
         string name = Path.GetFileNameWithoutExtension(fullFilename);
         GRasterLayer rasterLayer = new GRasterLayer(fullFilename);
         //reading
         Summary = "数据读取中";
         for (int i = 0; i < rasterLayer.BandCount; i++)
         {
             GRasterBand band    = rasterLayer.BandCollection[i];
             band.BandName       = name + "_band_" + i;
             Bitmap2 bmp2        = new Bitmap2(bmp: band.GrayscaleImage, name: band.BandName, gdalBand: band, gdalLayer: rasterLayer);
             dict[band.BandName] = bmp2;
             Process             = (double)(i + 1) / rasterLayer.BandCount;
         }
         //read complete
         Summary  = "读取完毕";
         Complete = true;
         OnTaskComplete?.Invoke(Name, name, dict, rasterLayer);
     });
 }
Ejemplo n.º 9
0
 public void Dispose()
 {
     _pBand = null;
 }
Ejemplo n.º 10
0
        /// <summary>
        /// 底图区域功能按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Map_function_Click(object sender, EventArgs e)
        {
            ToolStripItem item = sender as ToolStripItem;

            switch (item.Name)
            {
            //rpc transform
            case "RPC_ToolStripMenuItem":
                RPCForm rpcForm = new RPCForm();
                if (rpcForm.ShowDialog() == DialogResult.OK)
                {
                    IJob rpcRectifyJob = new IJobRPCRectify(rpcForm.A, rpcForm.B, rpcForm.C, rpcForm.D, rpcForm.RPCParamaters, rpcForm.RawBinRasterFullFilenames);
                    RegisterJob(rpcRectifyJob);
                    rpcRectifyJob.Start();
                }
                break;

            //cov matrix
            case "cov_toolStripButton":
                COVForm covForm = new COVForm();
                covForm.RasterDic = _rasterDic;
                if (covForm.ShowDialog() == DialogResult.OK)
                {
                    GRasterBand band1        = _rasterDic[covForm.Target1Key].BandCollection[0];
                    GRasterBand band2        = _rasterDic[covForm.Target2Key].BandCollection[0];
                    IJob        covRasterJob = new JobCOVRaster(band1, band2);
                    RegisterJob(covRasterJob);
                    covRasterJob.Start();
                }
                break;

            //task
            case "task_toolStripButton":
                TaskMonitor taskForm = new TaskMonitor();
                taskForm.Jobs = _jobs;
                taskForm.ShowDialog();
                break;

            //calucte kappa
            case "kappa_toolStripButton":
                KappaForm kappaForm = new KappaForm();
                kappaForm.RasterDic = _rasterDic;
                kappaForm.ShowDialog();
                break;

            //添加图像
            case "open_toolstripmenuitem":
            case "open_contextMenuStrip":
                ReadImage();
                break;

            //超像素分割
            case "SLIC_toolStripButton":
            case "SLIC_toolStripMenu":
                Bitmap bmp = map_pictureBox.Image as Bitmap;
                if (bmp != null)
                {
                    ThreadStart slic_ts = delegate { RunSLIC(bmp); };
                    Thread      slic_t  = new Thread(slic_ts);
                    slic_t.IsBackground = true;
                    slic_t.Start();
                }
                else
                {
                    UpdateStatusLabel("未选中待计算图像,地图区域无图片", STATUE_ENUM.ERROR);
                }
                break;

            //super pixel
            case "SLIC_Center_toolStripButton":
            case "SLIC_Center_toolStripMenu":
                OpenFileDialog opg = new OpenFileDialog
                {
                    Filter = "JSON文件|*.json"
                };
                if (opg.ShowDialog() == DialogResult.OK)
                {
                    //1.读取center中心
                    using (StreamReader sr = new StreamReader(opg.FileName))
                    {
                        List <byte> colors  = new List <byte>();
                        Center[]    centers = SuperPixelSegment.ReadCenter(sr.ReadToEnd());
                        //2.设置使用图层
                        SLICForm centerApplyForm = new SLICForm();
                        if (centerApplyForm.ShowDialog() == DialogResult.OK)
                        {
                            ThreadStart s = delegate { RunCenter(centerApplyForm.FileNameCollection, centers); };
                            Thread      t = new Thread(s);
                            t.IsBackground = true;
                            t.Start();
                        }
                    }
                }
                break;

            //dqn classification
            case "DQN_toolStripButton":
                DQNForm dqnForm = new DQNForm();
                dqnForm.RasterDic = _rasterDic;
                if (dqnForm.ShowDialog() == DialogResult.OK)
                {
                    //"Image Classification",
                    if (dqnForm.TaskName == "Image Classification")
                    {
                        IJob dqnClassifyJob = new JobDQNClassify(_rasterDic[dqnForm.SelectedFeatureRasterLayer], _rasterDic[dqnForm.SelectedLabelRasterLayer], dqnForm.Epochs);
                        RegisterJob(dqnClassifyJob);
                        dqnClassifyJob.Start();
                    }
                    //"Road Extraction"
                    else if (dqnForm.TaskName == "Road Extraction")
                    {
                    }
                }
                break;

            //cnn classification
            case "CNN_toolStripButton":
                CNNForm cnnForm = new CNNForm();
                cnnForm.RasterDic = _rasterDic;
                if (cnnForm.ShowDialog() == DialogResult.OK)
                {
                    IJob cnnClassifyJob = new JobCNNClassify(_rasterDic[cnnForm.SelectedFeatureRasterLayer], _rasterDic[cnnForm.SelectedLabelRasterLayer], cnnForm.Epochs, cnnForm.Model, cnnForm.ImageWidth, cnnForm.ImageHeight, 1);
                    RegisterJob(cnnClassifyJob);
                    cnnClassifyJob.Start();
                }
                break;

            //random forest classification
            case "rf_toolStripButton":
                RandomForestForm rfForm = new RandomForestForm();
                rfForm.RasterDic = _rasterDic;
                if (rfForm.ShowDialog() == DialogResult.OK)
                {
                    IJob rfJob = new JobRFClassify(rfForm.TreeCount, rfForm.FullFilename, _rasterDic[rfForm.FeatureKey]);
                    RegisterJob(rfJob);
                    rfJob.Start();
                }
                break;

            //drawing comparsion multi-reslut curve
            case "Compare_Plot_toolStripButton":
                ComparedPlotForm cp_form = new ComparedPlotForm();
                cp_form.ShowDialog();
                break;

            default:
                break;
            }
        }