資源簡介
利用C#語言讀取DEN數據的ASCII碼文件,并進行坡度的求取
代碼片段和文件信息
using?System;
using?System.IO;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
namespace?slope
{
????class?Program
????{
????????static?void?Main(string[]?args)
????????{
????????????//讀取DEM轉換后得到的ASCII碼文本,將高程值保存在二維數組中
????????????//StreamReader[]?str?=?new?StreamReader(@“G:\C#\dem.txt“);
????????????string[]?str?=?File.ReadAllLines(@“G:\C#\dem.txt“?Encoding.Default);
????????????int?ncols?nrows;
????????????int?i?j?k;
????????????double?xllcorner?yllcorner?cellsize?NODATA_value;?
??????
????????????ncols?=?Convert.ToInt32(str[0].Substring(143));
????????????nrows?=?Convert.ToInt32(str[1].Substring(14?3));
????????????xllcorner?=?Convert.ToDouble(str[2].Substring(14?6));
????????????yllcorner?=?Convert.ToDouble(str[3].Substring(14?7));
????????????cellsize?=?Convert.ToDouble(str[4].Substring(14?2));
????????????NODATA_value?=?Convert.ToDouble(str[5].Substring(14?5));
????????????Console.WriteLine(“ncols:{0}“?ncols);
????????????Console.WriteLine(“nrows:{0}“?nrows);
????????????Console.WriteLine(“xllcorner:{0}“?xllcorner);
????????????Console.WriteLine(“yllcorner:{0}“?yllcorner);
????????????Console.WriteLine(“cellsize:{0}“?cellsize);
????????????Console.WriteLine(“NODATA_value:{0}“?NODATA_value);
????????????double[]?dem?=?new?double[nrows?ncols];
????????????string?[]?str1?=?new?string[ncols];
????????????char[]?interval?=?new?char[]?{?‘?‘?};
????????????for?(i?=?6k=0;?i?????????????{
????????????????str1?=?str[i].Split(interval);
???????
- 上一篇:重寫Buttion按鈕
- 下一篇:游戲賬戶管理系統
評論
共有 條評論