Example #1
0
        public void GetPolygonsTest()
        {
            var m = new HydroNumerics.MikeSheTools.Core.Model(@"E:\dhi\data\dkm\dk2\result\DK2_v3_gvf_PT_100p_24hr.she");

            var precip = new HydroNumerics.MikeSheTools.DFS.DFS2(m.Input.MIKESHE_FLOWMODEL.Climate.PrecipitationRate.FULLY_DISTRIBUTED.DFS_2D_DATA_FILE.FILE_NAME);

            var actual = XYPolygon.GetPolygons(precip);

            System.Data.DataTable dt = new System.Data.DataTable();
            dt.Columns.Add("ID", typeof(int));

            int k = 0;

            using (HydroNumerics.Geometry.Shapes.ShapeWriter sw = new Geometry.Shapes.ShapeWriter(@"d:\temp\out.shp"))
            {
                for (int i = 0; i < precip.NumberOfColumns; i++)
                {
                    for (int j = 0; j < precip.NumberOfRows; j++)
                    {
                        var drow = dt.NewRow();
                        drow[0] = k;
                        sw.Write(new GeoRefData()
                        {
                            Geometry = actual[i, j], Data = drow
                        });
                        k++;
                    }
                }
            }
        }
Example #2
0
    /// <summary>
    /// Loads a MikeShe setup
    /// </summary>
    /// <param name="SheFile"></param>
    /// <param name="Start"></param>
    /// <param name="End"></param>
    public void LoadMikeSheData(string SheFile, DateTime Start, DateTime End)
    {
      LogThis("Loading Mike she model. FileName: " + SheFile);
      MikeSheTools.Core.Model m = new MikeSheTools.Core.Model(SheFile);

      LogThis("Distributing m11 detailed time series on catchments");
      var m11 = m.Results.Mike11Observations.Where(mm => mm.Simulation != null).ToList();
      foreach (var c in AllCatchments.Values)
      {
        //We find all the detailed timeseries that starts with the catchment ID.
        //If there are more than one they ar summed
        var flows = m11.Where(mm=>mm.Name.Substring(0, Math.Min(mm.Name.Length, c.ID.ToString().Length))== c.ID.ToString());
        List<double> flowdata=null;
        foreach(var flow in flows)
        {
          if (flowdata == null)
            flowdata = new List<double>(flow.Simulation.Items.Select(v => Math.Abs(v.Value))); //Careful we are now removing negative flows
          else
            for (int i = 0; i < flowdata.Count; i++)
              flowdata[i] += flow.Simulation.Items[i].Value;
        }
        if (flowdata != null)
        {
          c.M11Flow = new ZoomTimeSeries();
          c.M11Flow.GetTs(TimeStepUnit.Day).AddRange(flows.First().Simulation.StartTime, flowdata);
        }
      }
      LogThis(AllCatchments.Values.Count(c=>c.M11Flow!=null) + " catchments now have m11 flow");

      LogThis("Distributing precipitation");
      var precip = new HydroNumerics.MikeSheTools.DFS.DFS2(m.Input.MIKESHE_FLOWMODEL.Climate.PrecipitationRate.FULLY_DISTRIBUTED.DFS_2D_DATA_FILE.FILE_NAME);
      foreach (var c in GetValuesFromGrid(precip, AllCatchments.Values.Where(c => c.Precipitation == null).ToList(), true, Start, End))
      {
        AllCatchments[c.Key].Precipitation = new ZoomTimeSeries() { Accumulate = true };
        AllCatchments[c.Key].Precipitation.GetTs(TimeStepUnit.Month).AddRange(c.Value.StartTime, c.Value.Items.Select(t => t.Value));
      }
      precip.Dispose();

      LogThis(AllCatchments.Values.Count(c => c.Precipitation != null) + " catchments now have precipitation");

      LogThis("Distributing temperature");
      var temperature = new HydroNumerics.MikeSheTools.DFS.DFS2(m.Input.MIKESHE_FLOWMODEL.Climate.AirTemperature.FULLY_DISTRIBUTED.DFS_2D_DATA_FILE.FILE_NAME);
      foreach (var t in GetValuesFromGrid(temperature, AllCatchments.Values.Where(c => c.Temperature == null).ToList(), false, Start, End))
        AllCatchments[t.Key].Temperature = t.Value;
      temperature.Dispose();
      LogThis(AllCatchments.Values.Count(c => c.Temperature != null) + " catchments now have Temperature");


      m.Dispose();

      LogThis("Mike she model loaded");
    }