Ejemplo n.º 1
0
        private void BarButtonItem_ItemClick(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            var            file           = string.Empty;

            if (openFileDialog.ShowDialog() == true)
            {
                string          pathFile = openFileDialog.FileName;
                List <string[]> rows     = File.ReadAllLines(pathFile).Select(x => x.Split(',')).ToList();


                //add cols to datatable:
                string[] labelnya = rows[0];
                rows.RemoveAt(0);
                int no = 1;

                foreach (var item in rows)
                {
                    var data = new TutupanLahan();
                    data.no    = no++;
                    data.band1 = double.Parse(item[0]);
                    data.band2 = double.Parse(item[1]);
                    data.band3 = double.Parse(item[2]);
                    data.kelas = item[3];
                    lisdata.Add(data);
                }

                GridSource.DataContext = lisdata;
                RowsCount.Content      = lisdata.Count;

                DecisinTree(labelnya, rows);
            }
        }
Ejemplo n.º 2
0
        private void BarButtonItem_ItemClick_2(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            var            file           = string.Empty;

            if (openFileDialog.ShowDialog() == true)
            {
                string pathFile  = openFileDialog.FileName;
                string extension = Path.GetExtension(openFileDialog.FileName);
                if (extension.Equals(".csv"))
                {
                    List <string[]> rows = File.ReadAllLines(pathFile).Select(x => x.Split(',')).ToList();
                    rowstest    = rows;
                    lisdatatest = new List <TutupanLahan>();
                    string[] labelnya = rows[0];
                    rows.RemoveAt(0);
                    int no = 1;

                    foreach (var item in rows)
                    {
                        var data = new TutupanLahan();
                        data.no    = no++;
                        data.band1 = double.Parse(item[0]);
                        data.band2 = double.Parse(item[1]);
                        data.band3 = double.Parse(item[2]);
                        data.kelas = item[3];
                        lisdatatest.Add(data);
                    }
                    GridSourceTest.DataContext = lisdatatest;
                    RowsCount.Content          = lisdatatest.Count;
                }
                else
                {
                    MessageBox.Show("Mohon masukan fail dengan ekstensi csv");
                }
            }
        }
Ejemplo n.º 3
0
        private void BarButtonItem_ItemClick_5(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            var            file           = string.Empty;

            if (openFileDialog.ShowDialog() == true)
            {
                string pathFile  = openFileDialog.FileName;
                string extension = Path.GetExtension(openFileDialog.FileName);
                if (extension.Equals(".tif"))
                {
                    try
                    {
                        GdalConfiguration.ConfigureGdal();
                        Gdal.AllRegister();

                        Dataset ds = Gdal.Open(pathFile, Access.GA_ReadOnly);

                        if (ds == null)
                        {
                            Console.WriteLine("Can't open " + pathFile);
                            System.Environment.Exit(-1);
                        }

                        Console.WriteLine("Raster dataset parameters:");
                        Console.WriteLine("  Projection: " + ds.GetProjectionRef());
                        Console.WriteLine("  RasterCount: " + ds.RasterCount);
                        Console.WriteLine("  RasterSize (" + ds.RasterXSize + "," + ds.RasterYSize + ")");

                        Driver drv = ds.GetDriver();
                        if (drv == null)
                        {
                            Console.WriteLine("Can't get driver.");
                            System.Environment.Exit(-1);
                        }

                        Console.WriteLine("Using driver " + drv.LongName);

                        //raster size
                        int rasterCols = ds.RasterXSize;
                        int rasterRows = ds.RasterYSize;

                        //Extract geotransform
                        double[] geotransform = new double[6];
                        ds.GetGeoTransform(geotransform);

                        //Get raster bounding box
                        double originX     = geotransform[0];
                        double originY     = geotransform[3];
                        double pixelWidth  = geotransform[1];
                        double pixelHeight = geotransform[5];


                        double[] rasterValues;
                        double[] rasterValues2;
                        double[] rasterValues3;

                        int rastWidth  = rasterCols;
                        int rastHeight = rasterRows;

                        rasterValues  = new double[rastWidth * rastHeight];
                        rasterValues2 = new double[rastWidth * rastHeight];
                        rasterValues3 = new double[rastWidth * rastHeight];

                        for (int iBand = 1; iBand <= ds.RasterCount; iBand++)
                        {
                            Band band = ds.GetRasterBand(iBand);
                            Console.WriteLine("Band " + iBand + " :");
                            Console.WriteLine("DataType: " + band.DataType);
                            Console.WriteLine("Size (" + band.XSize + "," + band.YSize + ")");

                            if (iBand == 1)
                            {
                                band.ReadRaster(0, 0, rastWidth, rastHeight, rasterValues, rastWidth, rastHeight, 0, 0);
                                rasterValues = rasterValues.Where(x => x > 0).ToArray();
                            }
                            else if (iBand == 2)
                            {
                                band.ReadRaster(0, 0, rastWidth, rastHeight, rasterValues2, rastWidth, rastHeight, 0, 0);
                                rasterValues2 = rasterValues2.Where(x => x > 0).ToArray();
                            }
                            else if (iBand == 3)
                            {
                                band.ReadRaster(0, 0, rastWidth, rastHeight, rasterValues3, rastWidth, rastHeight, 0, 0);
                                rasterValues3 = rasterValues3.Where(x => x > 0).ToArray();
                            }
                        }
                        lisdatatest = new List <TutupanLahan>();
                        inputsTIF   = new double[rasterValues3.Length][];
                        for (int i = 0; i < rasterValues.Length; i++)
                        {
                            inputsTIF[i] = new double[3] {
                                rasterValues[i], rasterValues2[i], rasterValues3[i]
                            };
                            var data = new TutupanLahan();
                            data.no    = i;
                            data.band1 = rasterValues[i];
                            data.band2 = rasterValues2[i];
                            data.band3 = rasterValues3[i];
                            data.kelas = string.Empty;
                            lisdatatest.Add(data);
                        }

                        GridSourceTest.DataContext = lisdatatest;
                        RowsCount.Content          = lisdatatest.Count;
                    }
                    catch (Exception x)
                    {
                        Console.WriteLine("Application error: " + x.Message);
                    }
                }
                else
                {
                    MessageBox.Show("Mohon masukan Data TIF");
                }
            }
        }