示例#1
0
        /*
         *  VALUECOUNT = 2         //default:0
         *  VALUES = "{0,1}"       //
         *  VALUENAMES             //
         *  SPATIALREF=Proj4                  //default:wgs-84
         *  MAPINFO={X,Y}:{Col,Row}:{ResolutionX,ResolutionY} //default:null
         *  WITHHDR=[TRUE|FALSE]      //default:true
         */
        public override IRasterDataProvider Create(string fileName, int xSize, int ySize, int bandCount, enumDataType dataType, params object[] options)
        {
            ISpatialReference spatialRef;
            MvgHeader         mvgHeader;
            HdrMapInfo        mapInfo = null;
            bool  isWithHdr           = true;
            Int16 valueCount          = 0;

            Int16[]  values     = null;
            string[] valueNames = null;
            using (FileStream fileStream = new FileStream(fileName, FileMode.Create))
            {
                ParserMvgHeaderParams(options, out spatialRef, out mapInfo, out isWithHdr, out valueCount, out values, out valueNames);
                mvgHeader = CreateMvgHeader(xSize, ySize, spatialRef, mapInfo, valueCount, values, valueNames);
                int headerSize = mvgHeader.HeaderSize;
                int fileLength = mvgHeader.HeaderSize + xSize * ySize * bandCount * DataTypeHelper.SizeOf(enumDataType.Int16);
                fileStream.SetLength(fileLength);
                fileStream.Write(mvgHeader.ToBytes(), 0, headerSize);
            }
            if (isWithHdr)
            {
                mvgHeader.ToHdrFile().SaveTo(HdrFile.GetHdrFileName(fileName));
            }
            IGeoDataProvider provider = BuildDataProviderByArgs(fileName, enumDataProviderAccess.Update, mvgHeader);

            return(provider as IRasterDataProvider);
        }
示例#2
0
        protected HdrMapInfo GetHdrMapInfo(AWXLevel2HeaderImage l2H)
        {
            HdrMapInfo mapInfo = new HdrMapInfo();

            mapInfo.BaseMapCoordinateXY = new HdrGeoPointCoord(l2H.GeographicalScopeWestLongitude / 100.0f, l2H.GeographicalScopeNorthLatitude / 100.0f);//左上角经纬度
            mapInfo.BaseRowColNumber    = new Point(1, 1);
            mapInfo.CoordinateType      = GetCoordinateSystemName();
            float XResolution = Math.Abs(l2H.GeographicalScopeEastLongitude - l2H.GeographicalScopeWestLongitude) * 1.0f / 100.0f / l2H.ImageWidth;
            float YResolution = Math.Abs(l2H.GeographicalScopeNorthLatitude - l2H.GeographicalScopeSouthLatitude) * 1.0f / 100.0f / l2H.ImageHeight;

            mapInfo.XYResolution = new HdrGeoPointCoord(XResolution, YResolution);
            return(mapInfo);
        }
示例#3
0
 internal void SetMapInfo(HdrMapInfo mapInfo)
 {
     if (mapInfo == null)
     {
         return;
     }
     LongitudeResolution = (float)mapInfo.XYResolution.Longitude;
     LatitudeResolution  = (float)mapInfo.XYResolution.Latitude;
     MinLon = (float)mapInfo.BaseMapCoordinateXY.Longitude - LongitudeResolution * (mapInfo.BaseRowColNumber.X - 1);/*ENVI pixel from 1*/
     MaxLat = (float)mapInfo.BaseMapCoordinateXY.Latitude + LatitudeResolution * (mapInfo.BaseRowColNumber.Y - 1);
     MaxLon = MinLon + LongitudeResolution * _width;
     MinLat = MaxLat - LatitudeResolution * _height;
 }
示例#4
0
        private HdrMapInfo GetHdrMapInfo()
        {
            HdrMapInfo mapInfo = new HdrMapInfo();

            if (_spatialRef != null && _spatialRef.ProjectionCoordSystem != null)
            {
                mapInfo.Name  = GetMapInfoName();
                mapInfo.Units = "Meters";
            }
            mapInfo.BaseMapCoordinateXY = new HdrGeoPointCoord(_coordEnvelope.MinX, _coordEnvelope.MaxY);
            mapInfo.BaseRowColNumber    = new Point(1, 1);
            mapInfo.CoordinateType      = GetCoordinateSystemName();
            mapInfo.XYResolution        = new HdrGeoPointCoord(Double.Parse(_resolutionX.ToString()), Double.Parse(_resolutionY.ToString()));//低精度向高精度转化
            return(mapInfo);
        }
示例#5
0
        private HdrMapInfo ParseMapInfoFromOptionValue(string value)
        {
            if (string.IsNullOrEmpty(value))
            {
                return(null);
            }
            string[] parts = value.Split(':');
            if (parts.Length != 3)
            {
                return(null);
            }
            for (int i = 0; i < parts.Length; i++)
            {
                parts[i] = parts[i].Replace('{', ' ').Replace('}', ' ').Trim();
            }
            string[] values = parts[0].Split(',');
            if (values.Length != 2)
            {
                return(null);
            }
            HdrMapInfo mapInfo = new HdrMapInfo();

            mapInfo.BaseRowColNumber = new Point(int.Parse(values[0]), int.Parse(values[1]));
            values = parts[1].Split(',');
            if (values.Length != 2)
            {
                return(null);
            }
            mapInfo.BaseMapCoordinateXY = new HdrGeoPointCoord(double.Parse(values[0]), double.Parse(values[1]));
            values = parts[2].Split(',');
            if (values.Length != 2)
            {
                return(null);
            }
            mapInfo.XYResolution = new HdrGeoPointCoord(double.Parse(values[0]), double.Parse(values[1]));
            return(mapInfo);
        }
示例#6
0
        private void ParseOptions(int width, int height, object[] options, out ISpatialReference spatialRef, out CoordEnvelope coordEnvelope, out HdrMapInfo mapInfo,
                                  out bool isWithHdr, out int extHeaderSize)
        {
            mapInfo       = null;
            spatialRef    = null;
            coordEnvelope = null;
            isWithHdr     = true;
            extHeaderSize = 0;
            if (options == null || options.Length == 0)
            {
                return;
            }
            foreach (object option in options)
            {
                string param = option.ToString();
                int    k     = param.IndexOf('=');
                string key   = param.Substring(0, k).ToUpper().Trim();
                string value = param.Substring(k + 1).ToUpper().Trim();
                switch (key.ToUpper())
                {
                case "SPATIALREF":
                    spatialRef = SpatialReferenceFactory.GetSpatialReferenceByProj4String(value);
                    break;

                case "MAPINFO":
                    mapInfo       = ParseMapInfoFromOptionValue(value);
                    coordEnvelope = CoordEnvelope.FromMapInfoString(value, new Size(width, height));
                    break;

                case "WITHHDR":
                    isWithHdr = value.ToUpper() == "TRUE" || value == "1";
                    break;

                case "EXTHEADERSIZE":
                    extHeaderSize = int.Parse(value);
                    break;

                default:
                    break;
                }
            }
        }
示例#7
0
        internal void ParserMvgHeaderParams(object[] options, out ISpatialReference spatialRef, out HdrMapInfo mapInfo, out bool isWithHdr,
                                            out Int16 valueCount, out Int16[] values, out string[] valueNames)
        {
            spatialRef = null;
            mapInfo    = null;
            isWithHdr  = true;
            valueCount = 0;
            values     = null;
            valueNames = null;
            if (options == null || options.Length == 0)
            {
                return;
            }
            foreach (object option in options)
            {
                string param = option.ToString();
                int    k     = param.IndexOf('=');
                string key   = param.Substring(0, k).ToUpper().Trim();
                string value = param.Substring(k + 1).ToUpper().Trim();
                switch (key)
                {
                case "VALUECOUNT":
                    valueCount = Convert.ToInt16(value);
                    break;

                case "VALUES":
                    values = ParserValues(value);
                    break;

                case "VALUENAMES":
                    valueNames = ParserValueNames(value);
                    break;

                case "SPATIALREF":
                    spatialRef = SpatialReferenceFactory.GetSpatialReferenceByProj4String(value);
                    break;

                case "MAPINFO":
                    mapInfo = ParseMapInfo(value);
                    break;

                case "WITHHDR":
                    isWithHdr = value.ToUpper() == "TRUE" || value == "1";
                    break;

                default:
                    break;
                }
            }
        }
示例#8
0
        private MvgHeader CreateMvgHeader(int xSize, int ySize, ISpatialReference spatialRef, HdrMapInfo mapInfo, Int16 valueCount, Int16[] values, string[] valueNames)
        {
            if (values == null || valueNames == null || valueCount == 0)
            {
                throw new NotSupportedException("所给参数(values,valueNames,valueCount)不完整!");
            }
            MvgHeader mvgHeader = new MvgHeader();

            mvgHeader.Width      = (Int16)xSize;
            mvgHeader.Height     = (Int16)ySize;
            mvgHeader.SpatialRef = spatialRef;
            mvgHeader.ValueCount = valueCount;
            mvgHeader.Values     = values;
            mvgHeader.ValueNames = valueNames;
            mvgHeader.SetMapInfo(mapInfo);
            return(mvgHeader);
        }