/// <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); } }
public bool Open(string gridFile, bool inRAM) { if (grid.Open(gridFile, MapWinGIS.GridDataType.UnknownDataType, inRAM, MapWinGIS.GridFileType.UseExtension, null) == false) { gErrorMsg = "Problem opening grid: " + grid.get_ErrorMsg(grid.LastErrorCode); Error.SetErrorMsg(gErrorMsg); Debug.WriteLine(gErrorMsg); return(false); } else { return(true); } }
/// <summary> /// This creates a new shapefile that has Z values and follows along the same line segments. /// The boundaries for grid cells are marked with vertices and the segment is given a Z value /// that corresponds to the grid elevation it intersects. /// </summary> /// <param name="ElevGrid">A string filename for the grid that contains the elevations.</param> /// <param name="PolyLine">A string filename for a polyline shapefile that shows the pathways of the cross sections in the X-Y direction.</param> /// <param name="OutFileName">A string containing the full path of the desired output shapefile. The extension should be *.shp</param> /// <param name="CrossSectionType">Clarifies the type of output</param> /// <param name="ICallBack">A MapWinGIS.ICallback for progress messages. [Optional]</param> /// <remarks>This function throws Argument or Application exceptions on errors, so it's recommended that coders enclose it in a try catch block.</remarks> public static void GetCrossSection(string ElevGrid, string PolyLine, string OutFileName, CrossSectionTypes CrossSectionType, MapWinGIS.ICallback ICallBack) { bool res; // Load the grid if (ElevGrid == null) { throw new ArgumentException("ElevGrid cannot be null."); } if (System.IO.File.Exists(ElevGrid) == false) { throw new ArgumentException("The file " + ElevGrid + " does not exist."); } MapWinGIS.Grid mwGrid = new MapWinGIS.Grid(); res = mwGrid.Open(ElevGrid, MapWinGIS.GridDataType.UnknownDataType, true, MapWinGIS.GridFileType.UseExtension, ICallBack); if (res == false) { throw new ApplicationException(mwGrid.get_ErrorMsg(mwGrid.LastErrorCode)); } // Load the Shapefile if (PolyLine == null) { throw new ArgumentException("PolyLine cannot be null."); } if (System.IO.File.Exists(PolyLine) == false) { throw new ArgumentException("The file " + PolyLine + " does not exist."); } MapWinGIS.Shapefile mwPolyLine = new MapWinGIS.Shapefile(); res = mwPolyLine.Open(PolyLine, ICallBack); if (res == false) { throw new ApplicationException(mwPolyLine.get_ErrorMsg(mwPolyLine.LastErrorCode)); } GetCrossSection(mwGrid, mwPolyLine, OutFileName, CrossSectionType, ICallBack); }
/// <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"); }