Example #1
0
    public void Open()
    {
      Connection c = Connection.Create(@"..\..\..\testdata\mike11\novomr6.xns11");

      CrossSectionDataFactory cd = new CrossSectionDataFactory();

      var xsecs = cd.Open(@"..\..\..\testdata\mike11\novomr6.xns11", null);
      

      CrossSectionFactory cf = new CrossSectionFactory();
      var v= new CrossSectionPointList();
      v.Add(new CrossSectionPoint(0,5));
      v.Add(new CrossSectionPoint(1,2));
      v.Add(new CrossSectionPoint(2,2));
      v.Add(new CrossSectionPoint(3,5));

      cf.BuildOpen("tempo");
      cf.SetRawPoints(v);
      
      var cs = cf.GetCrossSection();

      CrossSectionData d = new CrossSectionData();
      d.Add(cs);
      d.Connection = Connection.Create(@"c:\temp\new.xns11");
      


      
     
      CrossSectionFactory cdd = new CrossSectionFactory();
     
     
    }
Example #2
0
        public void Open()
        {
            Connection c = Connection.Create(@"..\..\..\testdata\mike11\novomr6.xns11");

            CrossSectionDataFactory cd = new CrossSectionDataFactory();

            var xsecs = cd.Open(@"..\..\..\testdata\mike11\novomr6.xns11", null);


            CrossSectionFactory cf = new CrossSectionFactory();
            var v = new CrossSectionPointList();

            v.Add(new CrossSectionPoint(0, 5));
            v.Add(new CrossSectionPoint(1, 2));
            v.Add(new CrossSectionPoint(2, 2));
            v.Add(new CrossSectionPoint(3, 5));

            cf.BuildOpen("tempo");
            cf.SetRawPoints(v);

            var cs = cf.GetCrossSection();

            CrossSectionData d = new CrossSectionData();

            d.Add(cs);
            d.Connection = Connection.Create(@"c:\temp\new.xns11");



            CrossSectionFactory cdd = new CrossSectionFactory();
        }
Example #3
0
        public void Save()
        {
            if (xsecs != null)
            {
                CrossSectionDataFactory.Save(xsecs);
            }

            HasChanges = false;
        }
Example #4
0
        /// <summary>
        /// Load an xns11 file, add a cross section and save the file again,
        /// adding a "-csModPro" to the end of the filename.
        /// </summary>
        /// <param name="xns11Filepath">Filepath to xns11 file from the CrossSection example data</param>
        public static void ModifyCrossSectionProcessedAndSave(string xns11Filepath)
        {
            // Load cross section data
            Diagnostics             diagnostics   = new Diagnostics("Errors");
            CrossSectionDataFactory csDataFactory = new CrossSectionDataFactory();
            CrossSectionData        csData        = csDataFactory.Open(Connection.Create(xns11Filepath), diagnostics);

            // Modify cross section
            ModifyCrossSectionProcessed(csData);

            // Save the cross section as a new file name
            csData.Connection.FilePath.FileNameWithoutExtension += "-csModPro";
            CrossSectionDataFactory.Save(csData);
        }
        /// <summary>
        /// Example of how to load an xns11 file, add a cross section and save the
        /// file again, adding a "-csAdd" to the end of the new filename.
        /// </summary>
        /// <param name="xns11Filepath">Filepath to xns11 file</param>
        public static void AddCrossSectionAndSave(string xns11Filepath)
        {
            // Load cross section data
            Diagnostics             diagnostics   = new Diagnostics("Errors");
            CrossSectionDataFactory csDataFactory = new CrossSectionDataFactory();
            CrossSectionData        csData        = csDataFactory.Open(Connection.Create(xns11Filepath), diagnostics);

            // Add cross section
            CreateAndAddOpenCrossSection(csData);
            CreateAndAddCircularCrossSection(csData);

            // Save the cross section as a new file name
            csData.Connection.FilePath.FileNameWithoutExtension += "-csAdd";
            CrossSectionDataFactory.Save(csData);
        }
        public void CrossSectionExamplesLoopAllCrossSections()
        {
            string xns11Filepath = Path.Combine(ExampleBase.ExampleRoot, @"CrossSection\CrossSections.xns11");

            // Load cross section data
            Diagnostics             diagnostics   = new Diagnostics("Errors");
            CrossSectionDataFactory csDataFactory = new CrossSectionDataFactory();
            CrossSectionData        csData        = csDataFactory.Open(Connection.Create(xns11Filepath), diagnostics);

            // Loop over all cross sections
            CrossSectionExamples.LoopAllCrossSections(csData);

            // Save the cross section as a new file name
            csData.Connection.FilePath.FileNameWithoutExtension += "-csLoop";
            CrossSectionDataFactory.Save(csData);
        }
Example #7
0
        /// <summary>
        /// Example of how to navigate and find cross sections.
        /// <para>
        /// There are two ways to get cross sections: Find or Get
        /// </para>
        /// <para>
        /// Find will search the cross section data object for a cross
        /// section at the specified location. If no cross section is
        /// found, null is returned.
        /// </para>
        /// <para>
        /// Get will search the cross section data object for a cross
        /// section at the specified location. If no cross section is
        /// found, it will interpolate/extrapolate if possible, and only
        /// if that interpolation/extrapolation is not possible, null
        /// is returned. The get methods are used by the engine.
        /// </para>
        /// <para>
        /// Users that want to update or in other ways process the cross
        /// sections should always use the Find methods.
        /// </para>
        /// </summary>
        /// <param name="xns11Filepath">Filepath to xns11 file</param>
        public static void Navigation(string xns11Filepath)
        {
            // Load cross section data
            Diagnostics             diagnostics   = new Diagnostics("Errors");
            CrossSectionDataFactory csDataFactory = new CrossSectionDataFactory();
            CrossSectionData        csData        = csDataFactory.Open(Connection.Create(xns11Filepath), diagnostics);

            ICrossSection crossSection;

            // Find a cross section on a given location
            crossSection = csData.FindCrossSection(new Location("LINDSKOV", 1370), "TOPO-95");
            if (crossSection == null)
            {
                throw new Exception("Could not find cross section at location");
            }

            // Find a cross section closest to a given location
            crossSection = csData.FindClosestCrossSection(new Location("LINDSKOV", 1250), "TOPO-95");
            if (crossSection == null || crossSection.Location.Chainage != 1172)
            {
                throw new Exception("Expected cross section at chainage 1172");
            }

            // Find all cross sections inside a given location span
            IList <ICrossSection> css = csData.FindCrossSectionsForLocationSpan(new LocationSpan("LINDSKOV", 1000, 2000), "TOPO-95", true);

            if (css.Count != 6)
            {
                throw new Exception("Expected 6 cross sections");
            }

            // Find cross sections that are neighbours to a given locatin.
            ICrossSection csAfter;
            ICrossSection csBefore;

            csData.FindNeighborCrossSections(new Location("LINDSKOV", 1250), "TOPO-95", true, out csBefore, out csAfter);
            if (csBefore == null || csBefore.Location.Chainage != 1172)
            {
                throw new Exception("Expected cross section at chainage 1172");
            }
            if (csAfter == null || csAfter.Location.Chainage != 1370)
            {
                throw new Exception("Expected cross section at chainage 1370");
            }
        }
        /// <summary>
        /// Export from xns11 to text file
        /// </summary>
        public static void Export(string xns11FileName, string txtFileName)
        {
            // Open cross section file
            CrossSectionDataFactory crossSectionDataFactory = new CrossSectionDataFactory();
            CrossSectionData        csData = crossSectionDataFactory.Open(Connection.Create(xns11FileName), null);

            // Open text file to write to
            StreamWriter writer = new StreamWriter(txtFileName);

            // Loop over all cross sections
            foreach (ICrossSection crossSection in csData)
            {
                // Export only those with raw data.
                // Any other filtering can be added here.
                if (!(crossSection.BaseCrossSection is XSBaseRaw))
                {
                    continue;
                }

                XSBaseRaw xsBase = crossSection.BaseCrossSection as XSBaseRaw;

                // Write cross section info-line.
                // First value in inf- line is a "what-to-do when importing" flag.
                // 0: Do nothing
                // 1: Update existing/create new if not existing
                writer.WriteLine("{0},{1},{2},{3},{4},{5}",
                                 "1",
                                 crossSection.Location.ID.EnQuote(),
                                 crossSection.Location.Chainage.ToString("R", CultureInfo.InvariantCulture),
                                 crossSection.TopoID.EnQuote(),
                                 crossSection.Location.Z.ToString("R", CultureInfo.InvariantCulture),
                                 xsBase.Points.Count);

                // Write coordinates of all raw points
                for (int i = 0; i < xsBase.Points.Count; i++)
                {
                    ICrossSectionPoint p = xsBase.Points[i];
                    writer.WriteLine("{0},{1}",
                                     p.X.ToString("R", CultureInfo.InvariantCulture),
                                     p.Z.ToString("R", CultureInfo.InvariantCulture));
                }
            }
            writer.Close();
        }
Example #9
0
        /// <summary>
        /// Reads the cross sections from an .xns-file
        /// </summary>
        /// <param name="xnsFile"></param>
        public void ReadCrossSections(string xnsFile)
        {
            CrossSectionDataFactory cd = new CrossSectionDataFactory();

            xsecs = cd.Open(xnsFile, null);


            //Now loop the cross sections
            foreach (var cs in xsecs)
            {
                XSOpen Opencs = cs.BaseCrossSection as XSOpen;
                if (Opencs != null)
                {
                    //Create a HydroNumerics.MikeSheTools.Mike11.CrossSection from the M11-CrossSection
                    CrossSection MyCs = new CrossSection(cs);

                    CombineNetworkAndCrossSections(MyCs);
                }
            }
        }
Example #10
0
    /// <summary>
    /// Reads the cross sections from an .xns-file
    /// </summary>
    /// <param name="xnsFile"></param>
    public void ReadCrossSections(string xnsFile)
    {
      CrossSectionDataFactory cd = new CrossSectionDataFactory();
      xsecs = cd.Open(xnsFile, null);
      
     
      //Now loop the cross sections
      foreach (var cs in xsecs)
      {
        XSOpen Opencs = cs.BaseCrossSection as XSOpen;
        if (Opencs != null)
        {
          //Create a HydroNumerics.MikeSheTools.Mike11.CrossSection from the M11-CrossSection
          CrossSection MyCs = new CrossSection(cs);

          CombineNetworkAndCrossSections(MyCs);
        }
      }
    }
        /// <summary>
        /// Import from text file to xns11 file
        /// </summary>
        /// <param name="txtFileName">Path and name of text file to import</param>
        /// <param name="xns11FileName">Path and name of xns11 file to create or update</param>
        /// <param name="xns11NewFileName">Path and name of xns11 file to write to</param>
        public static void Import(string txtFileName, string xns11FileName, string xns11NewFileName = null)
        {
            StreamReader reader = new StreamReader(txtFileName);

            CrossSectionDataFactory crossSectionDataFactory = new CrossSectionDataFactory();
            CrossSectionData        csData;

            if (File.Exists(xns11FileName))
            {
                csData = crossSectionDataFactory.Open(Connection.Create(xns11FileName), null);
            }
            else
            {
                csData = new CrossSectionData();
            }
            if (string.IsNullOrEmpty(xns11NewFileName))
            {
                xns11NewFileName = xns11FileName;
            }

            string line;

            // Read cross section info-line
            while ((line = reader.ReadLine()) != null)
            {
                // Split cross section info-line
                string[] split = line.SplitQuoted(',', '"');

                // extract info from info-line
                Location location     = new Location(split[1], double.Parse(split[2], CultureInfo.InvariantCulture));
                string   topoId       = split[3];
                double   datum        = double.Parse(split[4], CultureInfo.InvariantCulture);
                int      numRawPoints = int.Parse(split[5]);

                // Check if this cross section is to be processed
                if (split[0] == "1")
                {
                    ICrossSection cs = csData.FindCrossSection(location, topoId);

                    CrossSectionPointList points = new CrossSectionPointList();

                    // Read raw points
                    for (int i = 0; i < numRawPoints; i++)
                    {
                        line = reader.ReadLine();
                        if (line == null) // end-of-file
                        {
                            throw new EndOfStreamException("File ended prematurely");
                        }

                        string[] coords = line.Split(',');

                        double x = double.Parse(coords[0], CultureInfo.InvariantCulture);
                        double z = double.Parse(coords[1], CultureInfo.InvariantCulture);
                        points.Add(new CrossSectionPoint(x, z));
                    }

                    // Check if cross section already exists
                    if (cs != null)
                    {
                        // Check if it is a cross section with raw points
                        XSBaseRaw xsBaseRaw = cs.BaseCrossSection as XSBaseRaw;
                        if (xsBaseRaw == null)
                        {
                            throw new Exception("Cannot modify raw points of a cross section without raw points: " + location.ToString() + ", " + topoId);
                        }

                        // replace datum (in case datum changes)
                        cs.Location.Z = datum;
                        // Replace points
                        xsBaseRaw.Points = points;
                        // Set default markers
                        xsBaseRaw.UpdateMarkersToDefaults(true, true, true);
                        // Recalculate processed data
                        xsBaseRaw.ProcessingLevelsSpecs.NoOfLevels = 50;
                        xsBaseRaw.CalculateProcessedData();
                    }
                    else
                    {
                        // Create a new cross section
                        CrossSectionFactory builder = new CrossSectionFactory();
                        builder.BuildOpen("");

                        // Defines the location of the current cross section. The Z-coordinate
                        // for an open cross section with raw data is a Z-offset, and usually zero.
                        builder.SetLocation(new ZLocation(location.ID, location.Chainage)
                        {
                            Z = datum
                        });

                        // Set raw points and default markers
                        builder.SetRawPoints(points);
                        builder.SetDefaultMarkers();

                        // Define resistance properties as relative
                        FlowResistance flowResistance = new FlowResistance();
                        flowResistance.Formulation            = ResistanceFormulation.Relative;
                        flowResistance.ResistanceDistribution = ResistanceDistribution.Uniform;
                        flowResistance.ResistanceValue        = 1;
                        builder.SetFlowResistance(flowResistance);
                        builder.SetRadiusType(RadiusType.ResistanceRadius);

                        // Get the cross section
                        CrossSectionLocated csLocated = builder.GetCrossSection();
                        // Set topo-id
                        csLocated.TopoID = topoId;

                        // now, calculate processed data
                        csLocated.BaseCrossSection.ProcessingLevelsSpecs.Option     = ProcessingOption.AutomaticLevels;
                        csLocated.BaseCrossSection.ProcessingLevelsSpecs.NoOfLevels = 0;
                        csLocated.BaseCrossSection.CalculateProcessedData();

                        // Store cross section in database
                        csData.Add(csLocated);
                    }
                }
                else // this cross section should not be processed
                {
                    // Skip line containing raw points
                    for (int i = 0; i < numRawPoints; i++)
                    {
                        line = reader.ReadLine();
                        if (line == null) // end-of-file
                        {
                            throw new EndOfStreamException("File ended prematurely");
                        }
                    }
                }
            }
            csData.Connection = Connection.Create(xns11NewFileName);
            CrossSectionDataFactory.Save(csData);
        }