Ejemplo n.º 1
0
        //Execute
        private void button2_Click(object sender, EventArgs e)
        {
            string OutputString = this.textBox1.Text.Trim();
            string InputString  = this.comboBox1.Text.Trim();

            //The input is null
            if ((InputString == "") || (OutputString == ""))
            {
                MessageBox.Show("The parameters are not complete.", "Admin", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (File.Exists(OutputString))
            {
                MessageBox.Show("The output file has existed.", "Admin", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            int selectIndex = this.comboBox1.SelectedIndex;

            if ((selectIndex < 0) && (InputString != "")) //Input data by selecting from folder
            {
                RasterSymbolizer  RasterSymbol  = new RasterSymbolizer();
                IRasterSymbolizer IRasterSymbol = RasterSymbol;
                MapRasterLayer    RasterLayer   = new MapRasterLayer(InputString, RasterSymbol); //Open the raster layer
                IRaster           Raster        = RasterLayer.DataSet;
            }
            else if (selectIndex >= 0) //Input data by selecting from combox
            {
                IMapRasterLayer[] RasterArr   = MainMap.GetRasterLayers();
                IMapRasterLayer   RasterLayer = RasterArr[selectIndex];
                IRaster           Raster      = RasterLayer.DataSet;
            }
        }
Ejemplo n.º 2
0
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            //check if there is a raster in the map
            IMapRasterLayer[] rasters = mapMain.GetRasterLayers();
            if (rasters.Length == 0)
            {
                MessageBox.Show("Please add the snow data layer to the map");
                return;
            }

            //we use the first raster layer for snow calculation
            IMapRasterLayer snowLayer  = rasters[0];
            IRaster         snowRaster = snowLayer.DataSet;

            //creates a variable for the coordinate
            DotSpatial.Topology.Coordinate c;

            //create a feature variable from the polygon
            IFeature polygon = polygonFNew.Features[0];
            IRaster  cRaster = null;

            //clip raster with polygon: using built-in function
            //note: this is slow because it still makes a huge raster...
            cRaster = DotSpatial.Analysis.ClipRaster.ClipRasterWithPolygon(polygon, snowRaster, "snowRasterClip.bgd");

            //add the new clipped raster to the map
            mapMain.Layers.Add(cRaster);

            //calculate the volume using function in our VolumeCalculator class
            VolumeCalculator volumeCalc = new VolumeCalculator();
            double           volume_m3  = volumeCalc.CalculateVolume(cRaster);
            List <double>    areas_m2   = volumeCalc.CalculateAreaForLatLon(cRaster);

            //show the volume in the "results" textbox
            string volText = Convert.ToString(Math.Round(volume_m3, 0));

            string snowAreaText = Convert.ToString(Math.Round(areas_m2[0], 0));

            string totalAreaText = Convert.ToString(Math.Round(areas_m2[1], 0));

            double snowPercent     = 100 * (areas_m2[0] / areas_m2[1]);
            string snowPercentText = Convert.ToString(Math.Round(snowPercent, 1));

            tbVolume.Text = "Volume: " + volText + "(m\xB3)" + "\n" +
                            "Snow-covered area: " + snowAreaText + "(m\xB2)" + "\n"; //+
            //"Total area: " + totalAreaText + "\n" +
            //"Percent snow-covered: " + snowPercentText + "\n";
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds a new node to the tree view with the layer name
        /// </summary>
        /// <param name="layer">The layer.</param>
        /// <param name="bounds">The bounds.</param>
        internal void Add(IMapRasterLayer layer, Extent bounds)
        {
            treFeatures.SuspendLayout();

            var index = layer.DataSet.ProjToCell(bounds.Center);

            if (index == RcIndex.Empty)
            {
                return;
            }
            var val = layer.DataSet.Value[index.Row, index.Column];

            var text      = String.Format("{0} = {1} ({2},{3})", layer.LegendText, val, index.Column, index.Row);
            var nodeLayer = treFeatures.Nodes.Add(text);

            nodeLayer.Tag  = layer;
            nodeLayer.Name = layer.LegendText;

            treFeatures.ResumeLayout();
        }
Ejemplo n.º 4
0
        private void myButton_Click(object sender, EventArgs e)
        {
            foreach (var recentFile in Settings.Default.RecentFiles)
            {
                MessageBox.Show("Recent File: " + recentFile);
            }

            IMapRasterLayer[] layers = App.Map.GetRasterLayers();
            if (layers.Length == 0)
            {
                MessageBox.Show("Please add a raster layer.");
                return;
            }
            IMapRasterLayer layer = layers[0];

            layer.Symbolizer.ShadedRelief.ElevationFactor = 1;
            layer.Symbolizer.ShadedRelief.IsUsed          = true;
            layer.Symbolizer.CreateHillShade();

            layer.WriteBitmap();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Adds a new node to the tree view with the layer name
        /// </summary>
        /// <param name="layer">The layer.</param>
        /// <param name="bounds">The bounds.</param>
        internal void Add(IMapRasterLayer layer, Extent bounds)
        {
            treFeatures.SuspendLayout();

            var index = layer.DataSet.ProjToCell(bounds.Center);
            if (index == RcIndex.Empty) return;
            var val = layer.DataSet.Value[index.Row, index.Column];

            string text = String.Format("{0} = {1} ({2},{3})", layer.LegendText, val, index.Column, index.Row);
            TreeNode nodeLayer = treFeatures.Nodes.Add(text);
            nodeLayer.Tag = layer;
            nodeLayer.Name = layer.LegendText;

            treFeatures.ResumeLayout();
        }
Ejemplo n.º 6
0
        //saves the current HydroDesktop project file to the user specified location
        public void SavingProject()
        {
            string projectFileName = App.SerializationManager.CurrentProjectFile;

            Settings.Instance.AddFileToRecentFiles(projectFileName);

            string newProjectDirectory = Path.GetDirectoryName(projectFileName);

            App.ProgressHandler.Progress("Saving Project " + projectFileName, 0, "");
            Application.DoEvents();

            //are we saving or are we doing 'save as' ?
            if (projectFileName != Settings.Instance.CurrentProjectFile)
            {
                //also create a copy of the .sqlite database
                string newDbPath = Path.ChangeExtension(projectFileName, ".sqlite");

                //current database path
                string currentDbPath = SQLiteHelper.GetSQLiteFileName(Settings.Instance.DataRepositoryConnectionString);
                //copy db to new path. If no db exists, create new db in the new location
                if (SQLiteHelper.DatabaseExists(currentDbPath))
                {
                    File.Copy(currentDbPath, newDbPath, true);
                }
                else
                {
                    CreateNewDatabase(newDbPath);
                }
                //create a copy of the metadata cache (_cache.sqlite) database
                string newCachePath = projectFileName.Replace(".dspx", "_cache.sqlite");

                //current database path
                string currentCachePath = SQLiteHelper.GetSQLiteFileName(Settings.Instance.MetadataCacheConnectionString);
                //copy db to new path. If no db exists, create new db in the new location
                if (SQLiteHelper.DatabaseExists(currentCachePath))
                {
                    File.Copy(currentCachePath, newCachePath, true);
                }
                else
                {
                    SQLiteHelper.CreateMetadataCacheDb(newCachePath);
                }

                //TODO: need to trigger a DatabaseChanged event (Settings.Instance.DatabaseChanged..)

                //update application level database configuration settings
                Settings.Instance.DataRepositoryConnectionString = SQLiteHelper.GetSQLiteConnectionString(newDbPath);
                Settings.Instance.MetadataCacheConnectionString  = SQLiteHelper.GetSQLiteConnectionString(newCachePath);
                Settings.Instance.CurrentProjectFile             = App.SerializationManager.CurrentProjectFile;

                //Also save the files of all map layers

                string projDir = App.SerializationManager.CurrentProjectDirectory;

                foreach (IMapLayer layer in App.Map.MapFrame.GetAllLayers())
                {
                    IMapFeatureLayer fl = layer as IMapFeatureLayer;
                    if (fl != null)
                    {
                        if (!String.IsNullOrEmpty(fl.DataSet.Filename))
                        {
                            fl.DataSet.SaveAs(Path.Combine(projDir, Path.GetFileName(fl.DataSet.Filename)), true);
                        }
                    }
                    IMapRasterLayer rl = layer as IMapRasterLayer;
                    if (rl != null)
                    {
                        rl.DataSet.SaveAs(Path.Combine(projDir, Path.GetFileName(rl.DataSet.Filename)));
                    }
                }
            }
            App.ProgressHandler.Progress(String.Empty, 0, String.Empty);
        }