Example #1
0
        public virtual string Open(string path)
        {
            try
            {
                fs = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);
                br = new BinaryReader(fs);

                MinLevel = br.ReadInt32();
                MaxLevel = br.ReadInt32();

                MinRow         = br.ReadInt32();
                MaxRow         = br.ReadInt32();
                MinCol         = br.ReadInt32();
                MaxCol         = br.ReadInt32();
                outFormat      = (LCompressFormat)(br.ReadInt32());
                _region        = new GeoRegion();
                _region.MinLon = br.ReadDouble();
                _region.MaxLon = br.ReadDouble();
                _region.MinLat = br.ReadDouble();
                _region.MaxLat = br.ReadDouble();
                this.CFormat   = outFormat;
                int dt = br.ReadInt32();

                DataType = (LDataType)dt;

                _bitsPerPixel = br.ReadInt32() * 8;
                CurGeoRegion  = _region;

                MinX         = CurGeoRegion.MinLon;
                MaxX         = CurGeoRegion.MaxLon;
                MinY         = CurGeoRegion.MinLat;
                MaxY         = CurGeoRegion.MaxLat;
                _info        = new GGeoImageInfo();
                _info.MaxCol = MaxCol;
                _info.MinCol = MinCol;
                _info.MaxRow = MaxRow;
                _info.MinRow = MinRow;

                _info.MaxLevel  = MaxLevel;
                _info.MinLevel  = MinLevel;
                _info.outFormat = outFormat;
                _info.Region    = CurGeoRegion;
                this.Tag        = _info;
                //ResolutionX =
            }
            catch
            {
                return("wrong");
            }

            return("");
        }
Example #2
0
        //..

        public unsafe GeoImage ToCompressImage(LCompressFormat s, string filename)
        {
            LImageInfo info = new LImageInfo();

            GetImageInfo(_imgPtr, ref info);

            IntPtr of = IntPtr.Zero;

            info.LCFormate = s;
            CreateLFile(filename, info, ref of);
            int nTileY      = info.nRows;
            int nTileX      = info.nCols;
            int size        = 512 * 512 * (info.bits / 8) * info.bands;
            int bytePerLine = 512 * (info.bits / 8) * info.bands;

            byte[] buf = new byte[size];
            int    r   = 0;

            fixed(void *ptr = buf)
            {
                for (int nLvl = 0; nLvl < info.levelCount; nLvl++)
                {
                    for (int i = 0; i < nTileY; i++)
                    {
                        for (int j = 0; j < nTileX; j++)
                        {
                            r = ReadTile(1, nLvl, i, j, buf, 0, s);
                            LTileIO(LFRWFlag.LF_Write, of, nLvl, i, j, ptr, 1, ref r);
                        }
                    }

                    nTileX = (nTileX + 1) >> 1;
                    nTileY = (nTileY + 1) >> 1;
                }
            }

            CloseLFile(of);

            GeoImage reader = new GeoImage();

            reader.Open(filename);
            return(reader);
        }
Example #3
0
 public static extern void CreateLCompress(ref IntPtr lc, LCompressFormat format, LDataType dataType, int band);
Example #4
0
        public override unsafe int ReadTile(int band, int level, int row, int col, byte[] buffer, int offset, LCompressFormat outFormat)
        {
            if (buffer == null || offset < 0)
            {
                return(-1);
            }

            int count = 0;

            fixed(byte *ptr = buffer)
            {
                byte *ptrDat = ptr + offset;

                lock (loclObject)
                    LTileIO(LFRWFlag.LF_Read, _imgPtr, level, row, col, ptrDat, band, ref count);

                if (outFormat != CFormat && count > 0)
                {
                    //--解压缩
                    int destLen = 512 * 512 * _bands * BitsPerPixel / 8;

                    lock (loclObject)
                        DeCompress(_imgCompressPtr, (byte *)ptrDat, ref destLen, (byte *)ptrDat, count);

                    //--压缩
                    IntPtr lc = IntPtr.Zero;
                    CreateLCompress(ref lc, outFormat, _dataType, _bands);
                    Compress(lc, (byte *)ptrDat, ref count, (byte *)ptrDat, destLen);
                    CloseLCompress(lc);
                }
            }

            return(count);
        }
Example #5
0
        public override unsafe int ReadTile(int band, int level, int row, int col, byte[] buffer, int offset, LCompressFormat outFormat)
        {
            if (buffer == null || offset < 0)
            {
                return(-1);
            }
            int maxlevel = MaxLevel;
            int minlevel = MinLevel, minrow = MinRow, maxrow = MaxRow, mincol = MinCol, maxcol = MaxCol;
            int size = buffer.Length;

            for (int i = 0; i < size; i++)
            {
                buffer[i] = 0;
            }

            long bandoffset = 0;

            if (level > MaxLevel || level < minlevel)
            {
                return(0);
            }

            for (int k = maxlevel; k > level; k--)
            {
                double tileSize = (double)180 / (1 << k);

                minrow = MathEngine.GetRowFromLatitude(_region.MinLat, tileSize);
                maxrow = MathEngine.GetRowFromLatitude(_region.MaxLat, tileSize);
                mincol = MathEngine.GetColFromLongitude(_region.MinLon, tileSize);
                maxcol = MathEngine.GetColFromLongitude(_region.MaxLon, tileSize);

                bandoffset += (maxrow - minrow + 1) * (maxcol - mincol + 1) * 12;
            }

            double tilesize = (double)180 / (1 << level);

            minrow = MathEngine.GetRowFromLatitude(_region.MinLat, tilesize);
            maxrow = MathEngine.GetRowFromLatitude(_region.MaxLat, tilesize);
            mincol = MathEngine.GetColFromLongitude(_region.MinLon, tilesize);
            maxcol = MathEngine.GetColFromLongitude(_region.MaxLon, tilesize);
            if (row > maxrow || row < minrow || col > maxcol || col < mincol)
            {
                return(0);
            }

            br.BaseStream.Seek(1024 + bandoffset + ((row - minrow) * (maxcol - mincol + 1) + col - mincol) * 12, 0);
            long pos       = br.ReadInt64();
            int  posoffset = br.ReadInt32();

            if (posoffset <= 0 || br.BaseStream.Length < pos)
            {
                return(0);
            }

            br.BaseStream.Seek(pos, 0);
            br.Read(buffer, offset, posoffset);

            return(posoffset);
        }
Example #6
0
        public override unsafe int ReadTile(int band, int level
                                            , int row, int col, byte[] buffer, int offset, LCompressFormat outFormat)
        {
            string url = "";

            url = System.Configuration.ConfigurationManager.AppSettings["URL"];
            url = string.Format("http://{0}/ImageServer/ImageServer.ashx?name={1}&l={2}&r={3}&c={4}&o=1", url, filepath,
                                level, row, col);

            HttpWebRequest  r      = HttpWebRequest.Create(url) as HttpWebRequest;
            HttpWebResponse result = r.GetResponse() as HttpWebResponse;

            System.IO.Stream mem = result.GetResponseStream();

            MemoryStream ms = new MemoryStream(buffer);

            byte[] _bytes = new byte[4096];
            int    _i     = 0;
            int    len    = 0;

            do
            {
                _i = mem.Read(_bytes, 0, 4096);

                ms.Write(_bytes, 0, _i);
                len += _i;
            } while (_i > 0);

            return(len);
        }
Example #7
0
        public override unsafe int ReadTile(int band, int level, int row, int col, byte[] buffer, int offset, LCompressFormat outFormat)
        {
            if (_img == IntPtr.Zero)
            {
                return(-1);

                fixed(void *ptr = buffer)
                {
                    ReadImgBlock(_img, level, row, col, ptr);
                }

                return(512 * 512 * Bands * BitsPerPixel / 8);
        }
Example #8
0
        public virtual int ReadTile(int band, int level, int row, int col, byte[] buffer, int offset, LCompressFormat outFormat)
        {
            int r = -1;

            if (ReadTileEvent != null)
            {
                r = ReadTileEvent(_uri, band, level, row, col, outFormat, buffer, offset);
            }
            return(r);
        }