Example #1
0
        public void SaveAsTest()
        {
            if (DotSpatial.Data.DataManager.DefaultDataManager.PreferredProviders.Count == 0)
            {
                DotSpatial.Data.Rasters.GdalExtension.GdalRasterProvider lGdalRasterProvider = new DotSpatial.Data.Rasters.GdalExtension.GdalRasterProvider();
            }

            string GridDataFolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\..\..\..\Data\Grids\";

            DotSpatial.Data.IRaster sourceGrid = Raster.Open(GridDataFolder + @"elev_cm_ESRI\elev_cm_clip2\hdr.adf");
            Double sourceGridMaximum           = sourceGrid.Maximum;

            string savedGridName = GridDataFolder + @"elev_cm.tif";

            sourceGrid.SaveAs(savedGridName);

            Assert.AreEqual(sourceGrid.Maximum, sourceGridMaximum, 0.0001);

            DotSpatial.Data.IRaster savedSourceGrid = Raster.Open(savedGridName);

            Assert.AreEqual(sourceGridMaximum, savedSourceGrid.Maximum, 0.0001);

            sourceGrid.Close();
            savedSourceGrid.Close();
            System.IO.File.Delete(savedGridName);
        }
Example #2
0
        public void ClipRasterWithPolygonTest()
        {
            if (DotSpatial.Data.DataManager.DefaultDataManager.PreferredProviders.Count == 0)
            {
                DotSpatial.Data.Rasters.GdalExtension.GdalRasterProvider lGdalRasterProvider = new DotSpatial.Data.Rasters.GdalExtension.GdalRasterProvider();
            }

            DotSpatial.Data.Shapefile lClipPolygon = DotSpatial.Data.Shapefile.OpenFile(@"C:\Users\Jiri\Desktop\berounka.shp");
            DotSpatial.Data.IRaster   lGridToClip  = DotSpatial.Data.Raster.OpenFile(@"C:\Users\Jiri\Desktop\kriging2.bgd", false);

            DotSpatial.Data.Raster lGridAfterClip = new DotSpatial.Data.Raster();
            lGridAfterClip.Filename = @"C:\Users\Jiri\Desktop\kriging2.bgd";

            DotSpatial.Analysis.ClipRaster.ClipRasterWithPolygon(lClipPolygon.Features[0], lGridToClip, lGridAfterClip.Filename);

            IRaster ras2 = Raster.Open(lGridAfterClip.Filename);

            Assert.AreEqual(lGridAfterClip.NoDataValue, ras2.NoDataValue);
        }
Example #3
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            int    width     = 0;
            int    height    = 0;
            int    times     = 0;
            double threshold = 0.0;

            if (this.comboBoxInitialUrbanImage.SelectedItem == null || this.comboBoxLandSuitable.SelectedItem == null || this.comboBoxPg.SelectedItem == null)
            {
                MessageBox.Show("清先选择图层");
                return;
            }
            string initialUrbanImageLayerName = this.comboBoxInitialUrbanImage.SelectedItem.ToString();
            string pgLayerName           = this.comboBoxPg.SelectedItem.ToString();
            string landSuitableLayerName = this.comboBoxLandSuitable.SelectedItem.ToString();

            try
            {
                times     = Convert.ToInt32(this.textBoxTimes.Text);
                threshold = Convert.ToDouble(this.textBoxThreshold.Text);
            }
            catch
            {
                MessageBox.Show("请输入正确的times 和 threshold参数");
                return;
            }


            double[] imageBuffer    = GetData(initialUrbanImageLayerName, ref width, ref height);
            double[] pg             = GetData(pgLayerName, ref width, ref height);
            double[] suitableBuffer = GetData(landSuitableLayerName, ref width, ref height);

            if (imageBuffer == null || pg == null || suitableBuffer == null)
            {
                MessageBox.Show("图层名无效,图层不是栅格图层,将图层转化为GDAL dataset失败,从GDAL dataset中读取数据失败");
                return;
            }



            unsafe
            {
                fixed(double *pImageBuffer = imageBuffer, pSuitableBuffer = suitableBuffer, pPg = pg)
                {
                    // 调用c++接口得到模拟后的数据
                    SWIGTYPE_p_double result = simple_ca.simple_ca_logistic(new SWIGTYPE_p_double(new IntPtr(pImageBuffer), false),
                                                                            new SWIGTYPE_p_double(new IntPtr(pSuitableBuffer), false),
                                                                            new SWIGTYPE_p_double(new IntPtr(pPg), false),
                                                                            width,
                                                                            height, threshold, times);
                    //simple_ca.draw_image(new SWIGTYPE_p_double(new IntPtr(pImageBuffer), false), width, height);
                    //// 从指针中得到模拟结果,并纵向翻转
                    IntPtr  resultPointer = HandleRef.ToIntPtr(SWIGTYPE_p_double.getCPtr(result));
                    double *pResultImg    = (double *)resultPointer.ToPointer();

                    double[] resultImg = new double[width * height];
                    for (int row = 0; row < height; row++)
                    {
                        for (int col = 0; col < width; col++)
                        {
                            resultImg[row * width + col] = pResultImg[(height - row - 1) * width + col];
                        }
                    }

                    // 新建 GDAL dataset
                    OSGeo.GDAL.Driver  driver  = OSGeo.GDAL.Gdal.GetDriverByName("MEM");
                    OSGeo.GDAL.Dataset dataset = driver.Create("", width, height, 1, OSGeo.GDAL.DataType.GDT_Float64, null);
                    dataset.WriteRaster(0, 0, width, height, resultImg, width, height, 1, new int[1] {
                        1
                    }, 0, 0, 0);

                    // 将GDAL dataset转化为IRaster数据集
                    DotSpatial.Data.IRaster raster = GIS.GDAL.RasterConverter.Gdal2DSRaster(dataset, 1);
                    raster.Name = "Result";
                    this.Map.Layers.Add(raster);
                }
            }
        }
Example #4
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            double a0 = 0.0;
            double a1 = 0.0;
            int    moorNeighbourSize      = 0;
            double tSpon                  = 0.0;
            double sigma                  = 0.0;
            int    amountOfNewDevelopment = 0;


            // 读取配置参数
            try
            {
                a0 = Convert.ToDouble(this.textBoxA0.Text);
                a1 = Convert.ToDouble(this.textBoxA1.Text);
                moorNeighbourSize      = Convert.ToInt32(this.textBoxMoorNeighbourSize.Text);
                tSpon                  = Convert.ToDouble(this.textBoxTSpon.Text);
                sigma                  = Convert.ToDouble(this.textBoxSigma.Text);
                amountOfNewDevelopment = Convert.ToInt32(this.textBoxAmountOfNewDevelopment.Text);
            }
            catch
            {
                MessageBox.Show("请输入正确的a0 ,a1 , moorNeighbourSize, tSpon, sigma, amountOfNewDevelopment参数");
                return;
            }

            // 读取图层
            if (this.comboBoxInitialData.SelectedItem == null || this.comboBoxPgData.SelectedItem == null || this.comboBoxSuitableData.SelectedItem == null)
            {
                MessageBox.Show("清先选择图层");
                return;
            }
            string initialUrbanImageLayerName = this.comboBoxInitialData.SelectedItem.ToString();
            string pgLayerName           = this.comboBoxPgData.SelectedItem.ToString();
            string landSuitableLayerName = this.comboBoxSuitableData.SelectedItem.ToString();

            int width  = 0;
            int height = 0;

            double[] imageBuffer    = GetData(initialUrbanImageLayerName, ref width, ref height);
            double[] suitableBuffer = GetData(landSuitableLayerName, ref width, ref height);
            double[] pg             = GetData(pgLayerName, ref width, ref height);

            if (imageBuffer == null || pg == null || suitableBuffer == null)
            {
                MessageBox.Show("图层名无效,图层不是栅格图层,将图层转化为GDAL dataset失败,从GDAL dataset中读取数据失败");
                return;
            }

            //this.logisticPatchCa = new LogisticPatchCa(a0,
            //    a1,
            //    moorNeighbourSize,
            //    tSpon,
            //    sigma,
            //    height,
            //    width,
            //    imageBuffer,
            //    pg,
            //    suitableBuffer,
            //    amountOfNewDevelopment);

            //this.SetSimulate();
            //this.SetProgressBar();
            unsafe
            {
                fixed(double *pImageBuffer = imageBuffer, pSuitableBuffer = suitableBuffer, pPg = pg)
                {
                    // 调用c++接口得到模拟后的数据
                    SWIGTYPE_p_double result = logistic_patch_ca.logistic_patch_ca1(
                        a0,
                        a1,
                        moorNeighbourSize,
                        tSpon,
                        sigma,
                        height,
                        width,
                        new SWIGTYPE_p_double(new IntPtr(pImageBuffer), false),
                        new SWIGTYPE_p_double(new IntPtr(pSuitableBuffer), false),
                        new SWIGTYPE_p_double(new IntPtr(pPg), false),
                        amountOfNewDevelopment,
                        true);
                    // 从指针中得到模拟结果,并纵向翻转
                    IntPtr  resultPointer = HandleRef.ToIntPtr(SWIGTYPE_p_double.getCPtr(result));
                    double *pResultImg    = (double *)resultPointer.ToPointer();

                    double[] resultImg = new double[width * height];
                    for (int row = 0; row < height; row++)
                    {
                        for (int col = 0; col < width; col++)
                        {
                            resultImg[row * width + col] = pResultImg[(height - row - 1) * width + col];
                        }
                    }

                    // 新建 GDAL dataset
                    OSGeo.GDAL.Driver  driver  = OSGeo.GDAL.Gdal.GetDriverByName("MEM");
                    OSGeo.GDAL.Dataset dataset = driver.Create("", width, height, 1, OSGeo.GDAL.DataType.GDT_Float64, null);
                    dataset.WriteRaster(0, 0, width, height, resultImg, width, height, 1, new int[1] {
                        1
                    }, 0, 0, 0);

                    // 将GDAL dataset转化为IRaster数据集
                    DotSpatial.Data.IRaster raster = GIS.GDAL.RasterConverter.Gdal2DSRaster(dataset, 1);
                    raster.Name = "Result";
                    this.Map.Layers.Add(raster);
                }
            }
        }