VS2010 c#利用GDAL创建金字塔文件(金字塔文件包含在文件内部)
来源:互联网 发布:js中json删除指定元素 编辑:程序博客网 时间:2024/05/22 17:19
源代码下载地址:http://download.csdn.net/detail/ivanljf/5832879
1、首先要配置工程环境,将编译好的9个dll文件放在debug目录下,将带有csharp的四个dll添加到引用;如下图:
2.添加命名空间:using OSGeo.GDAL
3、贴出代码:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using OSGeo.GDAL;//添加该命名空间namespace Official_BuildOverviews{ class Program { public static void usage() { Console.WriteLine("usage: Official_BuildOverviews {GDAL dataet name} {resampling} {level1} {level2} ..."); Console.WriteLine("example: gdaloverviews sample.tif \"NEAREST\" 2 4"); System.Environment.Exit(-1); } static void Main(string[] args) { if (args.Length <= 2) usage(); Console.WriteLine(""); try { Gdal.AllRegister(); Dataset ds = Gdal.Open(args[0], Access.GA_Update); if (ds == null) { Console.WriteLine("Can't open" + args[0]); System.Environment.Exit(-1); } Console.WriteLine("Raster dataset parameters:"); Console.WriteLine(" Projection:" + ds.GetProjectionRef()); Console.WriteLine(" RasterCount:" + ds.RasterCount); Console.WriteLine(" RasterSize(" + ds.RasterXSize + "," + ds.RasterYSize + ")"); int[] levels = new int[args.Length - 2];//减去前两个参数,该数组存储级别数(2,4,8,16...) Console.WriteLine(levels.Length); for (int i = 2; i < args.Length; i++) { levels[i - 2] = int.Parse(args[i]);//从第三个参数开始存储 } if (ds.BuildOverviews(args[1], levels, new Gdal.GDALProgressFuncDelegate(ProgressFunc), "Sample Data") != (int)CPLErr.CE_None) { Console.WriteLine("The BuildOverviews operation doesn't work"); System.Environment.Exit(-1); } for (int iBand = 1; iBand <= ds.RasterCount;iBand++ ) { Band band = ds.GetRasterBand(iBand); Console.WriteLine("Band " + iBand + ":"); Console.WriteLine(" DataType: " + band.DataType); Console.WriteLine(" Size (" + band.XSize + "," + band.YSize + ")"); Console.WriteLine(" PaletteInterp: " + band.GetRasterColorInterpretation().ToString()); for (int iOver = 0; iOver < band.GetOverviewCount();iOver++ ) { Band over = band.GetOverview(iOver); Console.WriteLine(" OverView " + iOver + ":"); Console.WriteLine(" DataType:" + over.DataType); Console.WriteLine(" Size (" + over.XSize + "," + over.YSize + ")"); Console.WriteLine(" PaletteInterp: " + over.GetRasterColorInterpretation().ToString()); } } Console.WriteLine("Completed."); Console.WriteLine("Use: gdalread " + args[0] + " outfile.png [overview] to extract a particular overview!"); } catch (System.Exception ex) { Console.WriteLine("Application error: " + ex.Message); } } public static int ProgressFunc(double Complete, IntPtr Message, IntPtr Data)//和委托参数一致 public delegate int GDALProgressFuncDelegate(double Complete, IntPtr Message, IntPtr Data); { Console.Write("Processing ..." + Complete * 100 + "% Completed."); if (Message != IntPtr.Zero) { Console.Write("Message:" + System.Runtime.InteropServices.Marshal.PtrToStringAnsi(Message)); } if (Data != IntPtr.Zero) { Console.Write("Data:" + System.Runtime.InteropServices.Marshal.PtrToStringAnsi(Data)); } Console.WriteLine(""); return 1; } }}
注:该程序代码是命令行参数程序,若想调试该程序,需要将传递的参数提前设置好:
源代码下载地址:http://download.csdn.net/detail/ivanljf/5832879
- VS2010 c#利用GDAL创建金字塔文件(金字塔文件包含在文件内部)
- gdal 工具创建金字塔
- GDAL金字塔
- 使用GDAL创建Erdas格式的金字塔
- 一个php文件实现打印金字塔
- 4:(C#下使用GDAL库)创建影像文件
- 利用for循环创建金字塔
- GDAL构建金字塔
- gdal 图像金字塔
- 函数内部包含文件
- C++、GDAL创建shapefile文件
- C# Gdal 读取SHP文件
- C#用GDAL/OGR库创建与写Shape文件
- [转]使用GDAL创建Erdas格式的金字塔
- 【GDAL/OGR】利用GDAL/OGR读取shp文件并转换为json文件(Java版)
- 金字塔
- 金字塔
- 金字塔
- const、volatile区别
- [JavaScript]判断JS中的函数(方法)是否存在
- 由学生的读后感看SEO的工作
- Oracle基础学习笔记(一)-基于马士兵Oracle视频
- js保留两位小数
- VS2010 c#利用GDAL创建金字塔文件(金字塔文件包含在文件内部)
- POJ-1823-Hotel
- ubuntu编译android源码
- 黑马程序员——Java学习笔记(四) .
- 对象的动态和静态构造创建的区别
- UVa 729: The Hamming Distance Problem
- HDU 3939 毕达哥拉斯三元组
- HTML,CSS,HTTP
- Myeclipse修改Java web项目名称