• 根据范围获取影像瓦片,并生成GeoTIFF 文件《一》


    第一步 :根据查询的坐标范围,提取bundle紧凑型切片文件中的 图片,并保存

    输入参数:  四值数值  xmax,xmin,ymax,ymin,

                        切片原点:Xorigin  Yorigin

     private void  TEST()
            {
                CArcGIS103CacheInfo.OriginX = Xorgin;
                CArcGIS103CacheInfo.OriginY = Yorgin;
                CArcGIS103CacheInfo.resolution = resolution;
                int rowNum1; int colNum1;
                CArcGIS103CacheInfo.GetRowColNumber(Xmin, Ymax, out rowNum1, out colNum1);
                int rowNum2;int colNum2;
                CArcGIS103CacheInfo.GetRowColNumber(Xmax, Ymax, out rowNum2, out colNum2);
                int rowNum3;int colNum3;
                CArcGIS103CacheInfo.GetRowColNumber(Xmin, Ymin, out rowNum3, out colNum3);
                int rowNum4; int colNum4;
                CArcGIS103CacheInfo.GetRowColNumber(Xmax, Ymin, out rowNum4, out colNum4);
    
                int rowNummin = rowNum2;
                int rowNummax = rowNum3;
                int colNummin = colNum1;
                int colNummax = colNum2;
                int disRow = rowNummax - rowNummin;
                int disCol = colNummax - colNummin;
                int a = 1;
                //*********计算左上角坐标
                double ZSJ_x = Xorgin - colNum1 * (-1)*256*resolution;
                double ZSJ_y = Yorgin - (rowNum1) * 256 * resolution;
                
    
                double XXmax=Xorgin-(colNum2+1)*(-1) * 256 * resolution;
                double YYmax= Yorgin -( rowNum2) * 256 * resolution;
    
                double  XXmin= Xorgin - (colNum1 ) * (-1) * 256 * resolution;
                double YYmin= Yorgin - (rowNum3+1)  * 256 * resolution;
    
                /*
                double Xmin = 290657.60;
                double Ymin = 3211323.2;
                double Xmax = 422902.2;
                double Ymax = 3371264.00;
    
    
    
                *****/
    
                int b = 0;
                Console.WriteLine(DateTime.Now.ToString());
                GetJinCou2SongSan(rowNummin, rowNummax, colNummin, colNummax);
                Console.WriteLine(DateTime.Now.ToString());
            }
     //***** 根据 row  Col   读取切片 ,将紧凑型 转为松散型   *****/
    
            private  void  GetJinCou2SongSan(int rowNummin,int rowNummax,int colNummin,int colNummax)
            {
                for(int i=rowNummin;i<=rowNummax;i++)
                {
                    for(int j=colNummin;j<=colNummax;j++)
                    {
    
    
    
                        GetJinCou2SongSan2(i, j, "L08");
    
    
                    }
    
    
                }
            }
    
            private void GetJinCou2SongSan2(int row,int col,string mlevel)
            {
               
                string col16 = col.ToString("X"); //00A1  16进制的文件名
               
                string row16 = row.ToString("X");//00C5   16进制的文件名
    
                //计算bundle文件名 
    
                double rowgroupd = (double)(row / PacketSize);
                int rowgroup = (int)(PacketSize * Math.Floor(rowgroupd));
                double colgroupd = (double)(col / PacketSize);
                int colgroup = (int)(PacketSize * Math.Floor(colgroupd));
                string rowgroup16 = rowgroup.ToString("X");//80
                string colgroup16 = colgroup.ToString("X");//80
                if (rowgroup16.Length < 4)
                {
                    int l = 4 - rowgroup16.Length;
                    for (int i = 0; i < l; i++)
                    {
                        rowgroup16 = "0" + rowgroup16;
    
                    }
                }
    
                if (colgroup16.Length < 4)
                {
                    int lm = 4 - colgroup16.Length;
                    for (int i = 0; i < lm; i++)
                    {
                        colgroup16 = "0" + colgroup16;
    
                    }
                }
                //获取切片所在的bundle 文件
                string bundlename = @"E:2019ArcGIS10.3\_alllayers" + mlevel + "\" + "R" + rowgroup16 + "C" + colgroup16 + ".bundle";
                int index = PacketSize * (row - rowgroup) + (col - colgroup);
    
                FileStream inBundle = new FileStream(bundlename, FileMode.Open, FileAccess.Read);
                inBundle.Seek(64 + 8 * index, SeekOrigin.Begin);
                //获取位置索引并计算切片位置偏移量
                byte[] indexBytes = new byte[4];
                inBundle.Read(indexBytes, 0, 4);
                long offset = (long)(indexBytes[0] & 0xff) + (long)(indexBytes[1] & 0xff) * 256 + (long)(indexBytes[2] & 0xff) * 65536
                                    + (long)(indexBytes[3] & 0xff) * 16777216;
                long startOffset = offset - 4;
                inBundle.Seek(startOffset, SeekOrigin.Begin);
                byte[] lengthBytes = new byte[4];
                inBundle.Read(lengthBytes, 0, 4);
                int length = (int)(lengthBytes[0] & 0xff) + (int)(lengthBytes[1] & 0xff) * 256 + (int)(lengthBytes[2] & 0xff) * 65536
                            + (int)(lengthBytes[3] & 0xff) * 16777216;
                //根据切片位置和切片长度获取切片
    
                byte[] tileBytes = null;
                tileBytes = new byte[length];
                int bytesRead = 0;
                if (length > 4)
                {
                    bytesRead = inBundle.Read(tileBytes, 0, tileBytes.Length);
                }
                else
                {
                    tileBytes = null;
                }
                string outfilename = @"E:2019ArcGIS10.3L08Song" + "\" + "R" + row + "C" + col + ".png";
                using (FileStream stream = new FileStream(outfilename, FileMode.OpenOrCreate))
                {
                    stream.Write(tileBytes, 0, tileBytes.Length);
                }
    
            }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace TestReadArcgGISCache
    {
        class CArcGIS103CacheInfo
        {
            public   static double OriginX;
            public   static double OriginY;
            public    static double resolution;
           public  static void GetRowColNumber(double x,double y,out int RowNum,out int ColNum)
            {
    
                double colx = Math.Abs((OriginX - x)) / (256 * resolution);
                ColNum = (int)Math.Floor(colx);
    
                double rowx = (OriginY - y) / (256 * resolution);
                 RowNum = (int)Math.Floor(rowx);
    
                
            }
        }
    }
    

      

  • 相关阅读:
    HDU1255 覆盖的面积 —— 求矩形交面积 线段树 + 扫描线 + 离散化
    HDU1542 Atlantis —— 求矩形面积并 线段树 + 扫描线 + 离散化
    HDU1540 Tunnel Warfare —— 线段树 区间合并
    HDU3974 Assign the task —— dfs时间戳 + 线段树
    HDU4027 Can you answer these queries? —— 线段树 区间修改
    POJ3264 Balanced Lineup —— 线段树单点更新 区间最大最小值
    ZOJ1610 Count the Colors —— 线段树 区间染色
    HDU1698 Just a Hook —— 线段树 区间染色
    POJ2528 Mayor's posters —— 线段树染色 + 离散化
    POJ3468 A Simple Problem with Integers —— 线段树 区间修改
  • 原文地址:https://www.cnblogs.com/marky/p/10735543.html
Copyright © 2020-2023  润新知