internal static Stream Thumbnail(string dapUrl, int layerID) { Geosoft.Dap.Command c = new Geosoft.Dap.Command(dapUrl, false, Geosoft.Dap.Command.Version.GEOSOFT_XML_1_1, false, DapSecureToken.Instance, 30000); DataSet data = cachedData[layerID]; ArrayList datasets = new ArrayList(); datasets.Add(data.Name); double width = data.Boundary.MaxX - data.Boundary.MinX; double height = data.Boundary.MaxY - data.Boundary.MinY; Format format = new Format() { Transparent = true, Type = "image/png" }; const int TileSize = 100; const int Upscale = 4; Resolution rez; if (width > height) rez = new Resolution() { Width = TileSize * Upscale, Height = (int)Math.Max(1.0, (double)TileSize * Upscale * height / width) }; else if (height > width) rez = new Resolution() { Width = (int)Math.Max(1.0, (double)TileSize * Upscale * width / height), Height = TileSize * Upscale }; else rez = new Resolution() { Width = TileSize * Upscale, Height = TileSize * Upscale }; XmlDocument response = c.GetImage(format, data.Boundary, rez, false, false, datasets); byte[] pictureData = Convert.FromBase64String(response.SelectSingleNode("/geosoft_xml/response/image/picture").InnerText); MemoryStream serverResponseImage = new MemoryStream(pictureData); MemoryStream result = new MemoryStream(); using (Bitmap src = new Bitmap(serverResponseImage)) { using (Bitmap dst = new Bitmap(rez.Width / Upscale, rez.Height / Upscale)) { using (Graphics g = Graphics.FromImage(dst)) { g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.DrawImage(src, 0, 0, rez.Width / Upscale, rez.Height / Upscale); } dst.Save(result, System.Drawing.Imaging.ImageFormat.Png); } } result.Seek(0, SeekOrigin.Begin); return result; }
/// <summary> /// Encode the request to get an image of a list of datasets /// </summary> /// <param name="szHandle">The handle which uniquly identifies this request/response pair</param> /// <param name="hFormat">The format of the image</param> /// <param name="hBoundingBox">The area of the iamge</param> /// <param name="hResolution">The hieght and width of the image</param> /// <param name="bBaseMap">Draw the base map</param> /// <param name="bIndexMap">Draw the index map</param> /// <param name="hItems">The list of unique dataset names to draw</param> /// <returns>The GeosoftXML request</returns> public System.Xml.XmlDocument Image(string szHandle, Format hFormat, BoundingBox hBoundingBox, Resolution hResolution, bool bBaseMap, bool bIndexMap, ArrayList hItems) { // --- Create required nodes --- System.Xml.XmlAttribute hAttr; System.Xml.XmlElement hGetImageNode = CreateRequest(szHandle, Constant.Tag.IMAGE_TAG); System.Xml.XmlElement hFormatNode = hGetImageNode.OwnerDocument.CreateElement(Constant.Tag.FORMAT_TAG); System.Xml.XmlElement hResolutionNode = hGetImageNode.OwnerDocument.CreateElement(Constant.Tag.RESOLUTION_TAG); System.Xml.XmlElement hLayersNode = hGetImageNode.OwnerDocument.CreateElement(Constant.Tag.LAYERS_TAG); System.Xml.XmlNode hBoundingBoxNode; // --- Setup hierchy --- hGetImageNode.AppendChild(hFormatNode); hGetImageNode.AppendChild(hResolutionNode); hGetImageNode.AppendChild(hLayersNode); hBoundingBoxNode = AddBoundingBox(hGetImageNode, hBoundingBox); AddCoordinateSystem(hBoundingBoxNode, hBoundingBox.CoordinateSystem); if (hFormat.Type != null && hFormat.Type.Length != 0) { hAttr = hGetImageNode.OwnerDocument.CreateAttribute(Constant.Attribute.TYPE_ATTR); hAttr.Value = hFormat.Type; hFormatNode.SetAttributeNode(hAttr); } if (hFormat.Transparent) { hAttr = hGetImageNode.OwnerDocument.CreateAttribute(Constant.Attribute.TRANSPARENT_ATTR); hAttr.Value = "TRUE"; hFormatNode.SetAttributeNode(hAttr); } if (hFormat.Background != null && hFormat.Background.Length != 0) { hAttr = hGetImageNode.OwnerDocument.CreateAttribute(Constant.Attribute.BACKGROUND_ATTR); hAttr.Value = hFormat.Background; hFormatNode.SetAttributeNode(hAttr); } hAttr = hGetImageNode.OwnerDocument.CreateAttribute(Constant.Attribute.WIDTH_ATTR); hAttr.Value = hResolution.Width.ToString(); hResolutionNode.SetAttributeNode(hAttr); hAttr = hGetImageNode.OwnerDocument.CreateAttribute(Constant.Attribute.HEIGHT_ATTR); hAttr.Value = hResolution.Height.ToString(); hResolutionNode.SetAttributeNode(hAttr); hAttr = hGetImageNode.OwnerDocument.CreateAttribute(Constant.Attribute.BASE_MAP_ATTR); hAttr.Value = bBaseMap.ToString(); hLayersNode.SetAttributeNode(hAttr); hAttr = hGetImageNode.OwnerDocument.CreateAttribute(Constant.Attribute.INDEX_MAP_ATTR); hAttr.Value = bIndexMap.ToString(); hLayersNode.SetAttributeNode(hAttr); foreach (Object item in hItems) { System.Xml.XmlElement hDataSetNode = hGetImageNode.OwnerDocument.CreateElement(Constant.Tag.DATASET_TAG); hAttr = hGetImageNode.OwnerDocument.CreateAttribute(Constant.Attribute.NAME_ATTR); hAttr.Value = item.ToString(); hDataSetNode.SetAttributeNode(hAttr); hLayersNode.AppendChild(hDataSetNode); } return hGetImageNode.OwnerDocument; }
/// <summary> /// Get an image from a list of Geosoft.Dap.Command.DataSet classes /// </summary> /// <param name="hFormat">The format to retrieve the image in</param> /// <param name="hBoundingBox">The bounding box of the image</param> /// <param name="hResolution">The resolution to retrive the image at</param> /// <param name="bBaseMap">Draw the base map</param> /// <param name="bIndexMap">Draw the index map</param> /// <param name="hArrayList">The list of Geosoft.Dap.Command.DataSet classes</param> /// <param name="progressCallBack">Progress handler (may be null)</param> /// <returns>The image response in GeosoftXML</returns> public System.Xml.XmlDocument GetImageEx(Format hFormat, BoundingBox hBoundingBox, Resolution hResolution, bool bBaseMap, bool bIndexMap, System.Collections.ArrayList hArrayList, UpdateProgessCallback progressCallBack) { ArrayList hList = new ArrayList(); foreach (DataSet hDataSet in hArrayList) { if (hDataSet.Url == Url) hList.Add(hDataSet.Name); } return GetImage(hFormat, hBoundingBox, hResolution, bBaseMap, bIndexMap, hList, progressCallBack); }
/// <summary> /// Get the image request document for a particular dataset from the catalog item element /// </summary> /// <param name="hFormat">The format to retrieve the image in</param> /// <param name="hBoundingBox">The bounding box of the image</param> /// <param name="hResolution">The resolution to retrive the image at</param> /// <param name="bBaseMap">Draw the base map</param> /// <param name="bIndexMap">Draw the index map</param> /// <param name="hArrayList">The list of dataset server names</param> /// <param name="szUrl">URL to use to retrieve image</param> /// <returns>The image request in GeosoftXML</returns> /// <remarks> /// This will acquire a reader lock assuming some communication will be initiated with server. Be sure to match this call /// with ReleaseImageRequestDocument to release this lock. /// </remarks> public System.Xml.XmlDocument GetImageRequestDocument(Format hFormat, BoundingBox hBoundingBox, Resolution hResolution, bool bBaseMap, bool bIndexMap, System.Collections.ArrayList hArrayList, out string szUrl) { System.Xml.XmlDocument hRequestDocument = null; try { m_oLock.AcquireReaderLock(-1); szUrl = CreateUrl(Constant.Request.IMAGE); hRequestDocument = m_hEncodeRequest.Image(null, hFormat, hBoundingBox, hResolution, bBaseMap, bIndexMap, hArrayList); } catch (Exception e) { m_oLock.ReleaseReaderLock(); hRequestDocument = null; throw e; } return hRequestDocument; }
/// <summary> /// Get an image from a list of dataset server names /// </summary> /// <param name="hFormat">The format to retrieve the image in</param> /// <param name="hBoundingBox">The bounding box of the image</param> /// <param name="hResolution">The resolution to retrive the image at</param> /// <param name="bBaseMap">Draw the base map</param> /// <param name="bIndexMap">Draw the index map</param> /// <param name="hArrayList">The list of dataset server names</param> /// <param name="progressCallBack">Progress handler (may be null)</param> /// <returns>The image response in GeosoftXML</returns> public System.Xml.XmlDocument GetImage(Format hFormat, BoundingBox hBoundingBox, Resolution hResolution, bool bBaseMap, bool bIndexMap, System.Collections.ArrayList hArrayList, UpdateProgessCallback progressCallBack) { string szUrl; System.Xml.XmlDocument hRequestDocument; System.Xml.XmlDocument hResponseDocument; try { m_oLock.AcquireReaderLock(-1); szUrl = CreateUrl(Constant.Request.IMAGE); hRequestDocument = m_hEncodeRequest.Image(null, hFormat, hBoundingBox, hResolution, bBaseMap, bIndexMap, hArrayList); hResponseDocument = m_oCommunication.Send(szUrl, hRequestDocument, progressCallBack); } finally { m_oLock.ReleaseReaderLock(); } return hResponseDocument; }
/// <summary> /// Get an image from a list of Geosoft.Dap.Command.DataSet classes /// </summary> /// <param name="hFormat">The format to retrieve the image in</param> /// <param name="hBoundingBox">The bounding box of the image</param> /// <param name="hResolution">The resolution to retrive the image at</param> /// <param name="bBaseMap">Draw the base map</param> /// <param name="bIndexMap">Draw the index map</param> /// <param name="hArrayList">The list of Geosoft.Dap.Command.DataSet classes</param> /// <returns>The image response in GeosoftXML</returns> public System.Xml.XmlDocument GetImageEx(Format hFormat, BoundingBox hBoundingBox, Resolution hResolution, bool bBaseMap, bool bIndexMap, System.Collections.ArrayList hArrayList) { return GetImageEx(hFormat, hBoundingBox, hResolution, bBaseMap, bIndexMap, hArrayList, null); }
/// <summary> /// Get an image from a list of dataset server names /// </summary> /// <param name="hFormat">The format to retrieve the image in</param> /// <param name="hBoundingBox">The bounding box of the image</param> /// <param name="hResolution">The resolution to retrive the image at</param> /// <param name="hArrayList">The list of dataset server name</param> /// <returns>The image response in GeosoftXML</returns> public System.Xml.XmlDocument GetImage(Format hFormat, BoundingBox hBoundingBox, Resolution hResolution, System.Collections.ArrayList hArrayList) { return GetImage(hFormat, hBoundingBox, hResolution, hArrayList, null); }
/// <summary> /// Get an image from a list of dataset server names /// </summary> /// <param name="hFormat">The format to retrieve the image in</param> /// <param name="hBoundingBox">The bounding box of the image</param> /// <param name="hResolution">The resolution to retrive the image at</param> /// <param name="hArrayList">The list of dataset server name</param> /// <param name="progressCallBack">Progress handler (may be null)</param> /// <returns>The image response in GeosoftXML</returns> public System.Xml.XmlDocument GetImage(Format hFormat, BoundingBox hBoundingBox, Resolution hResolution, System.Collections.ArrayList hArrayList, UpdateProgessCallback progressCallBack) { return GetImage(hFormat, hBoundingBox, hResolution, false, false, hArrayList, progressCallBack); }
/// <summary> /// Get an image from a dataset /// </summary> /// <param name="hDataSet">The dataset to get an image for</param> /// <param name="hFormat">The format to retrieve the image in</param> /// <param name="hResolution">The resolution to retrieve the image at</param> /// <param name="progressCallBack">Progress handler (may be null)</param> /// <returns>The image response in GeosoftXML</returns> public System.Xml.XmlDocument GetImage(DataSet hDataSet, Format hFormat, Resolution hResolution, UpdateProgessCallback progressCallBack) { // --- check to make sure that the dataset is located on the server this command is connected to --- if (hDataSet.Url != Url) throw new DapException("The dataset is not located on this server."); System.Collections.ArrayList hArrayList = new System.Collections.ArrayList(); hArrayList.Add(hDataSet.Name); return GetImage(hFormat, hDataSet.Boundary, hResolution, hArrayList, progressCallBack); }
/// <summary> /// Get an image from a dataset /// </summary> /// <param name="hDataSet">The dataset to get an image for</param> /// <param name="hFormat">The format to retrieve the image in</param> /// <param name="hResolution">The resolution to retrieve the image at</param> /// <returns>The image response in GeosoftXML</returns> public System.Xml.XmlDocument GetImage(DataSet hDataSet, Format hFormat, Resolution hResolution) { return GetImage(hDataSet, hFormat, hResolution, null); }
/// <summary> /// Get the image for a particular dataset from the catalog item element /// </summary> /// <param name="hItem">The item element within a catalog response</param> /// <param name="hFormat">The format to retrieve the image in</param> /// <param name="hResolution">The resolution to retrieve the image at</param> /// <param name="progressCallBack">Progress handler (may be null)</param> /// <returns>The image response in GeosoftXML</returns> public System.Xml.XmlDocument GetImage(System.Xml.XmlNode hItem, Format hFormat, Resolution hResolution, UpdateProgessCallback progressCallBack) { DataSet hDataSet; BoundingBox hBoundingBox; // --- parse the data set element --- m_hParse.DataSet(hItem, out hDataSet); // --- parse the bounding box element --- m_hParse.BoundingBox(hItem.FirstChild, out hBoundingBox); hDataSet.Boundary = hBoundingBox; return GetImage(hDataSet, hFormat, hResolution, progressCallBack); }
/// <summary> /// Get the image for a particular dataset from the catalog item element /// </summary> /// <param name="hItem">The item element within a catalog response</param> /// <param name="hFormat">The format to retrieve the image in</param> /// <param name="hResolution">The resolution to retrieve the image at</param> /// <returns>The image response in GeosoftXML</returns> public System.Xml.XmlDocument GetImage(System.Xml.XmlNode hItem, Format hFormat, Resolution hResolution) { return GetImage(hItem, hFormat, hResolution, null); }
/// <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(); }