Ejemplo n.º 1
0
 private void GetAttrs(IHdfOperator oper)
 {
     _dsNames = oper.GetDatasetNames;
     _dsAttributes.Clear();
     _fileAttributes.Clear();
     foreach (string dsName in _dsNames)
     {
         Dictionary <string, string> dsAttrs = oper.GetAttributes(dsName);
         _dsAttributes.Add(dsName, dsAttrs);
     }
     _fileAttributes = oper.GetAttributes();
 }
Ejemplo n.º 2
0
        private void SetInputFileDataSet(string filename)
        {
            using (IHdfOperator oper = HdfOperatorFactory(filename))
            {
                if (oper == null)
                {
                    return;
                }
                GetAttrs(oper);
            }

            FillTreeView(filename);
            TrySetGeoInfo();
        }
Ejemplo n.º 3
0
        private CoordEnvelope GetCoordEnvelope(GeoAtrributes geoAtrrs)
        {
            double lulat = 0.0, lulon = 0.0, rdlat = 0.0, rdlon = 0.0;
            string lulatstr = geoAtrrs.LeftTopLatAtrrName;
            string lulonstr = geoAtrrs.LeftTopLonAtrrName;
            string rdlatstr = geoAtrrs.RightBottomLatAtrrName;
            string rdlonstr = geoAtrrs.RightBottomLonAtrrName;
            string unitstr  = geoAtrrs.Unit;

            using (IHdfOperator oper = HdfOperatorFactory(_fileName))
            {
                if (geoAtrrs.Location == enumGeoAttType.File)
                {
                    _fileAttributes = oper.GetAttributes();
                    if (_fileAttributes == null)
                    {
                        return(null);
                    }
                    if (!GetExtentPoints(lulatstr, lulonstr, rdlatstr, rdlonstr, out lulat, out lulon, out rdlat, out rdlon))
                    {
                        return(null);
                    }

                    if (!string.IsNullOrEmpty(unitstr) && _fileAttributes.ContainsKey(unitstr))
                    {
                        string unit = _fileAttributes[unitstr];
                        if (!string.IsNullOrEmpty(unit))
                        {
                            UpdateRDLonLat(unit, ref lulat, ref lulon, ref rdlat, ref rdlon);
                        }
                    }
                }
                else
                {
                    string geoDataset = geoAtrrs.GeoDataset;
                    lulat = GetDoubleAtrr(oper, geoDataset, lulatstr);
                    lulon = GetDoubleAtrr(oper, geoDataset, lulonstr);
                    rdlat = GetDoubleAtrr(oper, geoDataset, rdlatstr);
                    rdlon = GetDoubleAtrr(oper, geoDataset, rdlonstr);
                    if (Math.Abs(lulat - double.MinValue) < double.Epsilon ||
                        Math.Abs(lulon - double.MinValue) < double.Epsilon ||
                        Math.Abs(rdlat - double.MinValue) < double.Epsilon ||
                        Math.Abs(rdlon - double.MinValue) < double.Epsilon)
                    {
                        return(null);
                    }
                }
                return(new CoordEnvelope(lulon, rdlon, rdlat, lulat));
            }
        }
Ejemplo n.º 4
0
        private double GetDoubleAtrr(IHdfOperator oper, string dataSet, string atrribute)
        {
            double result   = double.MinValue;
            string attrTemp = oper.GetAttributeValue(dataSet, atrribute);

            if (!string.IsNullOrEmpty(attrTemp))
            {
                if (double.TryParse(attrTemp, out result))
                {
                    return(result);
                }
            }
            return(double.MinValue);
        }
Ejemplo n.º 5
0
        protected void Init(Dataset ds)
        {
            this.ds = ds;
            var subDsDic = ds.GetSubDatasets();

            if (Path.GetExtension(fileName).ToLower() != ".l1b" && subDsDic.Count > 0)
            {
                isMultiDs = true;
                //初始化IHdfOperator
                {
                    int _h5FileId = H5F.open(fileName, H5F.ACC_RDONLY);

                    if (_h5FileId >= 0)
                    {
                        hdfOperator = new Hdf5Operator(fileName);
                        //HDF5

                        H5F.close(_h5FileId);
                    }
                    else if (HDF4Helper.IsHdf4(fileName))
                    {
                        //HDF4
                        hdfOperator = new Hdf4Operator(fileName);
                    }
                }
                _fileAttrs = hdfOperator?.GetAttributes();

                GetAllSubDatasetFullpaths(ds);

                TryGetSizeOfMultiDs();
            }
            else if (ds.RasterCount > 0)
            {
                double[] geoTrans = new double[6];
                ds.GetGeoTransform(geoTrans);

                Width       = ds.RasterXSize;
                Height      = ds.RasterYSize;
                ResolutionX = Convert.ToSingle(geoTrans[1]);
                ResolutionY = Math.Abs(Convert.ToSingle(geoTrans[5]));
                BandCount   = ds.RasterCount;
                DataType    = ds.GetRasterBand(1).DataType;
                DriverName  = ds.GetDriver().ShortName;
                string wkt = ds.GetProjection();
                if (!string.IsNullOrEmpty(wkt))
                {
                    SpatialRef = new SpatialReference(wkt);
                }
            }
        }