给GE下载的JPG卫片加配准JGW文件(批量 winform)
jpg地圖的空間數據文件-jgw文件格式
1、X-Scale(一個像元的大小)
2、旋轉項
3、旋轉項
4、負的Y-Scale(一個像元的大小)
5、轉換項,即左上角X坐標
6、轉換項,即左上角Y坐標
?衛片為256*256大小,文件名以“qrst”串四分
private void button10_Click(object sender, EventArgs e){ if (Directory.Exists(textBox1.Text)){DirectoryInfo di = new DirectoryInfo(textBox1.Text);foreach (FileInfo fi in di.GetFiles("*.jpg")){string str = fi.Name.Substring(0, fi.Name.IndexOf("."));double[] coor = GetCoordinatesFromAddress(str);double[] line = new double[6];line[0] = (coor[2] - coor[0]) / 256;line[1] = 0;line[2] = 0;line[3] = (-1) * (coor[1] - coor[3]) / 256;line[4] = coor[0];line[5] = coor[1];try{FileStream fs = new FileStream(di.FullName + "//"+str+".jgw", FileMode.Create, FileAccess.Write);StreamWriter sw = new StreamWriter(fs);for (int i = 0; i < 6; i++){sw.WriteLine(line[i].ToString("0.0000000000"));//小數點后保留10位}sw.Close();fs.Close();}catch(Exception ex){MessageBox.Show(ex.ToString());}}MessageBox.Show("All Done!");}}protected double[] GetCoordinatesFromAddress(string str){// get normalized coordinate firstdouble x = 0.0;//X,Y是以地圖的左上角為原點的坐標double y = 0.0;double scale = 1.0;str = str.Substring(1, str.Length - 1); // skip the first characterwhile (str.Length > 0){scale *= 0.5;//var c = str.charAt(0); // remove first characterchar c = str[0];if (c == 'r' || c == 's'){x += scale;}if (c == 't' || c == 's'){y += scale;}str = str.Substring(1, str.Length - 1);}double[] ret = new double[9];//qrst地圖的0度經緯度是在十字中心,經度出現負數是西經,正數是東經double long_left = (x - 0.5) * 360;double lat_top = NormalToMercator(y);double long_right = (x + scale - 0.5) * 360;double lat_bot = NormalToMercator(y + scale);double long_cent = (x + scale * 0.5 - 0.5) * 360;double lat_cent = NormalToMercator(y + scale * 0.5);ret[0] = Convert.ToDouble(long_left.ToString("F8"));ret[1] = Convert.ToDouble(lat_top.ToString("F8"));ret[2] = Convert.ToDouble(long_right.ToString("F8"));ret[3] = Convert.ToDouble(lat_bot.ToString("F8"));ret[4] = Convert.ToDouble(long_cent.ToString("F8"));ret[5] = Convert.ToDouble(lat_cent.ToString("F8"));ret[6] = x;ret[7] = y;ret[8] = scale;return ret;}protected double NormalToMercator(double y){y -= 0.5;y *= 2 * Math.PI;y = Math.Exp(y * 2);y = (y - 1) / (y + 1);y = Math.Asin(y);y = y * -180 / Math.PI;return y;}
總結
以上是生活随笔為你收集整理的给GE下载的JPG卫片加配准JGW文件(批量 winform)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 玩homegrownpet遇见unabl
- 下一篇: 安装catia时 计算机ID不同步,CA