Esempio n. 1
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. 2
0
        }//End Write_Vertical

        #endregion

        #region Array - Grid Handling

        /// <summary>
        /// Converts a region of a grid into a 2D array of float values
        /// </summary>
        /// <param name="mwSourceGrid">The grid to read</param>
        /// <param name="ICallBack">A MapWinGIS.ICallback for status messages</param>
        /// <returns>float[][] the values from the grid</returns>
        public float[][] GetArrayFromWindow(MapWinGIS.Grid mwSourceGrid, MapWinGIS.ICallback ICallBack)
        {
            if (mwSourceGrid == null)
            {
                if (ICallBack != null)
                {
                    ICallBack.Error("Error", "SourceGrid cannot be null.");
                }
                throw new ArgumentException("SourceGrid cannot be null.");
            }

            int numRows = this.Rectangle.Height;
            int numCols = this.Rectangle.Width;

            // Populate the Array by directly reading values from the grid
            float[][] SourceArray = new float[numRows][];
            float[]   Temp        = new float[numRows * numCols];

            // Read from the ocx once, rather than calling several times
            if (ICallBack != null)
            {
                ICallBack.Progress("Status", 0, " Loading Values");
            }
            mwSourceGrid.GetFloatWindow(this.Rectangle.Y, this.Rectangle.Bottom - 1, this.Rectangle.X, this.Rectangle.Right - 1, ref Temp[0]);
            if (ICallBack != null)
            {
                ICallBack.Progress("Status", 0, "Copying Values");
            }
            for (int row = 0; row < numRows; row++)
            {
                SourceArray[row] = new float[numCols];
                //
                for (int col = 0; col < numCols; col++)
                {
                    // copy the values into a 2D style array because it improves
                    // handling speeds for some reason
                    SourceArray[row][col] = Temp[row * numCols + col];
                }
            }
            if (ICallBack != null)
            {
                ICallBack.Progress("Status", 0, "Finished copying values from grid.");
            }
            return(SourceArray);
        }// End GetArrayFromWindow
Esempio n. 3
0
        }// End GetArrayFromWindow

        /// <summary>
        /// Returns jagged array where the borders are read from the destination file but the central
        /// portion is set to be the maximum float value.
        /// </summary>
        /// <param name="mwSourceGrid">A MapWinGIS.Grid to read the frame borders that are on the very outside of the image</param>
        /// <param name="mwDestGrid">A MapWinGIS.Grid to read the frame borders on the interior edges already processed </param>
        /// <param name="ICallBack">A MapWinGIS.ICallback for messages (optional)</param>
        /// <returns>A float[][] array representing the destination values for an entire frame</returns>
        public float[][] GetBorders(MapWinGIS.Grid mwSourceGrid, MapWinGIS.Grid mwDestGrid, MapWinGIS.ICallback ICallBack)
        {
            if (mwSourceGrid == null || mwDestGrid == null)
            {
                if (ICallBack != null)
                {
                    ICallBack.Error("Error", "SourceGrid cannot be null.");
                }
                throw new ArgumentException("SourceGrid cannot be null.");
            }

            int numRows = this.Rectangle.Height;
            int numCols = this.Rectangle.Width;

            // Populate the Array by directly reading values from the grid
            float[][] SourceArray = new float[numRows][];


            // Read from the ocx once, rather than calling several times



            // Initialize the array to max values
            for (int row = 0; row < numRows; row++)
            {
                SourceArray[row] = new float[numCols];
                for (int col = 0; col < numCols; col++)
                {
                    SourceArray[row][col] = float.MaxValue;
                }
            }

            // If we need a dependency in a given direction, read it from the file.
            if (Y == 0)
            {
                mwSourceGrid.GetFloatWindow(this.Rectangle.Y, this.Rectangle.Y, this.Rectangle.X, this.Rectangle.Right - 1, ref SourceArray[0][0]);
            }
            else if (Parent.First_Time(X, Y - 1) == false)
            {
                mwDestGrid.GetFloatWindow(this.Rectangle.Y, this.Rectangle.Y, this.Rectangle.X, this.Rectangle.Right - 1, ref SourceArray[0][0]);
            }

            if (Y == Parent.NumFramesTall - 1)
            {
                mwSourceGrid.GetFloatWindow(this.Rectangle.Bottom - 1, this.Rectangle.Bottom - 1, this.Rectangle.X, this.Rectangle.Right - 1, ref SourceArray[numRows - 1][0]);
            }
            else if (Parent.First_Time(X, Y + 1) == false)
            {
                mwDestGrid.GetFloatWindow(this.Rectangle.Bottom - 1, this.Rectangle.Bottom - 1, this.Rectangle.X, this.Rectangle.Right - 1, ref SourceArray[numRows - 1][0]);
            }

            if (X == 0)
            {
                float[] Temp = new float[numRows];
                mwSourceGrid.GetFloatWindow(this.Rectangle.Y, this.Rectangle.Bottom - 1, this.Rectangle.X, this.Rectangle.X, ref Temp[0]);
                for (int row = 0; row < numRows; row++)
                {
                    SourceArray[row][0] = Temp[row];
                }
            }
            else if (Parent.First_Time(X - 1, Y) == false)
            {
                float[] Temp = new float[numRows];
                mwDestGrid.GetFloatWindow(this.Rectangle.Y, this.Rectangle.Bottom - 1, this.Rectangle.X, this.Rectangle.X, ref Temp[0]);
                for (int row = 0; row < numRows; row++)
                {
                    SourceArray[row][0] = Temp[row];
                }
            }

            if (X == Parent.NumFramesWide - 1)
            {
                float[] Temp = new float[numRows];
                mwSourceGrid.GetFloatWindow(this.Rectangle.Y, this.Rectangle.Bottom - 1, this.Rectangle.Right - 1, this.Rectangle.Right - 1, ref Temp[0]);
                for (int row = 0; row < numRows; row++)
                {
                    SourceArray[row][numCols - 1] = Temp[row];
                }
            }
            else if (Parent.First_Time(X + 1, Y) == false)
            {
                float[] Temp = new float[numRows];
                mwDestGrid.GetFloatWindow(this.Rectangle.Y, this.Rectangle.Bottom - 1, this.Rectangle.Right - 1, this.Rectangle.Right - 1, ref Temp[0]);
                for (int row = 0; row < numRows; row++)
                {
                    SourceArray[row][numCols - 1] = Temp[row];
                }
            }
            if (ICallBack != null)
            {
                ICallBack.Progress("Status", 0, "Finished copying values from grid.");
            }
            return(SourceArray);
        }