public void InitializeTest()
    {
      ID15Reader catchme = new ID15Reader(); 
      catchme.LoadCatchments(@"D:\DK_information\TestData\FileStructure\id15_NSTmodel.shp");


      AtmosphericDeposition target = new AtmosphericDeposition(); 
      DateTime Start = new DateTime(); 
      DateTime End = new DateTime();
      target.Shapefile = new SafeFile() { FileName = @"D:\DK_information\TestData\FileStructure\Ndeposition\EMEP_centroid_DK.shp" };
      target.ExcelFile = new SafeFile() { FileName = @"D:\DK_information\TestData\FileStructure\Ndeposition\EMEP_Ndep_1990_2013.xlsx" };
      target.Initialize(Start, End, catchme.AllCatchments.Values);

      //TODO: Add precipitation for this to work

      Assert.AreEqual(0.0144132844, target.GetValue(catchme.AllCatchments.Values.First(), new DateTime(1990, 5, 1)),1e-6);
    }
Пример #2
0
    static void Main(string[] args)
    {

      if(args.Count()<2)
      {
        Console.WriteLine("Usage: CatchmentConnector <ID15-catchments shapefile> <Station shapefile>");
        return;
      }

      string CatchmentFilename = Path.GetFullPath(args[0]);

      string FilePath = Path.GetDirectoryName(CatchmentFilename);

      ID15Reader m = new ID15Reader();
      m.LoadCatchments(CatchmentFilename);

      Dictionary<int, Catchment> StationCatchment = new Dictionary<int, Catchment>();


      string outpufilen = Path.Combine(FilePath, "output2.shp");

      if (args.Count() == 3)
        outpufilen = args[2];

      using (ShapeReader sr = new ShapeReader(args[1]))
      {
        foreach (var station in sr.GeoData)
        {
          int stationid = (int)station.Data["DMUstnr"];

          int catchid = (int)station.Data["ID15_NEW"];

          Catchment c;

          if (!m.AllCatchments.TryGetValue(catchid, out c))
          {
            Console.WriteLine("Catchment with ID: " + catchid + " not found");

          }
          else
          {
            StationCatchment.Add(stationid, c);
            c.Measurements = new DMUStation() { ID = stationid };
          }
        }


        using (ShapeWriter sw = new ShapeWriter(outpufilen) { Projection = sr.Projection })
        {

          DataTable dt = new DataTable();
          dt.Columns.Add("DMUstnr", typeof(int));
          dt.Columns.Add("ID15_NEW", typeof(int));
          dt.Columns.Add("TotalArea", typeof(double));
          dt.Columns.Add("Area", typeof(double));
          dt.Columns.Add("To_DMUstnr", typeof(int));

          foreach (var c in StationCatchment)
          {
            var row = dt.NewRow();
            row[0] = c.Key;
            row[1] = c.Value.ID;
            var upstream = m.GetUpstreamCatchments(c.Value).ToList();

            row[2] = upstream.Sum(cu => cu.Geometry.GetArea());

            var toremove = upstream.Where(cu => cu.ID != c.Value.ID & cu.Measurements != null).SelectMany(cu => m.GetUpstreamCatchments(cu)).Distinct().ToList();

            foreach (var cu in toremove)
              upstream.Remove(cu);

            row[3] = upstream.Sum(cu => cu.Geometry.GetArea());

            IXYPolygon geom;
            if (upstream.Count > 1)
              geom = HydroNumerics.Geometry.ClipperTools.Union(upstream.Select(g => g.Geometry).Cast<IXYPolygon>().ToList());
            else
              geom = upstream.First().Geometry;

            var ds = m.GetDownStreamCatchments(c.Value);
            ds.Remove(c.Value);
            var dsc = ds.FirstOrDefault(dc => dc.Measurements != null);

            if (dsc != null)
              row[4] = dsc.Measurements.ID;

            sw.Write(new HydroNumerics.Geometry.GeoRefData() { Geometry = geom, Data = row });

          }

        }
      }

      Console.WriteLine("Done! Hit enter to exit.");
      Console.Read();
    }