【代碼分享-04-Delft3d結構化網格轉MIKE非結構化網格存儲及Delft3D、MIKE網格生成前處理GIS數據轉換
///
/// 將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();
}
}
工程師必備
- 項目客服
- 培訓客服
- 平臺客服
TOP




















