protected virtual void Dispose(bool disposeManagedResources)
 {
     // process only if mananged and unmanaged resources have
     // not been disposed of.
     if (!this.disposed)
     {
         //Trace.WriteLine("GridWrapper: Resources not disposed");
         if (disposeManagedResources)
         {
             //Trace.WriteLine("GridWrapper: Disposing managed resources");
             // dispose managed resources
             gErrorMsg = null;
         }
         // dispose unmanaged resources
         //Trace.WriteLine("GridWrapper: Disposing unmanaged resouces");
         if (grid != null)
         {
             //Trace.WriteLine("GridWrapper: Disposing of grid COM object");
             grid.Close();
             while (Marshal.ReleaseComObject(grid) != 0)
             {
                 ;
             }
             grid = null;
         }
         disposed = true;
     }
     else
     {
         Trace.WriteLine("GridWrapper: Resources already disposed");
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Wraps MapWinGIS.Close()
 /// </summary>
 public void Close()
 {
     if (m_Grid.Close() == false)
     {
         MapWinUtility.Logger.Dbg("Error closing grid: " + m_Grid.get_ErrorMsg(m_Grid.LastErrorCode));
         throw new MapWinGeoProc.MapWinException(m_Grid.LastErrorCode);
     }
 }
Esempio n. 3
0
        public bool RunAutoSnap(string outletPath, string newOutletPath, string d8Result, string streamShapeResult, double snapThreshod)
        {
            MapWinGIS.Grid g = new MapWinGIS.Grid();
            g.Open(d8Result);
            double dx = g.Header.dX;

            g.Close();
            return(MapWinGeoProc.Utils.SnapPointsToLines(outletPath, streamShapeResult, snapThreshod, dx / 2, newOutletPath, true, null));
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        /// <summary>
        /// 关闭图层. 设置未定义的图层类型
        /// </summary>
        public void Close()
        {
            m_error = LayerSourceError.None;
            switch (this.Type)
            {
            case LayerSourceType.Shapefile:
                m_shapefile.Close();
                m_shapefile = null;
                break;

            case LayerSourceType.Image:
                m_image.Close();
                m_image = null;
                break;

            case LayerSourceType.Grid:
                m_grid.Close();
                m_grid = null;
                break;

            default:
                break;
            }
        }
        /// <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");
        }