public void GetLength()
		{
			XYPolyline xyPolyline = new XYPolyline();
			xyPolyline.Points.Add(new XYPoint(6,2));
			xyPolyline.Points.Add(new XYPoint(2,2));
			xyPolyline.Points.Add(new XYPoint(8,2));
			xyPolyline.Points.Add(new XYPoint(8,4));
			xyPolyline.Points.Add(new XYPoint(5,4));
			xyPolyline.Points.Add(new XYPoint(9,7));
			
			Assert.AreEqual((double) 20, xyPolyline.GetLength()); 
		}
Example #2
0
    public void SaveToShape(string ShapeFileName)
    {
      using (ShapeWriter sw = new ShapeWriter(ShapeFileName))
      {
        DataTable dt = new DataTable();
        dt.Columns.Add("LinkID", typeof(string));
        dt.Columns.Add("FromNode", typeof(string));
        dt.Columns.Add("ToNode", typeof(string));
        dt.Columns.Add("SpecifiedLength", typeof(double));

        foreach (var b in Links.Values)
        {
          GeoRefData grf = new GeoRefData();
          var l = new XYPolyline();
          l.Points.Add(new XYPoint(b.UpstreamNode.pfsnode.X, b.UpstreamNode.pfsnode.Y));
          l.Points.Add(new XYPoint(b.DownstreamNode.pfsnode.X, b.DownstreamNode.pfsnode.Y));
          grf.Geometry = l;
          grf.Data = dt.NewRow();
          grf.Data[0] = b.pfslink.LinkID;
          grf.Data[1] = b.pfslink.FromNode;
          grf.Data[2] = b.pfslink.ToNode;
          grf.Data[3] = b.pfslink.SpecifiedLength;
          sw.Write(grf);
        }
      }

      if (Branches != null && Branches.Count > 0)
      {
        using (ShapeWriter sw = new ShapeWriter(Path.Combine(Path.GetDirectoryName(ShapeFileName), Path.GetFileNameWithoutExtension(ShapeFileName)+"_branches.shp")))
        {
          DataTable dt = new DataTable();
          dt.Columns.Add("Name", typeof(string));
          dt.Columns.Add("Length", typeof(double));

          foreach (var b in Branches)
          {

            var line = new XYPolyline();
            line.Points.AddRange(b.Links.Select(p => p.UpstreamNode.Location));
            line.Points.Add(b.Links.Last().DownstreamNode.Location);
            GeoRefData grf = new GeoRefData();
            grf.Geometry = line; 
            grf.Data = dt.NewRow();
            grf.Data[0] = b.Name;
            grf.Data[1] = line.GetLength();
            
            sw.Write(grf);


          }



        }

      }
    }