Ejemplo n.º 1
0
        /// <summary>
        /// Update DFS2 bathymetry, lowering bathymetry with 5.61 meters everywhere,
        /// taking land value into account.
        /// <para>
        /// The method assumes that the OresundBathy900.dfs2 test file
        /// (or preferably a copy of it) is the input file.
        /// </para>
        /// </summary>
        /// <param name="bathyFilename">Path and name of OresundBathy900.dfs2 test file</param>
        public static void ModifyDfs2Bathymetry(string bathyFilename)
        {
            // Open file
            Dfs2File dfs2 = DfsFileFactory.Dfs2FileOpenEdit(bathyFilename);

            // Second custom block (index 1) contains the M21_MISC values,
            // where the 4th (index 3) is the land value
            float landValue = (float)dfs2.FileInfo.CustomBlocks[1][3];

            // Read bathymetry data
            IDfsItemData2D <float> bathyData = (IDfsItemData2D <float>)dfs2.ReadItemTimeStepNext();

            // Modify bathymetry data
            for (int i = 0; i < bathyData.Data.Length; i++)
            {
                if (bathyData.Data[i] != landValue)
                {
                    bathyData.Data[i] -= 5.61f;
                }
            }

            // Write back bathymetry data
            dfs2.WriteItemTimeStep(1, 0, 0, bathyData.Data);
            dfs2.Close();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Example of how to update item information in a dfs2 file.
        /// <para>
        /// The method assumes that the Landuse.dfs2 test file
        /// (or preferably a copy of it) is the input file.
        /// </para>
        /// </summary>
        /// <param name="filename">Path and name of Landuse.dfs2 test file</param>
        public static void ModifyDfs2ItemInfo(string filename)
        {
            // Open the file for editing
            IDfs2File file = DfsFileFactory.Dfs2FileOpenEdit(filename);

            // Original name is "Landuse" (7 characters), "GroundUse" is truncated to "GroundU"
            file.ItemInfo[0].Name = "GroundUse";
            // Provide a new quantity (updating the item and unit of the quantity directly does not work!)
            file.ItemInfo[0].Quantity = new eumQuantity(eumItem.eumIAreaFraction, eumUnit.eumUPerCent);

            // done
            file.Close();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Example of how to update item axis in a dfs2 file.
        /// <para>
        /// The method assumes that the OresundHD.dfs2 test file
        /// (or preferably a copy of it) is the input file.
        /// </para>
        /// </summary>
        /// <param name="filename">Path and name of OresundHD.dfs2 test file</param>
        public static void ModifyDfs2ItemAxis(string filename)
        {
            Dfs2File file = DfsFileFactory.Dfs2FileOpenEdit(filename);

            IDfsAxisEqD2 axisEqD2 = ((IDfsAxisEqD2)file.SpatialAxis);

            axisEqD2.X0 = 55;
            axisEqD2.Dx = 905;
            axisEqD2.Y0 = -55;
            axisEqD2.Dy = 915;

            file.Close();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Example of how to modify data of a certain item and time
        /// step in a dfs2 file.
        /// <para>
        /// The method assumes that the Landuse.dfs2 test file
        /// (or preferably a copy of it) is the input file.
        /// </para>
        /// </summary>
        /// <param name="filename">Path and name of Landuse.dfs2 test file</param>
        public static void ModifyDfs2FileData(string filename)
        {
            // Open the file for editing
            IDfs2File file = DfsFileFactory.Dfs2FileOpenEdit(filename);

            // Load and modify data from the first item and timestep
            IDfsItemData2D data2D = file.ReadItemTimeStepNext();

            data2D[21, 61] = 7f;
            data2D[21, 62] = 6f;
            data2D[21, 63] = 5f;
            data2D[21, 64] = 4f;
            data2D[21, 65] = 3f;

            // Write modified data back
            file.WriteItemTimeStep(1, 0, data2D.Time, data2D.Data);

            // done
            file.Close();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            string filename = @"Landuse2.dfs2";

            // Copy existing file to new name, in order to not mess up existing file
            System.IO.File.Copy(@"..\..\TestData\Landuse.dfs2", filename, true);
            System.IO.File.SetAttributes(filename, System.IO.FileAttributes.Normal); // remove read-only flag

            // Open the file for editing
            IDfs2File file = DfsFileFactory.Dfs2FileOpenEdit(filename);

            // Original name is "Landuse" (7 characters), "GroundUse" is truncated to "GroundU"
            file.ItemInfo[0].Name = "GroundUse";
            // Provide a new quantity (updating the item and unit of the quantity directly is not allowed!)
            file.ItemInfo[0].Quantity = new eumQuantity(eumItem.eumIAreaFraction, eumUnit.eumUPerCent);

            // done
            file.Close();

            Console.Out.WriteLine("Updated " + filename + " - remember to delete the file again");
        }