Example #1
0
        internal static Stream OverDAP(string dapUrl, string requestXML)
        {
            SearchRequest request = Decoder.SearchRequest(requestXML);

            Geosoft.Dap.Command c = new Geosoft.Dap.Command(dapUrl, false, Geosoft.Dap.Command.Version.GEOSOFT_XML_1_1, false, DapSecureToken.Instance, 30000);
            ArrayList datasets; c.GetCatalog(null, 0, request.Offset, request.MaxCount, request.TextFilter, request.AoIFilter, out datasets);
            int totalResults; c.GetDataSetCount(null, 0, request.Offset, request.MaxCount, request.TextFilter, request.AoIFilter, out totalResults);

            SearchResults result = new SearchResults(request.Version, request.Handle, request.Offset, totalResults);
            cachedData.Clear();
            foreach (DataSet d in datasets)
            {
                result.AddResult(new DAPLayer(d));
                cachedData.Add(int.Parse(d.Name), d);
            }

            return Encoder.SearchResults(result);
        }
Example #2
0
        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;
        }
Example #3
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="oLayersToDownload"></param>
        internal DatasetDisclaimer(List<Dapple.LayerGeneration.LayerBuilder> oLayersToDownload, System.Xml.XmlDocument oDownload)
        {
            InitializeComponent();

             string strTempFile = System.IO.Path.GetTempFileName();
             System.Xml.XmlReader oReader = null;

             foreach (Dapple.LayerGeneration.LayerBuilder oBuilder in oLayersToDownload)
             {
                if (oBuilder is Dapple.LayerGeneration.DAPQuadLayerBuilder && ((Dapple.LayerGeneration.DAPQuadLayerBuilder)oBuilder).ServerMajorVersion >= 11)
            {
               Dapple.LayerGeneration.DAPQuadLayerBuilder oDAPbuilder = (Dapple.LayerGeneration.DAPQuadLayerBuilder)oBuilder;

               Geosoft.Dap.Command oCommand = new Geosoft.Dap.Command(oDAPbuilder.ServerURL, false, Geosoft.Dap.Command.Version.GEOSOFT_XML_1_1, WorldWind.Net.WebDownload.DownloadTimeout);
               Geosoft.Dap.Common.DataSet oDataset = new Geosoft.Dap.Common.DataSet();
               oDataset.Name = oDAPbuilder.DatasetName;
               oDataset.Url = oDAPbuilder.ServerURL;

                    System.Xml.XmlDocument oDoc = null;
                    try
                    {
                        oDoc = oCommand.GetDisclaimer(oDataset);
                    }
                    catch (System.Net.WebException ex)
                    {
                        ex.Data["dataset"] = oBuilder.Title;
                        throw;
                    }
                    oDoc.Save(strTempFile);
                    oReader = System.Xml.XmlReader.Create(strTempFile);

               if (oReader.ReadToFollowing("disclaimer"))
               {
                  if (string.Compare(oReader.GetAttribute("value"), "true", true) == 0)
                  {
                     // --- read the base 64 encoded text into a temporary file ---

                     string strTempHtmFile = System.IO.Path.GetTempFileName();
                     System.IO.FileStream oOutputStream = new System.IO.FileStream(strTempHtmFile, System.IO.FileMode.Create);

                     byte[] bBuffer = new byte[65536];
                     int iCount = 0;

                     do
                     {
                        iCount = oReader.ReadElementContentAsBase64(bBuffer, 0, 65536);
                        oOutputStream.Write(bBuffer, 0, iCount);
                     } while (iCount != 0);

                     // --- close the output stream ---

                     if (oOutputStream != null)
                        oOutputStream.Close();
                     oOutputStream = null;

                     ListViewItem oItem = new ListViewItem();
                     oItem.Name = oDAPbuilder.DatasetName;
                            oItem.Text = oDAPbuilder.Title;
                     oItem.Tag = strTempHtmFile;
                     lvDatasets.Items.Add(oItem);
                  }
               }
               oReader.Close();
            }
             }
             System.IO.File.Delete(strTempFile);

             if (lvDatasets.Items.Count > 0)
             {
                lvDatasets.Items[0].Selected = true;
                wbDisclaimer.Navigate(lvDatasets.Items[0].Tag as string);
             }
        }
Example #4
0
        /// <summary>
        /// Default constructor
        /// </summary>
        /// <param name="oLayersToDownload"></param>
        internal DatasetDisclaimer(List <Dapple.LayerGeneration.LayerBuilder> oLayersToDownload, System.Xml.XmlDocument oDownload)
        {
            InitializeComponent();

            string strTempFile = System.IO.Path.GetTempFileName();

            System.Xml.XmlReader oReader = null;

            foreach (Dapple.LayerGeneration.LayerBuilder oBuilder in oLayersToDownload)
            {
                if (oBuilder is Dapple.LayerGeneration.DAPQuadLayerBuilder && ((Dapple.LayerGeneration.DAPQuadLayerBuilder)oBuilder).ServerMajorVersion >= 11)
                {
                    Dapple.LayerGeneration.DAPQuadLayerBuilder oDAPbuilder = (Dapple.LayerGeneration.DAPQuadLayerBuilder)oBuilder;

                    Geosoft.Dap.Command        oCommand = new Geosoft.Dap.Command(oDAPbuilder.ServerURL, false, Geosoft.Dap.Command.Version.GEOSOFT_XML_1_1, WorldWind.Net.WebDownload.DownloadTimeout);
                    Geosoft.Dap.Common.DataSet oDataset = new Geosoft.Dap.Common.DataSet();
                    oDataset.Name = oDAPbuilder.DatasetName;
                    oDataset.Url  = oDAPbuilder.ServerURL;

                    System.Xml.XmlDocument oDoc = null;
                    try
                    {
                        oDoc = oCommand.GetDisclaimer(oDataset);
                    }
                    catch (System.Net.WebException ex)
                    {
                        ex.Data["dataset"] = oBuilder.Title;
                        throw;
                    }
                    oDoc.Save(strTempFile);
                    oReader = System.Xml.XmlReader.Create(strTempFile);

                    if (oReader.ReadToFollowing("disclaimer"))
                    {
                        if (string.Compare(oReader.GetAttribute("value"), "true", true) == 0)
                        {
                            // --- read the base 64 encoded text into a temporary file ---

                            string strTempHtmFile = System.IO.Path.GetTempFileName();
                            System.IO.FileStream oOutputStream = new System.IO.FileStream(strTempHtmFile, System.IO.FileMode.Create);

                            byte[] bBuffer = new byte[65536];
                            int    iCount  = 0;

                            do
                            {
                                iCount = oReader.ReadElementContentAsBase64(bBuffer, 0, 65536);
                                oOutputStream.Write(bBuffer, 0, iCount);
                            } while (iCount != 0);


                            // --- close the output stream ---

                            if (oOutputStream != null)
                            {
                                oOutputStream.Close();
                            }
                            oOutputStream = null;

                            ListViewItem oItem = new ListViewItem();
                            oItem.Name = oDAPbuilder.DatasetName;
                            oItem.Text = oDAPbuilder.Title;
                            oItem.Tag  = strTempHtmFile;
                            lvDatasets.Items.Add(oItem);
                        }
                    }
                    oReader.Close();
                }
            }
            System.IO.File.Delete(strTempFile);

            if (lvDatasets.Items.Count > 0)
            {
                lvDatasets.Items[0].Selected = true;
                wbDisclaimer.Navigate(lvDatasets.Items[0].Tag as string);
            }
        }