-
大小: 4.46MB文件類(lèi)型: .rar金幣: 2下載: 0 次發(fā)布日期: 2023-09-20
- 語(yǔ)言: C#
- 標(biāo)簽: GDAL??OGR??讀取數(shù)據(jù)??C#版本??
資源簡(jiǎn)介
GDAL\OGR讀取數(shù)據(jù)示例 C#版本
有讀取柵格和矢量,并顯示數(shù)據(jù)里面的基本信息,可以用來(lái)作為入門(mén)例子

代碼片段和文件信息
using?OSGeo.GDAL;
using?OSGeo.OSR;
using?System;
namespace?GDALTest
{
????///?
????///?使用GDAL讀取柵格數(shù)據(jù)信息類(lèi)
????///?
????public?class?GDALReadFile
????{
????????public?static?string?GetRasterInfo(string?strFilePath)
????????{
????????????string?strInfomation?=?““;
????????????try
????????????{
????????????????/*?--------------------------------------------------------------------?*/
????????????????/*??????Register?driver(s).?????????????????????????????????????????????*/
????????????????/*?--------------------------------------------------------------------?*/
????????????????Gdal.AllRegister();
????????????????/*?--------------------------------------------------------------------?*/
????????????????/*??????Open?dataset.???????????????????????????????????????????????????*/
????????????????/*?--------------------------------------------------------------------?*/
????????????????Dataset?ds?=?Gdal.Open(strFilePath?Access.GA_ReadOnly);
????????????????if?(ds?==?null)
????????????????{
????????????????????strInfomation?=?(“Can‘t?open?“?+?strFilePath);
????????????????????return?strInfomation;
????????????????}
????????????????strInfomation?+=?(“Raster?dataset?parameters:\n“);
????????????????strInfomation?+=?(“??Projection:?“?+?ds.GetProjectionRef()?+?“\n“);
????????????????strInfomation?+=?(“??RasterCount:?“?+?ds.RasterCount.ToString()?+?“\n“);
????????????????strInfomation?+=?(“??RasterSize?(“?+?ds.RasterXSize.ToString()?+?““?+?ds.RasterYSize.ToString()?+?“)“?+?“\n“);
????????????????/*?--------------------------------------------------------------------?*/
????????????????/*??????Get?driver??????????????????????????????????????????????????????*/
????????????????/*?--------------------------------------------------------------------?*/
????????????????Driver?drv?=?ds.GetDriver();
????????????????if?(drv?==?null)
????????????????{
????????????????????strInfomation?+=?(“Can‘t?get?driver.“);
????????????????????return?strInfomation;
????????????????}
????????????????strInfomation?+=?(“Using?driver?“?+?drv.LongName);
????????????????/*?--------------------------------------------------------------------?*/
????????????????/*??????Get?metadata????????????????????????????????????????????????????*/
????????????????/*?--------------------------------------------------------------------?*/
????????????????string[]?metadata?=?ds.Getmetadata(““);
????????????????if?(metadata.Length?>?0)
????????????????{
????????????????????strInfomation?+=?(“??metadata:“);
????????????????????for?(int?imeta?=?0;?imeta?tadata.Length;?imeta++)
????????????????????{
????????????????????????strInfomation?+=?(“????“?+?imeta.ToString()?+?“:??“?+?metadata[imeta]?+?“\n“);
????????????????????}
????????????????????strInfomation?+=?(“\n“);
????????????????}
????????????????/*?--------------------------------------------------------------------?*/
????????????????/*??????Report?“IMAGE_STRUCT
?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
?????文件????7294464??2012-04-26?09:32??GDALTest\bin\Debug\gdal19.dll
?????文件????????616??2012-03-15?13:53??GDALTest\bin\Debug\gdal19.dll.manifest
?????文件??????12800??2012-04-24?20:22??GDALTest\bin\Debug\gdalconst_wrap.dll
?????文件??????14328??2012-10-16?21:31??GDALTest\bin\Debug\GDALTest.vshost.exe
?????文件??????82944??2012-04-24?20:22??GDALTest\bin\Debug\gdal_wrap.dll
?????文件?????856064??2012-03-15?13:53??GDALTest\bin\Debug\geos_c.dll
?????文件????????616??2012-03-15?13:53??GDALTest\bin\Debug\geos_c.dll.manifest
?????文件?????481280??2012-03-15?13:53??GDALTest\bin\Debug\hd426m.dll
?????文件????1988096??2012-03-15?13:53??GDALTest\bin\Debug\hdf5dll.dll
?????文件?????109568??2012-03-15?13:53??GDALTest\bin\Debug\hm426m.dll
?????文件????1017344??2009-11-15?21:37??GDALTest\bin\Debug\libeay32.dll
?????文件?????968886??2010-02-22?15:28??GDALTest\bin\Debug\libiconv-2.dll
?????文件??????83906??2010-02-22?15:28??GDALTest\bin\Debug\libintl-8.dll
?????文件?????167936??2011-07-08?16:58??GDALTest\bin\Debug\libpq.dll
?????文件??????82432??2012-04-24?20:22??GDALTest\bin\Debug\ogr_wrap.dll
?????文件??????39936??2012-04-24?20:22??GDALTest\bin\Debug\osr_wrap.dll
?????文件?????220160??2012-03-15?13:53??GDALTest\bin\Debug\proj.dll
?????文件?????380928??2012-03-15?13:53??GDALTest\bin\Debug\SQLite3.dll
?????文件?????200704??2009-11-15?21:37??GDALTest\bin\Debug\ssleay32.dll
?????文件??????41472??2012-03-15?13:53??GDALTest\bin\Debug\szip.dll
?????文件??????61440??2012-03-15?13:53??GDALTest\bin\Debug\zlib1.dll
?????文件??????12252??2012-10-16?21:22??GDALTest\GDALReadFile.cs
?????文件???????4951??2012-10-16?20:45??GDALTest\GDALTest.csproj
?????文件????????905??2012-10-16?19:07??GDALTest\GDALTest.sln
????..A..H.?????19456??2012-10-16?21:23??GDALTest\GDALTest.suo
?????文件???????2549??2012-10-16?20:54??GDALTest\MainForm.cs
?????文件???????6917??2012-10-16?19:32??GDALTest\MainForm.Designer.cs
?????文件???????5814??2012-10-16?19:31??GDALTest\MainForm.resx
?????文件???????7648??2012-10-16?20:56??GDALTest\OGRReadFile.cs
?????文件????????492??2012-10-16?19:19??GDALTest\Program.cs
............此處省略12個(gè)文件信息
評(píng)論
共有 條評(píng)論