示例#1
0
        public GeoTiffProvider(string tiffPath, List <Color>?noDataColors = null)
        {
            if (!File.Exists(tiffPath))
            {
                throw new ArgumentException($"Tiff file expected at {tiffPath}");
            }

            var worldPath = GetPathWithoutExtension(tiffPath) + WorldExtension;

            if (!File.Exists(worldPath))
            {
                throw new ArgumentException($"World file expected at {worldPath}");
            }

            var tiffProperties  = LoadTiff(tiffPath);
            var worldProperties = LoadWorld(worldPath);

            _extent = CalculateExtent(tiffProperties, worldProperties);

            using var data = ReadImageAsStream(tiffPath, noDataColors);

            _mRaster = new MRaster(data.ToArray(), _extent);
            _feature = new RasterFeature(_mRaster);
            _feature.Styles.Add(new VectorStyle());
        }
示例#2
0
        private static List <RasterFeature> TileIndexToFeatures(TileIndex[] tileIndexes, ITileSource tileSource)
        {
            var features = new List <RasterFeature>();

            foreach (var tileIndex in tileIndexes)
            {
                var tileInfo = new TileInfo
                {
                    Index  = tileIndex,
                    Extent = TileTransform.TileToWorld(
                        new TileRange(tileIndex.Col, tileIndex.Row), tileIndex.Level, tileSource.Schema)
                };

                var raster = new MRaster(tileSource.GetTile(tileInfo), tileInfo.Extent.ToMRect());
                features.Add(new RasterFeature(raster));
            }
            return(features);
        }
示例#3
0
        public bool TryGetMap(IViewport viewport, [NotNullWhen(true)] out MRaster?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)");
                raster = null;
                return(false);
            }

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

            try
            {
                if (_getStreamAsync == null)
                {
                    raster = null;
                    return(false);
                }

                using var task   = _getStreamAsync(url);
                using var result = task.Result;
                // PDD: This could be more efficient
                var bytes = StreamHelper.ReadFully(result);
                if (viewport.Extent == null)
                {
                    raster = null;
                    return(false);
                }
                raster = new MRaster(bytes, viewport.Extent);   // This can throw exception
                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);
            }

            raster = null;
            return(false);
        }
示例#4
0
        public async Task <(bool Success, MRaster?)> TryGetMapAsync(IViewport viewport)
        {
            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, null);
            }

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

            try
            {
                var bytes = _persistentCache?.Find(url);
                if (bytes == null)
                {
                    if (_getStreamAsync == null)
                    {
                        return(false, null);
                    }

                    using var result = await _getStreamAsync(url);

                    // PDD: This could be more efficient
                    bytes = StreamHelper.ReadFully(result);
                    _persistentCache?.Add(url, bytes);
                }

                if (viewport.Extent == null)
                {
                    return(false, null);
                }
                var raster = new MRaster(bytes, viewport.Extent);       // This can throw exception
                return(true, raster);
            }
            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, null);
        }