예제 #1
0
        public virtual IMetadata GetMetadata()
        {
            if (this._Layer == null)
            {
                return(null);
            }

            //计算图像大小-按数据边界
            OSGeo.OGR.Envelope envelope = new OSGeo.OGR.Envelope();
            this._Layer.GetExtent(envelope, 1);

            //提取图像参数值
            MetadataR pMeta = new MetadataR();

            pMeta.MinX       = Math.Round(envelope.MinX, 8);
            pMeta.MaxX       = Math.Round(envelope.MaxX, 8);
            pMeta.MinY       = Math.Round(envelope.MinY, 8);
            pMeta.MaxY       = Math.Round(envelope.MaxY, 8);
            pMeta.IsNorthern = (pMeta.MinY > 0);
            return(pMeta);
        }
예제 #2
0
        public virtual IMetadataR GetMetadataR(int nBandIndex = 1)
        {
            if (this._Dataset == null)
            {
                return(null);
            }

            //提取图像参数值
            MetadataR pMeta = new MetadataR();

            pMeta.Cols  = _Dataset.RasterXSize;     //获取图像宽
            pMeta.Rows  = _Dataset.RasterYSize;     //获取图像高
            pMeta.Bands = _Dataset.RasterCount;     //波段数
            if (pMeta.Bands < nBandIndex - 1)
            {
                return(null);
            }

            double[] adfGeoTransform = new double[6];
            _Dataset.GetGeoTransform(adfGeoTransform);
            pMeta.MinX       = adfGeoTransform[0];
            pMeta.MinY       = adfGeoTransform[3];
            pMeta.IsNorthern = (adfGeoTransform[1] + adfGeoTransform[4] == 0);

            int ratio = pMeta.IsNorthern ? 1 : -1;

            pMeta.CellSize = adfGeoTransform[1];
            pMeta.MaxX     = pMeta.MinX + pMeta.CellSize * pMeta.Cols;
            pMeta.MaxY     = pMeta.MinY + ratio * pMeta.CellSize * pMeta.Rows;

            pMeta.MaxX = Math.Round(pMeta.MaxX, 8);
            pMeta.MaxY = Math.Round(pMeta.MaxY, 8);

            double dNoData = 0;
            Band   poBand  = _Dataset.GetRasterBand(nBandIndex);

            poBand.GetNoDataValue(out dNoData, out _);
            pMeta.NoDataValue = dNoData;
            return(pMeta);
        }