Ejemplo n.º 1
0
        private void ReadInputData(int outRow, int rowCount, RasterVirtualVistor <Tsrc>[] fileVistor, Tsrc nullValue)
        {
            for (int i = 0; i < _fileIn.Length; i++)
            {
                RasterVirtualVistor <Tsrc> fv = new RasterVirtualVistor <Tsrc>();
                fv.Raster  = _fileIn[i].Raster;
                fv.BandMap = _fileIn[i].BandMap;
                fv.IndexY  = outRow;
                fv.SizeY   = rowCount;
                fv.SizeX   = _fileIn[i].Raster.Width;
                //
                int[]         bandMap = _fileIn[i].BandMap;
                IRasterBand[] bands   = new RasterBand[bandMap.Length];
                for (int b = 0; b < bandMap.Length; b++)
                {
                    bands[b] = _fileIn[i].Raster.GetRasterBand(bandMap[b]);
                }
                fv.Bands = bands;
                Tsrc[][] bandsVirtureData = new Tsrc[bands.Length][];

                for (int j = 0; j < bands.Length; j++)
                {
                    int    bandNo         = bandMap[j];
                    Tsrc[] dstVirtualData = _vRasterIn[i].ReadData <Tsrc>(bandNo, 0, outRow, _vRasterIn[i].VirtualHeader.Width, rowCount, nullValue);
                    bandsVirtureData[j] = dstVirtualData;
                }
                fv.RasterBandsData = bandsVirtureData;
                fileVistor[i]      = fv;
            }
        }
Ejemplo n.º 2
0
        public RasterMinMaxModel(RasterBand band)
        {
            _band = band;

            RangeLowPercent   = 2.0;
            RangeHightPercent = 98.0;
            StdDevRange       = 2.0;
        }
Ejemplo n.º 3
0
        private void ComputeBandMinMax(RasterBand band, BandInfo bandInfo)
        {
            if (band == null || bandInfo == null)
            {
                return;
            }

            double min, max;

            if (band.ComputeMinMax(false, out min, out max))
            {
                bandInfo.Min.DoubleValue = min;
                bandInfo.Max.DoubleValue = max;
            }
        }
Ejemplo n.º 4
0
        private void ShowLocalStatistics(NodeData parent, RasterBand band, SelectionItem pixel)
        {
            double min, max, mean, stdDev;
            int    count;

            if (!band.ComputeLocalStatistics(pixel.Column, pixel.Row, LocalStatsRange, out min, out max, out mean, out stdDev,
                                             out count))
            {
                parent.AddSubItem("Local stats", "<failed to compute>");
            }
            else
            {
                var nodeStats = parent.AddSubItem("Local stats", LocalStatsRange + " pixel range");
                nodeStats.AddSubItem("Minimum", min);
                nodeStats.AddSubItem("Maximum", max);
                nodeStats.AddSubItem("Mean", mean);
                nodeStats.AddSubItem("Std. deviation", stdDev);
                nodeStats.AddSubItem("Count", count);
            }
        }
Ejemplo n.º 5
0
        private NodeData GetMetadata(RasterBand band)
        {
            if (band.MetadataCount > 0)
            {
                var metadata = new NodeData("Metadata");
                for (int j = 0; j < band.MetadataCount; j++)
                {
                    string s     = band.get_MetadataItem(j);
                    var    parts = s.Split('=');
                    if (parts.Length == 2)
                    {
                        metadata.AddSubItem(parts[0], parts[1]);
                    }
                }

                return(metadata);
            }

            return(null);
        }
Ejemplo n.º 6
0
 internal void ReadOutputData(int outRow, int rowCount, RasterVirtualVistor <Tdst>[] fileVistor)
 {
     for (int i = 0; i < _fileOut.Length; i++)
     {
         RasterVirtualVistor <Tdst> fv = new RasterVirtualVistor <Tdst>();
         fv.BandMap = _fileOut[i].BandMap;
         fv.IndexY  = outRow;
         fv.SizeX   = _fileOut[i].Raster.Width;
         fv.SizeY   = rowCount;
         fv.Raster  = _fileOut[i].Raster;
         int[]         bandMap = _fileOut[i].BandMap;
         IRasterBand[] bands   = new RasterBand[bandMap.Length];
         for (int b = 0; b < bandMap.Length; b++)
         {
             bands[b] = _fileOut[i].Raster.GetRasterBand(bandMap[b]);
         }
         fv.Bands = bands;
         //初始化源数据访问
         int          outWidth    = _vRasterIn[0].VirtualHeader.Width;
         int          readOffsetx = 0;
         int          readOffsetY = outRow;
         int          xSize       = outWidth;
         int          ySize       = rowCount;
         enumDataType type        = _fileOut[i].Raster.DataType;
         //if (type == enumDataType.Int16)
         //{
         Tdst[][] bandsVirtureData = new Tdst[bands.Length][];
         for (int b = 0; b < bands.Length; b++)
         {
             Tdst[]   bufferData = new Tdst[xSize * ySize];
             GCHandle buffer     = GetHandles(bufferData);
             bands[b].Read(readOffsetx, readOffsetY, xSize, ySize, buffer.AddrOfPinnedObject(), type, xSize, ySize);
             buffer.Free();
             bandsVirtureData[b] = bufferData;
         }
         fv.RasterBandsData = bandsVirtureData;
         //}
         fileVistor[i] = fv;
     }
 }
Ejemplo n.º 7
0
        public void Reclassify()
        {
            InitColorRamp();
            IRasterWorkspace  pRWS;
            IWorkspaceFactory pWorkspaceFactory;

            pWorkspaceFactory = new RasterWorkspaceFactory();
            String wsp;
            int    r;
            int    l;

            r    = ComboBoxInLayer.Text.LastIndexOf("\\");
            l    = ComboBoxInLayer.Text.LastIndexOf(".");
            wsp  = ComboBoxInLayer.Text.Substring(0, r);
            pRWS = (IRasterWorkspace)pWorkspaceFactory.OpenFromFile(wsp, 0);
            try
            {
                string ws  = System.IO.Path.GetDirectoryName(ComboBoxInLayer.Text);
                string fbs = System.IO.Path.GetFileName(ComboBoxInLayer.Text);

                IWorkspaceFactory pWork     = new RasterWorkspaceFactory();
                IRasterWorkspace  pRasterWs = pWork.OpenFromFile(ws, 0) as IRasterWorkspace;
                pRster = pRasterWs.OpenRasterDataset(fbs).CreateDefaultRaster();



                IRasterBandCollection pRasterBandCol;
                pRasterBandCol = (IRasterBandCollection)pRster;


                IRawPixels pRawpixel;
                pRawpixel = (IRawPixels)pRasterBandCol.Item(0);
                IRasterProps pRasterProps;
                pRasterProps = (IRasterProps)pRawpixel;
                IPnt pSize;
                pSize = new DblPnt();
                pSize.SetCoords(pRasterProps.Width, pRasterProps.Height);
                IPixelBlock pPixelBlock;
                pPixelBlock = pRawpixel.CreatePixelBlock(pSize);
                IPnt pPnt;
                pPnt   = new DblPnt();
                pPnt.X = 0; //the origin (top left corner) of the PixelBlock
                pPnt.Y = 0;
                pRawpixel.Read(pPnt, pPixelBlock);
                float PixelValue;

                minValue = 10000000;
                maxValue = 0;
                List <double> allValue = new List <double>();
                for (int i = 0; i < pPixelBlock.Width; i++)
                {
                    for (int j = 0; j < pPixelBlock.Height; j++)
                    {
                        PixelValue = (float)pPixelBlock.GetVal(0, i, j);
                        allValue.Add(PixelValue);
                        if (PixelValue != null)
                        {
                            if (PixelValue > maxValue)
                            {
                                maxValue = PixelValue;
                            }
                            if (PixelValue < minValue)
                            {
                                minValue = PixelValue;
                            }
                        }
                    }
                }

                IRasterBand pRasterBand = new RasterBand();
                pRasterBand = pRasterBandCol.Item(0);
                pRasterBand.ComputeStatsAndHist();

                IRasterStatistics pRasterStatistic;
                //double[] amount = pRasterBand.Histogram.Counts;
                pRasterStatistic = pRasterBand.Statistics;
                maxValue         = (float)pRasterStatistic.Maximum;
                minValue         = (float)pRasterStatistic.Minimum;

                //if (comboBox1.Text.Trim() == "等间隔")
                //{//先求每个等分间距
                float   Tmpincrement;
                DataRow FilterRow;
                Tmpincrement = (maxValue - minValue) / Convert.ToInt16(CmbLineCount.Text);
                FilterDataTable.Rows.Clear();
                for (int i = 1; i <= Convert.ToInt16(CmbLineCount.Text); i++)
                {
                    FilterRow    = FilterDataTable.NewRow();
                    FilterRow[0] = Convert.ToString(minValue + Tmpincrement * (i - 1)) + "~" + Convert.ToString(minValue + Tmpincrement * i);
                    FilterRow[1] = i;
                    FilterRow[2] = i;
                    FilterDataTable.Rows.Add(FilterRow);
                }
                DataGridFilterData.DataSource = FilterDataTable;
                DataGridFilterData.Refresh();
                // }
//else
                // {
                ////allValue.Sort();
                ////List<double> valuesort = new List<double>();
                ////valuesort = BublleSort(allValue);
                //allValue.Sort();
                //int amount = pPixelBlock.Width * pPixelBlock.Height;
                //int Tmpincrement;
                //DataRow FilterRow;
                //Tmpincrement = (amount) / Convert.ToInt16(CmbLineCount.Text);
                //FilterDataTable.Rows.Clear();
                //for (int i = 1; i < Convert.ToInt16(CmbLineCount.Text); i++)
                //{
                //    FilterRow = FilterDataTable.NewRow();
                //    if (allValue[Tmpincrement * (i - 1)] == allValue[Tmpincrement * (i)])
                //        break;
                //    FilterRow[0] = Convert.ToString(allValue[Tmpincrement * (i - 1)]) + "~" + Convert.ToString(allValue[Tmpincrement * (i)]);
                //    FilterRow[1] = i;
                //    FilterDataTable.Rows.Add(FilterRow);
                //}
                //if (allValue[Tmpincrement * Convert.ToInt16(CmbLineCount.Text)] != maxValue)
                //{
                //    FilterRow = FilterDataTable.NewRow();
                //    FilterRow[0] = Convert.ToString(allValue[Tmpincrement * Convert.ToInt16(CmbLineCount.Text)]) + "~" + Convert.ToString(maxValue);
                //    FilterRow[1] = Convert.ToInt16(CmbLineCount.Text);
                //    FilterDataTable.Rows.Add(FilterRow);
                //}
                //DataGridFilterData.DataSource = FilterDataTable;
                //DataGridFilterData.Refresh();
                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }
Ejemplo n.º 8
0
        private void selectRasterCmb_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (selectDBCmb.Text == null || selectRasterCmb.Text == null)
            {
                return;
            }

            RBandCmb.Items.Clear();
            GBandCmb.Items.Clear();
            BBandCmb.Items.Clear();

            rds = new RasterDataSet(GDB);
            rds.Open(selectRasterCmb.Text, 0);

            //将波段添加到各个comoBox中
            for (int i = 0; i < rds.GetBandNum(); i++)
            {
                RasBand = rds.GetRasterBand(i + 1);
                RBandCmb.Items.Add("波段" + (i + 1));
                GBandCmb.Items.Add("波段" + (i + 1));
                BBandCmb.Items.Add("波段" + (i + 1));
            }



            //在地图空间中显示该图层
            Map map = new Map();

            themeLayer = new RasterLayer();

            if (rds != null)
            {
                themeLayer.AttachData(rds);
            }

            map.Append(themeLayer);
            this.mapControl.ActiveMap = map;
            this.mapControl.Restore();


            RBandCmb.Text = "";
            GBandCmb.Text = "";
            BBandCmb.Text = "";

            if (RBandCmb.Items.Count >= 3 && GBandCmb.Items.Count >= 3 && BBandCmb.Items.Count >= 3)
            {
                RBandCmb.Enabled = true;
                GBandCmb.Enabled = true;
                BBandCmb.Enabled = true;

                RBandCmb.SelectedIndex = 0;
                GBandCmb.SelectedIndex = 1;
                BBandCmb.SelectedIndex = 2;
            }
            else
            {
                RBandCmb.Enabled = false;
                GBandCmb.Enabled = false;
                BBandCmb.Enabled = false;
            }

            //显示图像信息
            height = rds.GetPixelHeight();
            width  = rds.GetPixelWidth();

            labelHeight.Text = height.ToString();
            labelWidth.Text  = Width.ToString();

            labelHeight.Visible = true;
            labelWidth.Visible  = true;

            //显示图像分辨率
            resolutionX = rds.GetResolutionX();
            resolutionY = rds.GetResolutionY();

            labelResolutionX.Text = resolutionX.ToString();
            labelResolutionY.Text = resolutionY.ToString();

            labelResolutionX.Visible = true;
            labelResolutionY.Visible = true;



            //给分类器设置参数

            /*
             * textBox2.Text = "4";
             * textBox3.Text = "16";
             * textBox4.Text = "20";
             * textBox5.Text = "0.01";
             * textBox9.Text = "0.005";
             * textBox8.Text = "9.8";
             * textBox7.Text = "5";
             * textBox6.Text = "6.4";
             */
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Equalizes the histogram on a single raster band, asynchronously.
 /// </summary>
 /// <param name="band">The raster band.</param>
 /// <returns>A Tuple containing a BackgroundWorker representing the asynchronous operation and its parameter.</returns>
 public static BackgroundWorker EqualizeHistogram(RasterBand band)
 {
     return(EqualizeHistogram(new[] { band }));
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates an RGB composite of three or less bands of a dataset, asynchronously.
        /// </summary>
        /// <param name="gb">The dataset.</param>
        /// <param name="b1">The band representing the red values.</param>
        /// <param name="b2">The band representing the green values.</param>
        /// <param name="b3">The band representing the blue values.</param>
        /// <returns>A BackgroundWorker representing the asynchronous operation.</returns>
        public static BackgroundWorker CreateRGBComposite(Dataset gb, int b1, int b2, int b3)
        {
            BackgroundWorker bw = new BackgroundWorker();

            bw.DoWork += (s, e) => {
                MessageLog.Add("Creating RGB composite.");

                // Start timekeeping.
                Stopwatch st = new Stopwatch();
                st.Start();

                Bitmap     b  = new Bitmap((int)gb.Header.NCols, (int)gb.Header.NRows, PixelFormat.Format24bppRgb);
                BitmapData bd = b.LockBits(
                    new Rectangle(0, 0, (int)gb.Header.NCols, (int)gb.Header.NRows),
                    ImageLockMode.WriteOnly,
                    PixelFormat.Format24bppRgb
                    );

                // b1, b2, b3 are coming directly from the UI
                // This is where we check if any of them are omitted.
                RasterBand band1 = (b1 > -1) ? gb.Bands[(int)b1] : null;
                RasterBand band2 = (b2 > -1) ? gb.Bands[(int)b2] : null;
                RasterBand band3 = (b3 > -1) ? gb.Bands[(int)b3] : null;

                // Lock image bits
                if (band1 != null)
                {
                    band1.LockBits(ImageLockMode.ReadOnly);
                }
                if (band2 != null)
                {
                    band2.LockBits(ImageLockMode.ReadOnly);
                }
                if (band3 != null)
                {
                    band3.LockBits(ImageLockMode.ReadOnly);
                }

                unsafe {
                    for (int y = 0; y < gb.Header.NRows; y++)
                    {
                        byte *row = (byte *)bd.Scan0 + (y * bd.Stride), row1 = null, row2 = null, row3 = null;

                        // We preset a pointer before looping through rows,
                        // this is faster than calculating the offset in every iteration of the inner loop.
                        if (band1 != null)
                        {
                            row1 = ((byte *)band1.BitmapData.Scan0 + (y * band1.BitmapData.Stride));
                        }
                        if (band2 != null)
                        {
                            row2 = ((byte *)band2.BitmapData.Scan0 + (y * band2.BitmapData.Stride));
                        }
                        if (band3 != null)
                        {
                            row3 = ((byte *)band3.BitmapData.Scan0 + (y * band3.BitmapData.Stride));
                        }

                        // GDI bitmaps are BGR instead of RGB (!)
                        for (int x = 0; x < gb.Header.NCols; x++)
                        {
                            row[x * 3 + 2] = (band1 != null) ? row1[x] : (byte)0;
                            row[x * 3 + 1] = (band2 != null) ? row2[x] : (byte)0;
                            row[x * 3 + 0] = (band3 != null) ? row3[x] : (byte)0;
                        }

                        if (bw.CancellationPending)
                        {
                            e.Cancel = true;
                            goto cleanup;
                        }

                        bw.ReportProgress((int)(((double)y / gb.Header.NRows) * 100));
                    }
                }

cleanup:
                if (band1 != null)
                {
                    band1.UnlockBits();
                }
                if (band2 != null)
                {
                    band2.UnlockBits();
                }
                if (band3 != null)
                {
                    band3.UnlockBits();
                }

                b.UnlockBits(bd);

                e.Result = b;

                // Stop timekeeping and log elapsed time.
                st.Stop();
                MessageLog.Add(String.Format("Composition took {0} msecs.", st.ElapsedMilliseconds));
            };

            return(bw);
        }