Exemplo n.º 1
0
        /// <summary>
        /// Download the image for the given TileInfo.
        /// </summary>
        /// <param name="oTile">The TileInfo of the tile of this LayerInfo to download.</param>
        /// <returns>The filename for the image, or null if it could not be downloaded.</returns>
        public String CacheTileImage(TileInfo oTile)
        {
            String strCacheFilename = Path.Combine(CacheUtils.CacheRoot, GetCacheFilename(oTile));

            // --- Download the file if it doesn't already exist ---

            if (!File.Exists(strCacheFilename))
            {
                System.Diagnostics.Debug.WriteLine("LayerInfo: cacheing tile " + oTile.ToString());

                Directory.CreateDirectory(Path.GetDirectoryName(strCacheFilename));

                if (m_strServerType.ToUpperInvariant().Equals("DAP"))
                {
                    try
                    {
                        DownloadDapImage(strCacheFilename, oTile);
                    }
                    catch (DapException)
                    {
                        return null;
                    }
                    catch (WebException)
                    {
                        return null;
                    }
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            return strCacheFilename;
        }
Exemplo n.º 2
0
        public Stream GetCachedImageTile(string strServerType, string strServer, string strLayer, int iLevel, int iCol, int iRow)
        {
            strServerType = HttpUtility.UrlDecode(strServerType);
            strServer = HttpUtility.UrlDecode(strServer);
            strLayer = HttpUtility.UrlDecode(strLayer);
            TileInfo oTile = new TileInfo(iLevel, iCol, iRow);
            LayerInfo oLayer = new LayerInfo(strServerType, strServer, strLayer);

            #region // Input checking
            if (String.IsNullOrEmpty(strServerType) ||
                String.IsNullOrEmpty(strServer) ||
                String.IsNullOrEmpty(strLayer))
            {
                ReportStatusCode(HttpStatusCode.BadRequest);
                return null;
            }
            #endregion

            byte[] oImage = oLayer.GetTileImage(oTile);
            if (oImage != null)
            {
                return new MemoryStream(oImage);
            }
            else
            {
                ReportStatusCode(HttpStatusCode.NotFound);
                return null;
            }
        }
Exemplo n.º 3
0
        public Stream GenerateTileKml(String strServerType, String strServer, String strLayer, int iLevel, int iCol, int iRow, double dMinX, double dMinY, double dMaxX, double dMaxY)
        {
            strServerType = HttpUtility.UrlDecode(strServerType);
            strServer = HttpUtility.UrlDecode(strServer);
            strLayer = HttpUtility.UrlDecode(strLayer);

            TileInfo oTile = new TileInfo(iLevel, iCol, iRow);
            BoundingBox oLayerBounds = new BoundingBox(dMaxX, dMaxY, dMinX, dMinY);
            System.Diagnostics.Debug.Assert(oLayerBounds.MaxX >= oLayerBounds.MinX);
            System.Diagnostics.Debug.Assert(oLayerBounds.MaxY >= oLayerBounds.MinY);

            WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
            return TileKmlGenerator.GenerateTileKml(strServerType, strServer, strLayer, oTile, oLayerBounds);
        }
Exemplo n.º 4
0
        public static Uri BindImageCacheUriTemplate(Uri oBaseAddress, String strServerType, String strServer, String strLayer, TileInfo oTile)
        {
            UriTemplate oTemplate = new UriTemplate(ImageCacheUriTemplate);

            NameValueCollection oParameters = new NameValueCollection();
            oParameters.Add("serverType", HttpUtility.UrlEncode(strServerType));
            oParameters.Add("server", HttpUtility.UrlEncode(strServer));
            oParameters.Add("layer", HttpUtility.UrlEncode(strLayer));
            oParameters.Add("level", oTile.Level.ToString(CultureInfo.InvariantCulture));
            oParameters.Add("col", oTile.Column.ToString(CultureInfo.InvariantCulture));
            oParameters.Add("row", oTile.Row.ToString(CultureInfo.InvariantCulture));

            return oTemplate.BindByName(oBaseAddress, oParameters);
        }
Exemplo n.º 5
0
        public static Uri BindTileKmlUriTemplate(Uri oBaseAddress, String strServerType, String strServer, String strLayer, TileInfo oTile, BoundingBox oLayerBounds)
        {
            UriTemplate oTemplate = new UriTemplate(TileKmlUriTemplate);

            NameValueCollection oParameters = new NameValueCollection();
            oParameters.Add("serverType", HttpUtility.UrlEncode(strServerType));
            oParameters.Add("server", HttpUtility.UrlEncode(strServer));
            oParameters.Add("layer", HttpUtility.UrlEncode(strLayer));
            oParameters.Add("level", oTile.Level.ToString(CultureInfo.InvariantCulture));
            oParameters.Add("col", oTile.Column.ToString(CultureInfo.InvariantCulture));
            oParameters.Add("row", oTile.Row.ToString(CultureInfo.InvariantCulture));
            oParameters.Add("minx", oLayerBounds.MinX.ToString(CultureInfo.InvariantCulture));
            oParameters.Add("miny", oLayerBounds.MinY.ToString(CultureInfo.InvariantCulture));
            oParameters.Add("maxx", oLayerBounds.MaxX.ToString(CultureInfo.InvariantCulture));
            oParameters.Add("maxy", oLayerBounds.MaxY.ToString(CultureInfo.InvariantCulture));

            return oTemplate.BindByName(oBaseAddress, oParameters);
        }
Exemplo n.º 6
0
        public static MemoryStream GenerateTileKml(String strServerType, String strServer, String strLayer, TileInfo oTile, BoundingBox oLayerBounds)
        {
            BoundingBox oBoundsForThisFile = oTile.Bounds;

            MemoryStream result = new MemoryStream();
            XmlWriter oOutputWriter = XmlWriter.Create(result);
            oOutputWriter.WriteStartElement("kml", "http://www.opengis.net/kml/2.2");
            oOutputWriter.WriteStartElement("Document");

            oOutputWriter.WriteElementString("name", String.Format(CultureInfo.CurrentCulture, "Level {0}, Column {1}, Row {2}", oTile.Level, oTile.Column, oTile.Row));
            oOutputWriter.WriteStartElement("Region");
            oOutputWriter.WriteStartElement("LatLonAltBox");
            oOutputWriter.WriteElementString("north", oBoundsForThisFile.MaxY.ToString(CultureInfo.InvariantCulture));
            oOutputWriter.WriteElementString("south", oBoundsForThisFile.MinY.ToString(CultureInfo.InvariantCulture));
            oOutputWriter.WriteElementString("east", oBoundsForThisFile.MaxX.ToString(CultureInfo.InvariantCulture));
            oOutputWriter.WriteElementString("west", oBoundsForThisFile.MinX.ToString(CultureInfo.InvariantCulture));
            oOutputWriter.WriteEndElement(); //LatLonAltBox
            oOutputWriter.WriteStartElement("Lod");
            oOutputWriter.WriteElementString("minLodPixels", "256");
            oOutputWriter.WriteElementString("maxLodPixels", "-1");
            oOutputWriter.WriteEndElement(); //Lod
            oOutputWriter.WriteEndElement(); //Region

            bool blIntersecion = false;
            for (int iDRow = 0; iDRow <= 1; iDRow++)
            {
                for (int iDCol = 0; iDCol <= 1; iDCol++)
                {
                    TileInfo oSubTile = new TileInfo(oTile.Level + 1, oTile.Column * 2 + iDCol, oTile.Row * 2 + iDRow);
                    BoundingBox oBoundsForSubTile = oSubTile.Bounds;

                    if (oBoundsForSubTile.Intersects(oLayerBounds))
                    {
                        blIntersecion = true;

                        oOutputWriter.WriteStartElement("NetworkLink");
                        oOutputWriter.WriteElementString("name", String.Format(CultureInfo.InvariantCulture, "{0}{1} SubTile", iDRow == 0 ? "S" : "N", iDCol == 0 ? "W" : "E"));
                        oOutputWriter.WriteElementString("open", "1");
                        oOutputWriter.WriteStartElement("Region");
                        oOutputWriter.WriteStartElement("LatLonAltBox");
                        oOutputWriter.WriteElementString("north", oBoundsForSubTile.MaxY.ToString(CultureInfo.InvariantCulture));
                        oOutputWriter.WriteElementString("south", oBoundsForSubTile.MinY.ToString(CultureInfo.InvariantCulture));
                        oOutputWriter.WriteElementString("east", oBoundsForSubTile.MaxX.ToString(CultureInfo.InvariantCulture));
                        oOutputWriter.WriteElementString("west", oBoundsForSubTile.MinX.ToString(CultureInfo.InvariantCulture));
                        oOutputWriter.WriteEndElement(); //LatLonAltBox
                        oOutputWriter.WriteStartElement("Lod");
                        oOutputWriter.WriteElementString("minLodPixels", "256");
                        oOutputWriter.WriteElementString("maxLodPixels", "-1");
                        oOutputWriter.WriteEndElement(); //Lod
                        oOutputWriter.WriteEndElement(); //Region
                        oOutputWriter.WriteStartElement("Link");
                        oOutputWriter.WriteElementString("href", ContractHelper.BindTileKmlUriTemplate(ControlPanel.BaseAddress, strServerType, strServer, strLayer, oSubTile, oLayerBounds).ToString());
                        oOutputWriter.WriteElementString("viewRefreshMode", "onRegion");
                        oOutputWriter.WriteEndElement(); //Link
                        oOutputWriter.WriteEndElement(); //NetworkLink
                    }
                }
            }

            if (blIntersecion)
            {
                oOutputWriter.WriteStartElement("GroundOverlay");
                oOutputWriter.WriteElementString("drawOrder", (oTile.Level + 1).ToString(CultureInfo.InvariantCulture));
                oOutputWriter.WriteStartElement("Icon");
                oOutputWriter.WriteElementString("href", ContractHelper.BindImageCacheUriTemplate(ControlPanel.BaseAddress, strServerType, strServer, strLayer, oTile).ToString());
                oOutputWriter.WriteEndElement(); //Icon
                oOutputWriter.WriteStartElement("LatLonAltBox");
                oOutputWriter.WriteElementString("north", oBoundsForThisFile.MaxY.ToString(CultureInfo.InvariantCulture));
                oOutputWriter.WriteElementString("south", oBoundsForThisFile.MinY.ToString(CultureInfo.InvariantCulture));
                oOutputWriter.WriteElementString("east", oBoundsForThisFile.MaxX.ToString(CultureInfo.InvariantCulture));
                oOutputWriter.WriteElementString("west", oBoundsForThisFile.MinX.ToString(CultureInfo.InvariantCulture));
                oOutputWriter.WriteEndElement(); //LatLonAltBox
                oOutputWriter.WriteEndElement(); //GroundOverlay
            }

            oOutputWriter.WriteEndElement(); //Document
            oOutputWriter.WriteEndElement(); //kml
            oOutputWriter.Close();

            result.Seek(0, SeekOrigin.Begin);
            return result;
        }
Exemplo n.º 7
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="oLayer">The layer of this download.</param>
 /// <param name="oTile">The tile to download.</param>
 public DownloadInfo(LayerInfo oLayer, TileInfo oTile)
 {
     m_oLayer = oLayer;
     m_oTile = oTile;
 }
Exemplo n.º 8
0
        /// <summary>
        /// Create a root KML file for tiled KML for a given search result.
        /// </summary>
        /// <param name="oResult">The search result to create the root KML file for.</param>
        /// <returns>The filename of the created file.</returns>
        private static String CreateTileKmlFile(SearchResult oResult)
        {
            #region //Input checking
            if (oResult == null) throw new ArgumentNullException("oResult");
            if (!oResult.ServerType.Equals("DAP", StringComparison.InvariantCultureIgnoreCase))
                throw new ArgumentNullException("Only DAP servers are currently supported");
            #endregion

            String strCacheFilename = Path.Combine(CacheUtils.CacheRoot, GetRootKmlFilename(oResult));

            {
                Directory.CreateDirectory(Path.GetDirectoryName(strCacheFilename));
                XmlWriter oWriter = XmlWriter.Create(strCacheFilename);

                oWriter.WriteStartElement("kml", "http://www.opengis.net/kml/2.2");
                oWriter.WriteStartElement("Document");

                oWriter.WriteElementString("description", oResult.Description);
                oWriter.WriteStartElement("Camera");
                oWriter.WriteElementString("longitude", ((oResult.MinX + oResult.MaxX) / 2.0).ToString(CultureInfo.InvariantCulture));
                oWriter.WriteElementString("latitude", ((oResult.MinY + oResult.MaxY) / 2.0).ToString(CultureInfo.InvariantCulture));
                oWriter.WriteElementString("altitude", Math.Min(6500000, (oResult.MaxX - oResult.MinX) * 50 * 1000).ToString(CultureInfo.InvariantCulture));
                oWriter.WriteElementString("heading", "0");
                oWriter.WriteElementString("tilt", "0");
                oWriter.WriteElementString("roll", "0");
                oWriter.WriteEndElement(); // </Camera>

                for (int iColumn = 0; iColumn < 2; iColumn++)
                {
                    TileInfo oTile = new TileInfo(0, iColumn, 0);

                    Uri oTileKmlUrl = ContractHelper.BindTileKmlUriTemplate(ControlPanel.BaseAddress, oResult.ServerType, oResult.ServerUrl, oResult.GetAttribute("datasetname"), oTile, oResult.Bounds);

                    oWriter.WriteStartElement("NetworkLink");
                    oWriter.WriteElementString("name", "Some Hemisphere");
                    oWriter.WriteElementString("open", "1");
                    oWriter.WriteStartElement("Region");
                    oWriter.WriteStartElement("LatLonAltBox");
                    oWriter.WriteElementString("north", "90");
                    oWriter.WriteElementString("south", "-90");
                    oWriter.WriteElementString("east", (iColumn == 0 ? 0 : 180).ToString(CultureInfo.InvariantCulture));
                    oWriter.WriteElementString("west", (iColumn == 0 ? -180 : 0).ToString(CultureInfo.InvariantCulture));
                    oWriter.WriteEndElement(); // </LatLonAltBox>
                    oWriter.WriteStartElement("Lod");
                    oWriter.WriteElementString("minLodPixels", "128");
                    oWriter.WriteElementString("maxLodPixels", "-1");
                    oWriter.WriteEndElement(); // </Lod>
                    oWriter.WriteEndElement(); // </Region>
                    oWriter.WriteStartElement("Link");
                    oWriter.WriteElementString("href", oTileKmlUrl.ToString());
                    oWriter.WriteElementString("viewRefreshMode", "onRegion");
                    oWriter.WriteEndElement(); // </Link>
                    oWriter.WriteEndElement(); // </NetworkLink>
                }

                oWriter.WriteEndElement(); // </Document>
                oWriter.WriteEndElement(); // </kml>
                oWriter.Close();
            }

            return strCacheFilename;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Download an image for a layer.
        /// </summary>
        /// <param name="strCacheFilename">The filename to save the layer to.</param>
        /// <param name="oTile">The tile of this layer to download.</param>
        private void DownloadDapImage(string strCacheFilename, TileInfo oTile)
        {
            Format oFormat = new Format();
            oFormat.Type = "image/png";
            oFormat.Transparent = true;

            Resolution oRes = new Resolution();
            oRes.Height = TileInfo.TileSizePixels;
            oRes.Width = TileInfo.TileSizePixels;

            ArrayList oArr = new ArrayList();
            oArr.Add(m_strLayer);

            Command oCommand = new Command(m_strServer, false, Command.Version.GEOSOFT_XML_1_1, false, DapSecureToken.Instance);
            XmlDocument result = oCommand.GetImage(oFormat, oTile.Bounds, oRes, oArr);

            // --- Save the resulting image ---

            XmlNodeList hNodeList = result.SelectNodes("/" + Geosoft.Dap.Xml.Common.Constant.Tag.GEO_XML_TAG + "/" + Geosoft.Dap.Xml.Common.Constant.Tag.RESPONSE_TAG + "/" + Geosoft.Dap.Xml.Common.Constant.Tag.IMAGE_TAG + "/" + Geosoft.Dap.Xml.Common.Constant.Tag.PICTURE_TAG);
            if (hNodeList.Count == 0)
            {
                hNodeList = result.SelectNodes("/" + Geosoft.Dap.Xml.Common.Constant.Tag.GEO_XML_TAG + "/" + Geosoft.Dap.Xml.Common.Constant.Tag.RESPONSE_TAG + "/" + Geosoft.Dap.Xml.Common.Constant.Tag.TILE_TAG);
            }
            FileStream fs = new FileStream(strCacheFilename, System.IO.FileMode.Create);
            BinaryWriter bs = new BinaryWriter(fs);

            foreach (XmlNode hNode in hNodeList)
            {
                XmlNode hN1 = hNode.FirstChild;
                string jpegImage = hN1.Value;

                if (jpegImage != null)
                {
                    byte[] jpegRawImage = Convert.FromBase64String(jpegImage);

                    bs.Write(jpegRawImage);
                }
            }
            bs.Flush();
            bs.Close();
            fs.Close();
        }
Exemplo n.º 10
0
        /// <summary>
        /// Get the filename that this LayerInfo will save a given TileInfo as.
        /// </summary>
        /// <param name="oTile">The TileInfo for the tile to cache.</param>
        /// <returns>A filename relative to the cache root that the tile will be saved as.</returns>
        internal String GetCacheFilename(TileInfo oTile)
        {
            if (m_strServerType.ToUpperInvariant().Equals("DAP"))
            {
                UriBuilder oBuilder = new UriBuilder(m_strServer);
                return String.Format(CultureInfo.InvariantCulture, "DAP Images\\{0}\\{1}\\{2}\\{3:d4}-{4:d4}.png",
                    CacheUtils.CreateValidFilename(oBuilder.Host),
                    m_strLayer,
                    oTile.Level,
                    oTile.Column,
                    oTile.Row
                );
            }

            throw new NotImplementedException();
        }
Exemplo n.º 11
0
        /// <summary>
        /// Get the raw data for the given TileInfo.
        /// </summary>
        /// <param name="oTile">The TileInfo of the tile of this LayerInfo to get.</param>
        /// <returns>The raw data of the tile image, or null if it could not be downloaded.</returns>
        public byte[] GetTileImage(TileInfo oTile)
        {
            String strFilename = CacheTileImage(oTile);

            if (!String.IsNullOrEmpty(strFilename) && File.Exists(strFilename))
                return File.ReadAllBytes(strFilename);
            else
                return null;
        }