/// <summary> /// Returns a value like float Values[Y][X] where the block describes the window being specified /// </summary> /// <param name="StartRow">The 0 based row index corresponding to the Top (0,0 is Top, Left)</param> /// <param name="EndRow">The 0 based row index corresponding to the Bottom (0,0 is Top, Left)</param> /// <param name="StartCol">The 0 based column index corresponding to the Left (0,0 is Top, Left)</param> /// <param name="EndCol">The 0 based column index corresponding to the Right (0,0 is Top, Left)</param> /// <exception cref="System.ApplicationException">Returns an exception if there is a failure</exception> /// <remarks>The real return is in the Vals array that was dimensioned before calling this function.</remarks> public float[][] GetFloatWindow(int StartRow, int EndRow, int StartCol, int EndCol) { int X, Y; float[][] Vals = new float[(EndRow - StartRow) + 1][]; float[] RowVals = new float[m_Grid.Header.NumberCols]; Y = 0; for (int row = StartRow; row <= EndRow; row++) { X = 0; for (int col = StartCol; col < EndCol; col++) { X++; if (m_Grid.GetRow(Y, ref RowVals[0]) == false) { MapWinUtility.Logger.Dbg("MapWinGIS.Grid.GetRow returned an error."); throw new MapWinException(m_Grid.LastErrorCode); } Vals[Y][X] = RowVals[col]; } Y++; } return(Vals); }
public bool get_Row(int row, ref float[] valArray) { //talk to Chris about why this returns false.... grid.GetRow(row, ref valArray[0]); return(true); }
// This is not a full fledged map algebra function! This cannot deal with // images of different sizes or cell spacings. This is only a quick function // that can tell if, for instance, a pitfilled image is different from the // version created in Arcview. It simply takes each cell and finds the difference // in values. #region "Difference" /// <summary> /// Calculates the difference values and stores them in the Dest grid. This only works if the grids /// have the same number of rows and columns. /// </summary> /// <param name="Source1">MapWinGIS.Grid representing one source grid</param> /// <param name="Source2">MapWinGIS.Grid to compare Source1 against</param> /// <param name="Dest">MapWinGIS.Grid where the output is to be saved</param> /// <param name="ICallBack">A MapWinGIS.ICallBack</param> /// <remarks>Uses ArgumentExceptions if the grids are different sizes</remarks> public static void Difference(MapWinGIS.Grid Source1, MapWinGIS.Grid Source2, MapWinGIS.Grid Dest, MapWinGIS.ICallback ICallBack) { // Log entrance as best as possible while preventing errors from a null reference string Source1File = "null"; string Source2File = "null"; string DestFile = "null"; if (Source1 != null) { Source1File = Source1.Filename; if (Source1File == null) { Source1File = "Unnamed"; } } if (Source2 != null) { Source2File = Source2.Filename; if (Source2File == null) { Source2File = "Unnamed"; } } if (Dest != null) { DestFile = Dest.Filename; if (DestFile == null) { DestFile = "Unnamed"; } } MapWinUtility.Logger.Dbg("Difference(Source1: " + Source1File + ",\n" + " Source2: " + Source2File + ",\n" + " Dest: " + DestFile + ",\n" + " ICallback"); if (Source1 == null) { MapWinUtility.Logger.Dbg("Argument Exception: Source1 cannot be null."); throw new ArgumentException("Source1 cannot be null."); } if (Source2 == null) { MapWinUtility.Logger.Dbg("Argument Exception: Source2 cannot be null."); throw new ArgumentException("Source2 cannot be null."); } if (Dest == null) { MapWinUtility.Logger.Dbg("Argument Exception: Dest cannot be null."); throw new ArgumentException("Dest cannot be null."); } int nX, nY; nX = Source1.Header.NumberCols; nY = Source1.Header.NumberRows; if (Source2.Header.NumberRows != nY) { MapWinUtility.Logger.Dbg("Argument Exception: The grids are not the same height."); throw new ArgumentException("The grids are not the same height."); } if (Source2.Header.NumberCols != nX) { MapWinUtility.Logger.Dbg("Argument Exception: The grids are not the same width!"); throw new ArgumentException("The grids are not the same width!"); } if (Dest.Header.NumberRows != nY) { MapWinUtility.Logger.Dbg("Argument Exception: The output grid is not the same height!"); throw new ArgumentException("The output grid is not the same height!"); } if (Dest.Header.NumberCols != nX) { MapWinUtility.Logger.Dbg("Argument Exception: The output grid is not the same width!"); throw new ArgumentException("The output grid is not the same width!"); } int OldProg = 0; int Prog = 0; if (ICallBack != null) { ICallBack.Progress("Status", 0, "Difference...0% Complete"); } MapWinUtility.Logger.Progress("Difference...0% Complete", Prog, OldProg); if (Source1.DataType != MapWinGIS.GridDataType.FloatDataType) { switch (Source1.DataType) { case MapWinGIS.GridDataType.DoubleDataType: for (int Y = 0; Y < nY; Y++) { for (int X = 0; X < nX; X++) { double val = (double)Source1.get_Value(X, Y) - (double)Source2.get_Value(X, Y); Dest.set_Value(X, Y, val); } if (ICallBack != null) { Prog = (int)(Y * 100 / nY); if (Prog > OldProg) { ICallBack.Progress("Status", Prog, "Difference..." + Prog.ToString() + "% Complete"); MapWinUtility.Logger.Progress("Difference..." + Prog.ToString() + "% Complete", Prog, OldProg); OldProg = Prog; } } } break; case MapWinGIS.GridDataType.UnknownDataType: for (int Y = 0; Y < nY; Y++) { for (int X = 0; X < nX; X++) { double val = (double)Source1.get_Value(X, Y) - (double)Source2.get_Value(X, Y); Dest.set_Value(X, Y, val); } if (ICallBack != null) { Prog = (int)(Y * 100 / nY); if (Prog > OldProg) { ICallBack.Progress("Status", Prog, "Difference..." + Prog.ToString() + "% Complete"); MapWinUtility.Logger.Progress("Difference..." + Prog.ToString() + "% Complete", Prog, OldProg); OldProg = Prog; } } } break; case MapWinGIS.GridDataType.LongDataType: for (int Y = 0; Y < nY; Y++) { for (int X = 0; X < nX; X++) { long val = (long)Source1.get_Value(X, Y) - (long)Source2.get_Value(X, Y); Dest.set_Value(X, Y, val); } if (ICallBack != null) { Prog = (int)(Y * 100 / nY); if (Prog > OldProg) { MapWinUtility.Logger.Progress("Difference..." + Prog.ToString() + "% Complete", Prog, OldProg); ICallBack.Progress("Status", Prog, "Difference..." + Prog.ToString() + "% Complete"); OldProg = Prog; } } } break; case MapWinGIS.GridDataType.ShortDataType: for (int Y = 0; Y < nY; Y++) { for (int X = 0; X < nX; X++) { int val = (int)Source1.get_Value(X, Y) - (int)Source2.get_Value(X, Y); Dest.set_Value(X, Y, val); } if (ICallBack != null) { Prog = (int)(Y * 100 / nY); if (Prog > OldProg) { MapWinUtility.Logger.Progress("Difference..." + Prog.ToString() + "% Complete", Prog, OldProg); ICallBack.Progress("Status", Prog, "Difference..." + Prog.ToString() + "% Complete"); OldProg = Prog; } } } break; default: MapWinUtility.Logger.Progress("The Datatype was not a valid numeric type.", Prog, OldProg); throw new ArgumentException("The Datatype was not a valid numeric type."); } } else { for (int Y = 0; Y < nY; Y++) { float[] Vals1 = new float[nX]; float[] Vals2 = new float[nX]; float[] Diff = new float[nX]; Source1.GetRow(Y, ref Vals1[0]); Source2.GetRow(Y, ref Vals2[0]); for (int X = 0; X < nX; X++) { Diff[X] = Vals1[X] - Vals2[X]; } Dest.PutRow(Y, ref Diff[0]); if (ICallBack != null) { Prog = (int)(Y * 100 / nY); if (Prog > OldProg) { MapWinUtility.Logger.Progress("Difference..." + Prog.ToString() + "% Complete", Prog, OldProg); ICallBack.Progress("Status", Prog, "Difference..." + Prog.ToString() + "% Complete"); OldProg = Prog; } } } } MapWinUtility.Logger.Dbg("Finished Difference"); if (ICallBack != null) { ICallBack.Progress("Status", 0, "Done."); } }