Ejemplo n.º 1
0
        /// <summary>
        /// This function copies a two dimensional array of float values to the appropriate space in the grid.
        /// </summary>
        /// <param name="OutputArray">The two dimensional array of floats to save to the grid</param>
        /// <param name="mwGrid">The MapWinGIS.grid to save the float values to</param>
        /// <param name="ICallBack">A MapWinGIS.ICallback for status messages</param>
        public void SaveArrayToWindow(float[][] OutputArray, MapWinGIS.Grid mwGrid, MapWinGIS.ICallback ICallBack)
        {
            // Write values to the grid
            int numCols = this.Rectangle.Width;
            int numRows = this.Rectangle.Height;

            float[] Temp = new float[numCols * numRows];
            //Organize the OutputArray into a single window
            if (ICallBack != null)
            {
                ICallBack.Progress("Status", 0, "Copying value to 1-D array.");
            }
            for (int row = 0; row < numRows; row++)
            {
                for (int col = 0; col < numCols; col++)
                {
                    Temp[numCols * row + col] = OutputArray[row][col];
                }
            }
            if (ICallBack != null)
            {
                ICallBack.Progress("Status", 0, "Saving window to grid");
            }
            mwGrid.PutFloatWindow(this.Rectangle.Y, this.Rectangle.Bottom - 1, this.Rectangle.X, this.Rectangle.Right - 1, ref Temp[0]);
            return;
        }
Ejemplo 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);
        }