///
/// 将GIS的线矢量shp文件转换为MIKE网格绘制需要的边界xyz文件(格式为:x y connectivity)
///
///
///
public static void Shp2xyz(string shpfile, string xyzfile)
{
if (File.Exists(shpfile))
{
//存储所有线段的坐标点
List<</SPAN>IList<</SPAN>Coordinate>> lstpts = new List<</SPAN>IList<</SPAN>Coordinate>>();
IFeatureSet fs = FeatureSet.Open(shpfile);
IFeatureList lstf = fs.Features;
foreach (Feature f in lstf)
{
lstpts.Add(f.Coordinates);
}
//写x,y,connectivity格式ascii文件
StringBuilder sb = new StringBuilder();
int idx = 1;
foreach (IList<</SPAN>Coordinate> lstpt in lstpts)
{
int idxpt = 1;
foreach (Coordinate coord in lstpt)
{
if (idxpt == 1)
sb.AppendLine(string.Format(" {0} {1} {2}", coord.X, coord.Y,0));
else if (idxpt == lstpt.Count) sb.AppendLine(string.Format(" {0} {1} {2}", coord.X, coord.Y, 0));
else
sb.AppendLine(string.Format(" {0} {1} {2}", coord.X, coord.Y, 1));
idxpt++;
}
idx++;
}
StreamWriter sw = new StreamWriter(xyzfile);
sw.Write(sb.ToString());
sw.Flush();
sw.Close();
}
}