Esempio n. 1
0
 /// <summary>
 /// Saves the grid using all the current settings, using the extension to determine file type.
 /// </summary>
 public void Save()
 {
     if (m_Grid.Save(m_Grid.Filename, MapWinGIS.GridFileType.UseExtension, m_ICallBack) == false)
     {
         MapWinUtility.Logger.Dbg("MapWinGIS.Grid.Save threw an Exception.");
         throw new MapWinException(m_Grid.LastErrorCode);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Er... Changes a grid format?
        /// </summary>
        /// <param name="origFilename">Original Grid Filename</param>
        /// <param name="newFilename">Output Grid Filename</param>
        /// <param name="newFileType">Specifies the original file format of the grid</param>
        /// <param name="newFileFormat">Specifies the new file format</param>
        /// <param name="multFactor">Like Extrusion, this multiplies the Z value</param>
        /// <returns>Boolean, false if there was an error</returns>
        public static bool ChangeGridFormat(string origFilename, string newFilename, MapWinGIS.GridFileType newFileType, MapWinGIS.GridDataType newFileFormat, float multFactor)
        {
            bool Errors = false;

            MapWinGIS.Grid tGrd = new MapWinGIS.Grid();
            tGrd.Open(origFilename, MapWinGIS.GridDataType.UnknownDataType, true, MapWinGIS.GridFileType.UseExtension, null);

            Logger.Status("Writing Grid to New Format");

            //If we're multiplying by a factor, must
            //create the new grid and actually do it ourselves.
            //Otherwise, can save directly
            //Jiri Kadlec 1-28-2009 we still neet to create a new grid when the data or file type is different.
            if (multFactor == 1 && newFileFormat == tGrd.DataType)
            {
                Logger.Dbg("Saving directly to new format");
                tGrd.Save(newFilename, newFileType, null);
                // ProgressForm)
            }
            else
            {
                Logger.Dbg("Saving to new format with mult. factor: " + multFactor.ToString());

                MapWinGIS.GridHeader hdr = new MapWinGIS.GridHeader();
                hdr.CopyFrom(tGrd.Header);

                MapWinGIS.Grid newgrid = new MapWinGIS.Grid();
                if (!newgrid.CreateNew(newFilename, hdr, newFileFormat, hdr.NodataValue, true, newFileType, null))
                {
                    Logger.Message("Unable to create new grid!", "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error, System.Windows.Forms.DialogResult.OK);
                    Errors = true;
                }
                else
                {
                    int     ncols  = tGrd.Header.NumberCols;
                    int     nrows  = tGrd.Header.NumberRows;
                    float[] oneRow = new float[ncols + 1];
                    for (int i = 0; i <= nrows - 1; i++)
                    {
                        tGrd.GetFloatWindow(i, i, 0, ncols, ref oneRow[0]);
                        for (int z = 0; z <= ncols - 1; z++)
                        {
                            oneRow[z] *= multFactor;
                        }
                        newgrid.PutFloatWindow(i, i, 0, ncols, ref oneRow[0]);
                    }
                    newgrid.Save(newFilename, newFileType, null);
                    newgrid.Close();
                }
            }

            return(!Errors);
        }
 public bool Save(string gridFile)
 {
     if (grid.Save(gridFile, MapWinGIS.GridFileType.UseExtension, null) == false)
     {
         gErrorMsg = "Problem saving grid: " + grid.get_ErrorMsg(grid.LastErrorCode);
         Error.SetErrorMsg(gErrorMsg);
         Debug.WriteLine(gErrorMsg);
         return(false);
     }
     else
     {
         return(true);
     }
 }
        /// <summary>
        /// This overload calculates the difference between files.  THe number of rows and columns should be the same.
        /// </summary>
        /// <param name="SourceFile1">String filename of one grid to compare</param>
        /// <param name="SourceFile2">String filename of another grid to compare</param>
        /// <param name="DestFile">String filename of the output difference file</param>
        /// <param name="Overwrite">Boolean, true if you wish to overwrite an existing output
        /// file and delete the associated .bmp file.  False raises a messagebox if the files exist.</param>
        /// <param name="ICallBack">A MapWinGIS.ICallBack for status messages</param>
        public static void Difference(string SourceFile1, string SourceFile2, string DestFile, bool Overwrite, MapWinGIS.ICallback ICallBack)
        {
            MapWinGIS.Grid Source1 = new MapWinGIS.Grid();
            MapWinGIS.Grid Source2 = new MapWinGIS.Grid();
            MapWinGIS.Grid Dest    = new MapWinGIS.Grid();
            bool           res;

            // Open the source grids
            if (ICallBack != null)
            {
                ICallBack.Progress("Status", 0, "Opening Files...");
            }
            res = Source1.Open(SourceFile1, MapWinGIS.GridDataType.UnknownDataType, true, MapWinGIS.GridFileType.UseExtension, ICallBack);
            if (res == false)
            {
                MapWinUtility.Logger.Dbg("Argument Exception: " + Source1.get_ErrorMsg(Source1.LastErrorCode));
                throw new ArgumentException(Source1.get_ErrorMsg(Source1.LastErrorCode));
            }
            res = Source2.Open(SourceFile2, MapWinGIS.GridDataType.UnknownDataType, true, MapWinGIS.GridFileType.UseExtension, ICallBack);
            if (res == false)
            {
                throw new ArgumentException(Source2.get_ErrorMsg(Source2.LastErrorCode));
            }

            // Delete any existing files for our output grid
            if (System.IO.File.Exists(DestFile))
            {
                string bmp   = System.IO.Path.ChangeExtension(DestFile, "bmp");
                string bpw   = System.IO.Path.ChangeExtension(DestFile, "bpw");
                string prj   = System.IO.Path.ChangeExtension(DestFile, "prj");
                string mwleg = System.IO.Path.ChangeExtension(DestFile, "mwleg");
                if (Overwrite == false)
                {
                    if (System.IO.File.Exists(bmp) || System.IO.File.Exists(bpw) ||
                        System.IO.File.Exists(prj) || System.IO.File.Exists(mwleg))
                    {
                        if (MapWinUtility.Logger.Message("The output file exists, or associated files of the same name exist.  Do you wish to delete the existing files?\n", "Output Files Exist", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Warning, System.Windows.Forms.DialogResult.No) == System.Windows.Forms.DialogResult.No)
                        {
                            return;
                        }
                        // This ensures mapwindow will recognize the new image as a new file.
                        if (System.IO.File.Exists(bmp))
                        {
                            System.IO.File.Delete(bmp);
                        }
                        if (System.IO.File.Exists(bpw))
                        {
                            System.IO.File.Delete(bpw);
                        }
                        if (System.IO.File.Exists(prj))
                        {
                            System.IO.File.Delete(prj);
                        }
                        if (System.IO.File.Exists(mwleg))
                        {
                            System.IO.File.Delete(mwleg);
                        }
                    }
                    else
                    {
                        if (MapWinUtility.Logger.Message("The output file already exists.  Do you wish to delete it?", "Destination File Already Exists",
                                                         System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Warning, System.Windows.Forms.DialogResult.No)
                            == System.Windows.Forms.DialogResult.No)
                        {
                            return;
                        }
                    }
                }
                else
                {
                    if (System.IO.File.Exists(bmp))
                    {
                        System.IO.File.Delete(bmp);
                    }
                    if (System.IO.File.Exists(bpw))
                    {
                        System.IO.File.Delete(bpw);
                    }
                    if (System.IO.File.Exists(prj))
                    {
                        System.IO.File.Delete(prj);
                    }
                    if (System.IO.File.Exists(mwleg))
                    {
                        System.IO.File.Delete(mwleg);
                    }
                }
                System.IO.File.Delete(DestFile);
            }

            // Create a new output grid
            MapWinGIS.GridHeader newHeader = new MapWinGIS.GridHeader();
            newHeader.CopyFrom(Source1.Header);
            if (ICallBack != null)
            {
                MapWinUtility.Logger.Dbg("Creating Output File...");
                ICallBack.Progress("Status", 0, "Creating Output File...");
            }
            res = Dest.CreateNew(DestFile, newHeader, Source1.DataType, 0, true, MapWinGIS.GridFileType.UseExtension, ICallBack);
            if (res == false)
            {
                MapWinUtility.Logger.Dbg("Argument Exception: " + Dest.get_ErrorMsg(Dest.LastErrorCode));
                throw new ArgumentException(Dest.get_ErrorMsg(Dest.LastErrorCode));
            }

            // Calculate the differences
            Difference(Source1, Source2, Dest, ICallBack);

            // Close Source grids
            Source1.Close();
            Source2.Close();

            // Save and close the output grid
            res = Dest.Save(DestFile, MapWinGIS.GridFileType.UseExtension, ICallBack);
            if (res == false)
            {
                MapWinUtility.Logger.Dbg("Application Exception: " + Dest.get_ErrorMsg(Dest.LastErrorCode));
                throw new ArgumentException(Dest.get_ErrorMsg(Dest.LastErrorCode));
            }
            Dest.Close();
            MapWinUtility.Logger.Dbg("Finished Difference");
        }