jorsion
路人甲
路人甲
  • 注册日期2006-08-08
  • 发帖数4
  • QQ
  • 铜币122枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:2038回复:0

FWTools+SharpMap读取HDF

楼主#
更多 发布于:2009-04-01 23:44
前期顺利将<a href="http://www.hdfgroup.org/" target="_blank" ><FONT color=#800080>HDF</FONT></A>中的SDS数据读到了DataGridVIew中,后来又把GR数据读到了DataGridView中,但是GR是栅格图像啊,将它分波段读到DataGridView中不合适啊,于是就尝试把GR绘制出来。<BR>但俺对GDI+了解甚少。<BR>后来想到<a href="http://sharpmap.codeplex.com/" target="_blank" ><FONT color=#0000ff>SharpMap</FONT></A>可以借助<a href="http://www.gdal.org/" target="_blank" ><FONT color=#800080>GDAL</FONT></A>读取栅格数据,且又是开源的,可以拿来看看。<BR>下载了<a href="http://sharpmap.codeplex.com/Project/Download/SourceControlFileDownload.ashx?ProjectName=SharpMap;changeSetId=44819" target="_blank" ><FONT color=#0000ff>sharpmap-44819</FONT></A>,还好,里面有Extensions,其中就有支持了GDAL的GdalRasterLayer类,并且有一个Windows桌面版的Demo,其中有shapefile、grandientTheme、wms、wfs、OGR-MapInfo、GDAL-GeoTiff,哈哈,关键是有GDAL的例子。其实这些例子都差不多,也就是实例化一种Layer,然后添加到地图。<BR>但是,看看GdalRasterLayer中的构造方法,是这样的:<BR>
<BLOCKQUOTE>    public GdalRasterLayer(string strLayerName, string imageFilename)<BR>    {<BR>      this.LayerName = strLayerName;<BR>      this.Filename = imageFilename;<BR>      disposed = false;<BR>      OSGeo.GDAL.Gdal.AllRegister();<BR>      try<BR>      {<BR>        _GdalDataset = OSGeo.GDAL.Gdal.OpenShared(_Filename, OSGeo.GDAL.Access.GA_ReadOnly);<BR>        // have gdal read the projection<BR>        strProjection = _GdalDataset.GetProjectionRef();<BR>        // no projection info found in the image…check for a prj<BR>        if (strProjection == “” ;; File.Exists(imageFilename.Substring(0, imageFilename.LastIndexOf(”.”)) + “.prj”))<BR>        {<BR>          strProjection = File.ReadAllText(imageFilename.Substring(0, imageFilename.LastIndexOf(”.”)) + “.prj”);<BR>        }<BR>        imagesize = new Size(_GdalDataset.RasterXSize, _GdalDataset.RasterYSize);<BR>        _Envelope = this.GetExtent();<BR>        rectHistoBounds = new Rectangle((int)_Envelope.Left, (int)_Envelope.Bottom, (int)_Envelope.Width, (int)_Envelope.Height);<BR>        lbands = _GdalDataset.RasterCount;<BR>      }<BR>      catch (Exception ex)<BR>      {<BR>        _GdalDataset = null;<BR>        throw new Exception(”Couldn’t load ” + imageFilename + “\n\n” + ex.Message + ex.InnerException);<BR>      }<BR>    }<BR><BR></BLOCKQUOTE>这只适合于Tiff这种单个文件单个数据集的,但对于HDF这类层次式文件,里面有若干栅格数据集、这种情况下就要重载构造方法,重载如下:<BR>
<BLOCKQUOTE>public GdalRasterLayer(string strLayerName,OSGeo.GDAL.Dataset dataset)<BR>    {<BR>        this.LayerName = strLayerName;<BR>        disposed = false;<BR>        OSGeo.GDAL.Gdal.AllRegister();<BR>        try<BR>        {<BR>            _GdalDataset = dataset;<BR>            // have gdal read the projection<BR>            strProjection = _GdalDataset.GetProjectionRef();<BR>            imagesize = new Size(_GdalDataset.RasterXSize, _GdalDataset.RasterYSize);<BR>            _Envelope = this.GetExtent();<BR>            rectHistoBounds = new Rectangle((int)_Envelope.Left, (int)_Envelope.Bottom, (int)_Envelope.Width, (int)_Envelope.Height);<BR>            lbands = _GdalDataset.RasterCount;<BR>        }<BR>        catch (Exception ex)<BR>        {<BR>            _GdalDataset = null;<BR>            throw new Exception(ex.Message + ex.InnerException);<BR>        }<BR>    }<BR></BLOCKQUOTE>这样做了之后,还要把<a href="http://fwtools.maptools.org/" target="_blank" ><FONT color=#800080>FWTools</FONT></A>中的支持HDF的dll替换Extensions中的dll,然后重新编译,不然这样的GdalRasterLayer还是不支持<a href="http://www.hdfgroup.org/" target="_blank" ><FONT color=#800080>HDF</FONT></A>的。
喜欢0 评分0
博客:一牛九锁
游客

返回顶部