Inheritance: Geometry, IRaster
Example #1
0
        public IEnumerable<IFeature> FetchTiles(BoundingBox boundingBox, double resolution)
        {
            var extent = new Extent(boundingBox.Min.X, boundingBox.Min.Y, boundingBox.Max.X, boundingBox.Max.Y);
            var levelId = BruTile.Utilities.GetNearestLevel(_source.Schema.Resolutions, resolution);
            var infos = _source.Schema.GetTileInfos(extent, levelId).ToList();

            ICollection<WaitHandle> waitHandles = new List<WaitHandle>();
                        
            foreach (TileInfo info in infos)    
            {
                if (_bitmaps.Find(info.Index) != null) continue;
                if (_queue.Contains(info.Index)) continue;
                var waitHandle = new AutoResetEvent(false);
                waitHandles.Add(waitHandle);
                _queue.Add(info.Index);
                ThreadPool.QueueUserWorkItem(GetTileOnThread, new object[] { _source, info, _bitmaps, waitHandle });
            }

            WaitHandle.WaitAll(waitHandles.ToArray());
            
            IFeatures features = new Features();
            foreach (TileInfo info in infos)
            {
                byte[] bitmap = _bitmaps.Find(info.Index);
                if (bitmap == null) continue;
                IRaster raster = new Raster(new MemoryStream(bitmap), new BoundingBox(info.Extent.MinX, info.Extent.MinY, info.Extent.MaxX, info.Extent.MaxY));
                IFeature feature = features.New();
                feature.Geometry = raster;
                features.Add(feature);
            }
            return features;
        }
        /// <summary>
        /// Retrieves the bitmap from ArcGIS Dynamic service
        /// </summary>
        public bool TryGetMap(IViewport viewport, ref IRaster raster)
        {
            int width;
            int height;

            try
            {
                width = Convert.ToInt32(viewport.Width);
                height = Convert.ToInt32(viewport.Height);
            }
            catch (OverflowException)
            {
                Trace.Write("Could not conver double to int (ExportMap size)");
                return false;
            }
           
            var uri = new Uri(GetRequestUrl(viewport.Extent, width, height));
            var request = WebRequest.Create(uri);
            request.Method = "GET";
            request.Timeout = timeOut;
            request.Credentials = Credentials ?? CredentialCache.DefaultCredentials;

            try
            {
                var myWebResponse = (HttpWebResponse)request.GetResponse();
                var dataStream = myWebResponse.GetResponseStream();

                var bytes = BruTile.Utilities.ReadFully(myWebResponse.GetResponseStream());
                raster = new Raster(new MemoryStream(bytes), viewport.Extent);
                if (dataStream != null) dataStream.Close();

                myWebResponse.Close();
                return true;
            }
            catch (WebException webEx)
            {
                Trace.Write("There was a problem connecting to the ArcGIS server: " + webEx.Message);
            }
            catch (Exception ex)
            {
                Trace.Write("There was a problem while attempting to request the ArcGIS layer" + ex.Message);
            }

            return false;
        }
        public bool TryGetMap(IViewport viewport, ref IRaster raster)
        {
            int width;
            int height;

            try
            {
                width = Convert.ToInt32(viewport.Width);
                height = Convert.ToInt32(viewport.Height);
            }
            catch (OverflowException ex)
            {
                Logger.Log(LogLevel.Error, "Could not convert double to int (ExportMap size)", ex);
                return false;
            }

            var uri = new Uri(GetRequestUrl(viewport.Extent, width, height));
            var webRequest =  (HttpWebRequest)WebRequest.Create(uri);

            if (Credentials == null)
                webRequest.UseDefaultCredentials = true;
            else
                webRequest.Credentials = Credentials;

            try
            {
                var myWebResponse = webRequest.GetSyncResponse(_timeOut);

               using (var dataStream = myWebResponse.GetResponseStream())
               {
                   try
                   {
                       var bytes = BruTile.Utilities.ReadFully(dataStream);
                       raster = new Raster(new MemoryStream(bytes), viewport.Extent);
                   }
                   catch (Exception ex)
                   {
                        Logger.Log(LogLevel.Error, ex.Message, ex);
                        return false;
                   }
               }
               return true;
            }
            catch (WebException ex)
            {
                Logger.Log(LogLevel.Warning, ex.Message, ex);
                if (!ContinueOnError)
                    throw (new RenderException(
                        "There was a problem connecting to the ArcGISImage server",
                        ex));
                Debug.WriteLine("There was a problem connecting to the WMS server: " + ex.Message);
            }
            catch (Exception ex)
            {
                if (!ContinueOnError)
                    throw (new RenderException("There was a problem while attempting to request the WMS", ex));
                Debug.WriteLine("There was a problem while attempting to request the WMS" + ex.Message);
            }
            return false;
        }
Example #4
0
        public bool TryGetMap(IViewport viewport, ref IRaster raster)
        {

            int width;
            int height;

            try
            {
                width = Convert.ToInt32(viewport.Width);
                height = Convert.ToInt32(viewport.Height);
            }
            catch (OverflowException)
            {
                Trace.Write("Could not conver double to int (ExportMap size)");
                return false;
            }

            var url = GetRequestUrl(viewport.Extent, width, height);

            try
            {
                using (var task = _getStreamAsync(url))
                {
                    // PDD: This could be more efficient
                    var bytes = BruTile.Utilities.ReadFully(task.Result);                    
                    raster = new Raster(new MemoryStream(bytes), viewport.Extent);
                    task.Result.Close();
                }
                return true;
            }
            catch (WebException webEx)
            {
                if (!ContinueOnError)
                    throw (new RenderException(
                        "There was a problem connecting to the WMS server",
                        webEx));
                Trace.Write("There was a problem connecting to the WMS server: " + webEx.Message);
            }
            catch (Exception ex)
            {
                if (!ContinueOnError)
                    throw (new RenderException("There was a problem while attempting to request the WMS", ex));
                Trace.Write("There was a problem while attempting to request the WMS" + ex.Message);
            }
            return false;
        }
        public bool TryGetMap(IViewport viewport, ref IRaster raster)
        {
            int width;
            int height;

            try
            {
                width = Convert.ToInt32(viewport.Width);
                height = Convert.ToInt32(viewport.Height);
            }
            catch (OverflowException)
            {
                Trace.Write("Could not convert double to int (ExportMap size)");
                return false;
            }

            var uri = new Uri(GetRequestUrl(viewport.Extent, width, height));
            WebRequest webRequest = WebRequest.Create(uri);

            try
            {
                using (var webResponse = (HttpWebResponse)webRequest.GetResponse())
                using (var dataStream = webResponse.GetResponseStream())
                {
                    if (!webResponse.ContentType.StartsWith("image")) return false;

                    byte[] bytes = BruTile.Utilities.ReadFully(dataStream);
                    raster = new Raster(new MemoryStream(bytes), viewport.Extent);
                }
                return true;
            }
            catch (WebException webEx)
            {
                if (!ContinueOnError)
                    throw (new RenderException(
                        "There was a problem connecting to the WMS server",
                        webEx));
                Trace.Write("There was a problem connecting to the WMS server: " + webEx.Message);
            }
            catch (Exception ex)
            {
                if (!ContinueOnError)
                    throw (new RenderException("There was a problem while attempting to request the WMS", ex));
                Trace.Write("There was a problem while attempting to request the WMS" + ex.Message);
            }
            return false;
        }
        /// <summary>
        /// Retrieves the bitmap from ArcGIS Dynamic service
        /// </summary>
        public bool TryGetMap(IViewport viewport, ref IRaster raster)
        {
            int width;
            int height;

            try
            {
                width = Convert.ToInt32(viewport.Width);
                height = Convert.ToInt32(viewport.Height);
            }
            catch (OverflowException)
            {
                Debug.WriteLine("Could not conver double to int (ExportMap size)");
                return false;
            }
           
            var uri = new Uri(GetRequestUrl(viewport.Extent, width, height));
            var request = (HttpWebRequest)WebRequest.Create(uri);
            if (Credentials == null)
                request.UseDefaultCredentials = true;
            else
                request.Credentials = Credentials;

            try
            {
                var myWebResponse = request.GetSyncResponse(_timeOut);
                var dataStream = myWebResponse.GetResponseStream();

                var bytes = BruTile.Utilities.ReadFully(myWebResponse.GetResponseStream());
                raster = new Raster(new MemoryStream(bytes), viewport.Extent);
                if (dataStream != null) dataStream.Dispose();

                myWebResponse.Dispose();
                return true;
            }
            catch
            {
                return false;
            }
        }