public void WritePointShapeTest()
    {
      string File = @"..\..\..\TestData\WriteTest.Shp";

      ShapeWriter PSW = new ShapeWriter(File);

      PSW.WritePointShape(10, 20);
      PSW.WritePointShape(20, 30);
      PSW.WritePointShape(30, 40);

      DataTable DT = new DataTable();
      DT.Columns.Add("Name", typeof(string));
      DT.Rows.Add(new object[] { "point1" });
      DT.Rows.Add(new object[] { "point2" });
      DT.Rows.Add(new object[] { "point3" });

      PSW.Data.WriteDate(DT);
      PSW.Dispose();


      ShapeReader PSR = new ShapeReader(File);

      IXYPoint p;
      DataTable DTread = PSR.Data.Read();
      int i = 0;
      foreach (DataRow dr in DTread.Rows)
      {
        Console.WriteLine(dr[0].ToString());
        p = (IXYPoint)PSR.ReadNext(i);
        Console.WriteLine(p.X.ToString() + "   " + p.Y.ToString());
        i++;

      }
    }
 public void ReadNextTest2()
 {
   string File = @"..\..\..\..\MikeSheTools\TestData\CommandAreas.Shp";
   ShapeReader target = new ShapeReader(File);
   var geo = target.ReadNext();
   double d =((XYPolygon)geo).GetArea();
   Assert.IsTrue(0 < d);
 }
    public void TestMethod1()
    {
      string File = TestDataPath + @"CommandAreas.Shp";
      ShapeReader target = new ShapeReader(File);
      var geo = target.ReadNext(0);
      double d = ((XYPolygon)geo).GetArea();
      Assert.IsTrue(0 < d);

    }
Esempio n. 4
0
    public void TestMethod1()
    {
      Dictionary<int, int> dmuTOId15 = new Dictionary<int, int>();
      using (StreamReader sr = new StreamReader(@"D:\DK_information\Overfladevand\stationer\maol.txt"))
      {
        sr.ReadLine();
        while (!sr.EndOfStream)
        {
          var data = sr.ReadLine().Split(new string[] { "\t" }, StringSplitOptions.None);

          dmuTOId15.Add(int.Parse(data[1]), int.Parse(data[3]));

        }

      }
      using (ShapeWriter sw = new ShapeWriter(@"D:\DK_information\Overfladevand\stationer\stationer2.shp"))
      {
      using (ShapeReader sh = new ShapeReader(@"D:\DK_information\Overfladevand\stationer\stationer.shp"))
      {
        var dt = sh.Data.Read();
        dt.Columns.Add("ID15", typeof(int));
        for(int i =0;i< dt.Rows.Count;i++)
        {

          int dmunr = int.Parse(dt.Rows[i][0].ToString());

          int id15;
          if(dmuTOId15.TryGetValue(dmunr, out id15))
          {
            dt.Rows[i]["ID15"] = id15;
          }

          sw.Write(new Geometry.GeoRefData() { Geometry = sh.ReadNext(i), Data = dt.Rows[i] });


        }
      }
    }

    }
Esempio n. 5
0
    public void LoadStationData(SafeFile ShapeFileName, string StationData, DateTime Start, DateTime End)
    {

      StateVariables.ClearColumnValues("ObservedFlow");
      StateVariables.ClearColumnValues("ObservedNitrate");


      Dictionary<int, DMUStation> locatedStations = new Dictionary<int,DMUStation>();
      List<DMUStation> stations = new List<DMUStation>();
      LogThis("Reading stations from " + ShapeFileName.FileName);
      using (ShapeReader sr = new ShapeReader(ShapeFileName.FileName))
      {
        for (int i = 0; i < sr.Data.NoOfEntries; i++)
        {
          DMUStation dm = new DMUStation();
          dm.Location = sr.ReadNext(i) as XYPoint;
          dm.ID = sr.Data.ReadInt(i, ShapeFileName.ColumnNames[0]);
          dm.ODANummer = sr.Data.ReadInt(i, ShapeFileName.ColumnNames[1]);
          stations.Add(dm);
          if(dm.ODANummer!=0)
            locatedStations.Add(dm.ODANummer, dm);
          int id = sr.Data.ReadInt(i, ShapeFileName.ColumnNames[2]);
          if (id != 0 & AllCatchments.ContainsKey(id))
          {
            if (AllCatchments[id].Measurements != null)
            {
              int m = 0;
            }
            AllCatchments[id].Measurements = dm;
          }
        }
      }
      LogThis(stations.Count + " stations read. " + locatedStations.Count + " within catchments distributed on " + AllCatchments.Values.Count(ca => ca.Measurements != null) +" catchments.");

      using (StreamReader sr = new StreamReader(StationData))
      {
        sr.ReadLine();//HeadLine
        while (!sr.EndOfStream)
        {
          var data = sr.ReadLine().Split(';');
          DMUStation  station;

          if (locatedStations.TryGetValue(int.Parse(data[0]), out station))
          {
            var time = new DateTime(int.Parse(data[2]), int.Parse(data[3]), 1);
            if (time >= Start & time <= End)
            {
              station.Nitrate.Items.Add(new TimeStampValue(time, double.Parse(data[4])));
              station.Flow.Items.Add(new TimeStampValue(time, double.Parse(data[5]) * 1000));
            }
          }
        }
      }
    }
    public override void Initialize(DateTime Start, DateTime End, IEnumerable<Catchment> Catchments)
    {

      base.Initialize(Start, End, Catchments);
      Dictionary<XYPoint, List<double>> Data = new Dictionary<XYPoint,List<double>>();

      XSSFWorkbook hssfwb;
      using (FileStream file = new FileStream(ExcelFile.FileName, FileMode.Open, FileAccess.Read))
      {
        hssfwb = new XSSFWorkbook(file);
      }


      List<IRow> DataRows = new List<IRow>();
      var sheet = hssfwb.GetSheet("Ndep_Tot");
      for (int row = 1; row <= sheet.LastRowNum; row++)
      {
        if (sheet.GetRow(row) != null) //null is when the row only contains empty cells 
        {
          DataRows.Add(sheet.GetRow(row));
        }
      }


      using (ShapeReader sr = new ShapeReader(Shapefile.FileName))
      {
        FirstYear = (int)DataRows.First().Cells[0].NumericCellValue;
        for (int i = 0; i < sr.Data.NoOfEntries; i++)
        {
          int icoor = sr.Data.ReadInt(i, "i");
          int jcoor = sr.Data.ReadInt(i, "j");

          XYPoint point = (XYPoint)sr.ReadNext(i);
          
          //Create the timestampseries and set unit to kg/m2/s;
          var data = DataRows.Where(v => (int)v.Cells[3].NumericCellValue == icoor & (int)v.Cells[4].NumericCellValue == jcoor).OrderBy(v => (int)v.Cells[0].NumericCellValue).Select(v => v.Cells[6].NumericCellValue / (365.0 * 86400.0 * 1.0e6)).ToList();


          if(data.Count()>0)
            Data.Add(point, data);

        }
      }


      foreach (var c in Catchments)
      {
        XYPolygon poly = null;

        if (c.Geometry is XYPolygon)
          poly = c.Geometry as XYPolygon;
        else if (c.Geometry is MultiPartPolygon)
          poly = ((MultiPartPolygon)c.Geometry).Polygons.First(); //Just use the first polygon

        double LakeArea = c.Lakes.Sum(l => l.Geometry.GetArea()); //Get the area of the lakes
        if (c.BigLake != null) //Add the big lake
          LakeArea += c.BigLake.Geometry.GetArea();
        
        if (poly != null)
        {
          var point = new XYPoint(poly.PlotPoints.First().Longitude, poly.PlotPoints.First().Latitude); //Take one point in the polygon
          var closestpoint = Data.Keys.Select(p => new Tuple<XYPoint, double>(p, p.GetDistance(point))).OrderBy(s => s.Item2).First().Item1;
          deposition.Add(c.ID, new List<double>(Data[closestpoint].Select(v=>v*LakeArea)));
        }

      }
      NewMessage("Initialized");
      



    }