private static string ToString(Resolution r)
 {
     var sb = new StringBuilder("{" + r.Id);
     sb.AppendFormat(NumberFormatInfo.InvariantInfo, ";{0}", r.UnitsPerPixel);
     sb.AppendFormat(NumberFormatInfo.InvariantInfo, ";{0}", r.ScaleDenominator);
     sb.AppendFormat(NumberFormatInfo.InvariantInfo, ";{0}", r.Left);
     sb.AppendFormat(NumberFormatInfo.InvariantInfo, ";{0}", r.Top);
     sb.AppendFormat(NumberFormatInfo.InvariantInfo, ";{0}", r.MatrixWidth);
     sb.AppendFormat(NumberFormatInfo.InvariantInfo, ";{0}", r.MatrixHeight);
     sb.AppendFormat(NumberFormatInfo.InvariantInfo, ";{0}", r.TileWidth);
     sb.AppendFormat(NumberFormatInfo.InvariantInfo, ";{0}", r.TileHeight);
     sb.AppendFormat(NumberFormatInfo.InvariantInfo, ";{0}", r.ScaleDenominator);
     sb.Append("}");
     return sb.ToString();
 }
 // Methods
 public ArcGISTileSchema(string FilePath)
 {
     Resolution resolution2;
     this.url = @"C:\arcgisserver\arcgiscache\GZMap\Layers\conf.xml";
     this.url = FilePath;
     XmlDocument document = new XmlDocument();
     document.Load(this.url);
     XmlNode documentElement = document.DocumentElement;
     XmlNodeList elementsByTagName = document.GetElementsByTagName("LODInfo");
     List<LODInfo> list2 = new List<LODInfo>();
     foreach (XmlNode node2 in elementsByTagName)
     {
     string innerText = node2["LevelID"].InnerText;
     string str2 = node2["Scale"].InnerText;
     string str3 = node2["Resolution"].InnerText;
     LODInfo item = new LODInfo();
     item.LevelID = Convert.ToInt32(innerText);
     item.Scale = Convert.ToDouble(str2);
     item.Resolution = Convert.ToDouble(str3);
     list2.Add(item);
     }
     foreach (LODInfo info2 in list2)
     {
     resolution2 = new Resolution();
     Resolution resolution = resolution2;
     resolution.Id = info2.LevelID.ToString();
     resolution.UnitsPerPixel = info2.Resolution;
     base.Resolutions.Add(resolution);
     }
     base.Height = 0x100;
     base.Width = 0x100;
     base.Extent = new Extent(-180.0, -90.0, 180.0, 90.0);
     XmlNodeList list3 = document.GetElementsByTagName("SpatialReference");
     base.OriginX = Convert.ToDouble(list3[0]["XOrigin"].InnerText);
     base.OriginY = Convert.ToDouble(list3[0]["YOrigin"].InnerText);
     list3 = document.GetElementsByTagName("TileCols");
     base.Width = Convert.ToInt32(list3[0].InnerText);
     list3 = document.GetElementsByTagName("TileRows");
     base.Height = Convert.ToInt32(list3[0].InnerText);
     base.Axis = AxisDirection.InvertedY;
     list3 = document.GetElementsByTagName("TileOrigin");
     base.OriginX = Convert.ToDouble(list3[0].FirstChild.InnerText);
     base.OriginY = Convert.ToDouble(list3[0].LastChild.InnerText);
     base.Name = "ArcGISTileCache";
     base.Format = "png";
     base.Srs = "UnKnown";
     DirectoryInfo info3 = new DirectoryInfo(Path.GetDirectoryName(FilePath) + @"\_alllayers\L00");
     BoundingBox box = null;
     foreach (DirectoryInfo info4 in info3.GetDirectories())
     {
     int row = RowToHex(info4.Name);
     int level = 0;
     foreach (FileInfo info5 in info4.GetFiles())
     {
         if (info5.FullName.EndsWith(base.Format))
         {
             BoundingBox box2;
             int col = ColumnToHex(info5.Name);
             TileInfo info6 = new TileInfo();
             info6.Extent = this.TileToWorld(new TileRange(col, row), level, this);
             resolution2 = base.Resolutions[level];
             info6.Index = new TileIndex(col, row, resolution2.Id);
             try
             {
                 box2 = new BoundingBox(info6.Extent.MinX, info6.Extent.MinY, info6.Extent.MaxX, info6.Extent.MaxY);
             }
             catch (Exception)
             {
                 box2 = new BoundingBox(-180.0, -90.0, 180.0, 90.0);
             }
             if (box2 != null)
             {
                 box = (box == null) ? box2 : box.Join(box2);
             }
         }
     }
     }
     if (box != null)
     {
     base.Extent = new Extent(box.Min.X, box.Min.Y, box.Max.X, box.Max.Y);
     }
 }
        // Methods
        public ArcGISTileCompactSchema(string FilePath)
        {
            Resolution resolution2;
            this.url = @"C:\arcgisserver\arcgiscache\GZMap\Layers\conf.xml";
            this.url = FilePath;
            string cdiFile = string.Format(@"{0}\conf.cdi", Path.GetDirectoryName(FilePath));
            XmlDocument document = new XmlDocument();
            document.Load(this.url);
            XmlNode documentElement = document.DocumentElement;
            XmlNodeList elementsByTagName = document.GetElementsByTagName("LODInfo");
            List<LODInfo> list2 = new List<LODInfo>();
            foreach (XmlNode node2 in elementsByTagName)
            {
            string innerText = node2["LevelID"].InnerText;
            string str2 = node2["Scale"].InnerText;
            string str3 = node2["Resolution"].InnerText;
            LODInfo item = new LODInfo();
            item.LevelID = Convert.ToInt32(innerText);
            item.Scale = Convert.ToDouble(str2);
            item.Resolution = Convert.ToDouble(str3);
            list2.Add(item);
            }
            foreach (LODInfo info2 in list2)
            {
            resolution2 = new Resolution();
            Resolution resolution = resolution2;
            resolution.Id = info2.LevelID.ToString();
            resolution.UnitsPerPixel = info2.Resolution;
            base.Resolutions.Add(resolution);
            }
            base.Height = 0x100;
            base.Width = 0x100;
            base.Extent = new Extent(-180.0, -90.0, 180.0, 90.0);
            XmlNodeList list3 = document.GetElementsByTagName("SpatialReference");
            base.OriginX = Convert.ToDouble(list3[0]["XOrigin"].InnerText);
            base.OriginY = Convert.ToDouble(list3[0]["YOrigin"].InnerText);
            list3 = document.GetElementsByTagName("TileCols");
            base.Width = Convert.ToInt32(list3[0].InnerText);
            list3 = document.GetElementsByTagName("TileRows");
            base.Height = Convert.ToInt32(list3[0].InnerText);
            base.Axis = AxisDirection.InvertedY;
            list3 = document.GetElementsByTagName("TileOrigin");
            base.OriginX = Convert.ToDouble(list3[0].FirstChild.InnerText);
            base.OriginY = Convert.ToDouble(list3[0].LastChild.InnerText);
            base.Name = "ArcGISTileCache";
            base.Format = "png";
            base.Srs = "UnKnown";
            DirectoryInfo info3 = new DirectoryInfo(Path.GetDirectoryName(FilePath) + @"\_alllayers\L00");
            BoundingBox box = null;
            //foreach (FileInfo infoBundle in info3.GetFiles())
            //{
            //    if (infoBundle.FullName.EndsWith("bundle"))
            //    {
            //        BoundingBox box2;
            //        //int row = RowToHex(infoBundle.Name.Substring(1, 4));
            //        int row = RowToHex(infoBundle.Name);
            //        int level = 0;
            //        //int col = ColumnToHex(infoBundle.Name.Substring(6, 4));
            //        int col = ColumnToHex(infoBundle.Name);
            //        TileInfo infoTile = new TileInfo();
            //        infoTile.Extent = this.TileToWorld(new TileRange(col, row), level, this);
            //        resolution2 = base.Resolutions[level];
            //        infoTile.Index = new TileIndex(col, row, resolution2.Id);
            //        try
            //        {
            //            box2 = new BoundingBox(infoTile.Extent.MinX, infoTile.Extent.MinY, infoTile.Extent.MaxX, infoTile.Extent.MaxY);
            //        }
            //        catch (Exception)
            //        {
            //            box2 = new BoundingBox(-180,-90,180,90);
            //        }
            //        if (box2!=null)
            //        {
            //            box = (box == null) ? box2 : box.Join(box2);
            //        }
            //    }
            //}
            //foreach (DirectoryInfo info4 in info3.GetDirectories())
            //{
            //    int row = RowToHex(info4.Name);
            //    int level = 0;
            //    foreach (FileInfo info5 in info4.GetFiles())
            //    {
            //        if (info5.FullName.EndsWith(base.Format))
            //        {
            //            BoundingBox box2;
            //            int col = ColumnToHex(info5.Name);
            //            TileInfo info6 = new TileInfo();
            //            info6.Extent = this.TileToWorld(new TileRange(col, row), level, this);
            //            resolution2 = base.Resolutions[level];
            //            info6.Index = new TileIndex(col, row, resolution2.Id);
            //            try
            //            {
            //                box2 = new BoundingBox(info6.Extent.MinX, info6.Extent.MinY, info6.Extent.MaxX, info6.Extent.MaxY);
            //            }
            //            catch (Exception)
            //            {
            //                box2 = new BoundingBox(-180.0, -90.0, 180.0, 90.0);
            //            }
            //            if (box2 != null)
            //            {
            //                box = (box == null) ? box2 : box.Join(box2);
            //            }
            //        }
            //    }
            //}
            //if (box != null)
            //{
            //    base.Extent = new Extent(box.Min.X, box.Min.Y, box.Max.X, box.Max.Y);
            //}
            try
            {
            XDocument xDoc = XDocument.Load(cdiFile);

            var fullExtent = (from a in xDoc.Descendants("EnvelopeN")
                              select new Extent
                              (
                                    a.Element("XMin") == null ? double.NaN : double.Parse(a.Element("XMin").Value),
                                    a.Element("YMin") == null ? double.NaN : double.Parse(a.Element("YMin").Value),
                                    a.Element("XMax") == null ? double.NaN : double.Parse(a.Element("XMax").Value),
                                    a.Element("YMax") == null ? double.NaN : double.Parse(a.Element("YMax").Value)
                              )).First();
            //{ SpatialReference = this.SpatialReference }).First();

            base.Extent = fullExtent;

            }
            catch (Exception ex)
            {

            }
            //if (box != null)
            //{
            //    base.Extent = new Extent(box.Min.X, box.Min.Y, box.Max.X, box.Max.Y);
            //}
        }
Exemplo n.º 4
0
        private void DrawTile(MapArgs args, TileInfo info, Resolution resolution, byte[] buffer, TileReprojector tr = null)
        {
            if (buffer == null || buffer.Length == 0)
                return;

            tr = tr ?? new TileReprojector(args, _projection, _targetProjection);

            using (var bitmap = (Bitmap)Image.FromStream(new MemoryStream(buffer)))
            {
                var inWorldFile = new Reprojection.WorldFile(resolution.UnitsPerPixel, 0, 
                                                0, -resolution.UnitsPerPixel,
                                                info.Extent.MinX, info.Extent.MaxY);

                Reprojection.WorldFile outWorldFile;
                Bitmap outBitmap;


                tr.Reproject(inWorldFile, bitmap, out outWorldFile, out outBitmap);
                if (outWorldFile == null) return;

                var lt = args.ProjToPixel(outWorldFile.ToGround(0, 0));
                var rb = args.ProjToPixel(outWorldFile.ToGround(outBitmap.Width, outBitmap.Height));
                var rect = new Rectangle(lt, Size.Subtract(new Size(rb), new Size(lt)));

                args.Device.DrawImage(outBitmap, rect, 0, 0, outBitmap.Width, outBitmap.Height,
                    GraphicsUnit.Pixel, _imageAttributes);

                if (outBitmap != bitmap) outBitmap.Dispose();
                if (FrameTile)
                {
                    if (FramePen != null)
                        args.Device.DrawRectangle(FramePen, rect);
                }
            }
        }