Ejemplo n.º 1
0
        private void DrawRaster(string file)
        {
            try
            {
                Logger.Debug("Start drawing tile" + file + "...");
                IRasterLayer rl = new RasterLayerClass();
                rl.CreateFromFilePath(file);
                var props = (IRasterProps)rl.Raster;
                props.SpatialReference = _dataSpatialReference;

                if (_needReproject)
                {
                    IRasterGeometryProc rasterGeometryProc = new RasterGeometryProcClass();
                    var missing = Type.Missing;
                    rasterGeometryProc.ProjectFast(_layerSpatialReference, rstResamplingTypes.RSP_NearestNeighbor, ref missing, rl.Raster);
                }

                // Fix for issue "Each 256x256 tile rendering differently causing blockly effect."
                // In 10.1 the StrecthType for rasters seems to have changed from esriRasterStretch_NONE to "Percent Clip",
                // giving color problems with 24 or 32 bits tiles.
                // http://arcbrutile.codeplex.com/workitem/11207
                var image  = new Bitmap(file, true);
                var format = image.PixelFormat;
                if (format == PixelFormat.Format24bppRgb || format == PixelFormat.Format32bppArgb || format == PixelFormat.Format32bppRgb)
                {
                    var rasterRGBRenderer = new RasterRGBRendererClass();
                    ((IRasterStretch2)rasterRGBRenderer).StretchType = esriRasterStretchTypesEnum.esriRasterStretch_NONE;
                    rl.Renderer = rasterRGBRenderer;
                }

                rl.Renderer.ResamplingType = rstResamplingTypes.RSP_BilinearInterpolation;
                // Now set the spatial reference to the dataframe spatial reference!
                // Do not remove this line...
                rl.SpatialReference = _layerSpatialReference;
                //rl.Draw(ESRI.ArcGIS.esriSystem.esriDrawPhase.esriDPGeography, (IDisplay)activeView.ScreenDisplay, null);
                rl.Draw(esriDrawPhase.esriDPGeography, _display, null);
                //activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, trackCancel, env);
                Logger.Debug("End drawing tile.");
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch (Exception)
            {
                // what to do now...
                // just try to load next tile...
            }
        }
Ejemplo n.º 2
0
        public override void Draw(esriDrawPhase drawPhase, IDisplay display, ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel)
        {
            var file = @"D:\aaa\strava_issue\2016_1350.png";

            var rl = new RasterLayerClass();

            rl.CreateFromFilePath(file);
            var props = (IRasterProps)rl.Raster;

            props.SpatialReference = new SpatialReferences().GetSpatialReference("urn: ogc:def: crs:EPSG: 6.18.3:3857");
            IRasterGeometryProc3 rasterGeometryProc = new RasterGeometryProcClass();
            var missing = Type.Missing;
            var layerSpatialReference = sp;

            rasterGeometryProc.ProjectFast(layerSpatialReference, rstResamplingTypes.RSP_NearestNeighbor, ref missing, rl.Raster);

            // fix 9/10/2015: with projected tiles color changes and transparency is ignored.
            var image = new Bitmap(file, true);
            // image.MakeTransparent(Color.White);
            //image.Save(@"D:\aaa\strava_issue\2018_1350.png");
            var format = image.PixelFormat;

            if (format == PixelFormat.Format24bppRgb | format == PixelFormat.Format32bppArgb)
            {
                var rasterRgbRenderer = new RasterRGBRendererClass();
                ((IRasterStretch2)rasterRgbRenderer).StretchType = esriRasterStretchTypesEnum.esriRasterStretch_NONE;
                // ((IRasterStretch3)rasterRgbRenderer).UseGamma = true;
                ((IRasterStretch2)rasterRgbRenderer).Background = true;
                ((IRasterStretch3)rasterRgbRenderer).UseGamma   = true;
                var r = new RgbColorClass();
                r.Red   = 49;
                r.Green = 0;
                r.Blue  = 38;
                ((IRasterStretch2)rasterRgbRenderer).BackgroundColor = r;
                //((IRasterStretch2)rasterRgbRenderer).BackgroundColor = r;

                rl.Renderer = rasterRgbRenderer;
            }
            // end fix 9/10/2015: with projected tiles color changes and transparency is ignored.

            rl.Draw(esriDrawPhase.esriDPGeography, display, null);
        }
Ejemplo n.º 3
0
        private void DrawRasterNew(string file, TileInfo tileInfo)
        {
            if (_needReproject)
            {
                var rl = new RasterLayerClass();
                rl.CreateFromFilePath(file);
                var props = (IRasterProps)rl.Raster;
                props.SpatialReference = _dataSpatialReference;
                var rasterGeometryProc = new RasterGeometryProcClass();
                var missing            = Type.Missing;
                rasterGeometryProc.ProjectFast(_layerSpatialReference, rstResamplingTypes.RSP_NearestNeighbor, ref missing, rl.Raster);

                // fix 9/10/2015: with projected tiles color changes and transparency is ignored.
                var image  = new Bitmap(file, true);
                var format = image.PixelFormat;
                if (format == PixelFormat.Format24bppRgb | format == PixelFormat.Format32bppArgb)
                {
                    var rasterRgbRenderer = new RasterRGBRendererClass();
                    ((IRasterStretch2)rasterRgbRenderer).StretchType = esriRasterStretchTypesEnum.esriRasterStretch_NONE;
                    ((IRasterStretch2)rasterRgbRenderer).Background  = true;
                    rl.Renderer = rasterRgbRenderer;
                }
                // end fix 9/10/2015: with projected tiles color changes and transparency is ignored.

                rl.Draw(esriDrawPhase.esriDPGeography, _display, null);
            }
            else
            {
                using (var fs = new System.IO.FileStream(file, FileMode.Open, FileAccess.Read))
                {
                    if (fs.Length > 100)
                    {
                        var img1 = Image.FromStream(fs, true);
                        {
                            // add check if tile needs to be clipped
                            if (ClipTilesEnvelope != null)
                            {
                                if (tileInfo.Extent.MinX <ClipTilesEnvelope.XMin |
                                                          tileInfo.Extent.MaxX> ClipTilesEnvelope.XMax |
                                    tileInfo.Extent.MinY <ClipTilesEnvelope.YMin |
                                                          tileInfo.Extent.MaxY> ClipTilesEnvelope.YMax)
                                {
                                    img1 = ImageProcessor.CropImage(img1, tileInfo, ClipTilesEnvelope);
                                }
                            }

                            if (img1 != null)
                            {
                                var ms = new MemoryStream();
                                img1.Save(ms, ImageFormat.Png);
                                var bytes1 = ms.ToArray();
                                var ul     = new PointClass()
                                {
                                    X = tileInfo.Extent.MinX, Y = tileInfo.Extent.MaxY
                                };
                                var lr = new PointClass()
                                {
                                    X = tileInfo.Extent.MaxX, Y = tileInfo.Extent.MinY
                                };
                                ImageDrawer.Draw(_display, bytes1, ul, lr);
                                img1.Dispose();
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        private static void DrawRaster(string file)
        {
            try{
                Stopwatch timer = new Stopwatch();
                timer.Start();
                IRasterLayer rl;
                if (!layers.ContainsKey(file)){

                    Logger.Debug("Start drawing tile" + file + "...");
                    rl = new RasterLayerClass();

                    rl.CreateFromFilePath(file);
                    var props = (IRasterProps) rl.Raster;
                    props.SpatialReference = _dataSpatialReference;

                    if (_needReproject){
                        IRasterGeometryProc rasterGeometryProc = new RasterGeometryProcClass();
                        var missing = Type.Missing;
                        rasterGeometryProc.ProjectFast(_layerSpatialReference, rstResamplingTypes.RSP_NearestNeighbor,
                                                       ref missing, rl.Raster);
                    }

                    // Fix for issue "Each 256x256 tile rendering differently causing blockly effect."
                    // In 10.1 the StrecthType for rasters seems to have changed from esriRasterStretch_NONE to "Percent Clip",
                    // giving color problems with 24 or 32 bits tiles.
                    // http://arcbrutile.codeplex.com/workitem/11207
                    var image = new Bitmap(file, true);
                    var format = image.PixelFormat;
                    if (format == PixelFormat.Format24bppRgb || format == PixelFormat.Format32bppRgb){
                        var rasterRGBRenderer = new RasterRGBRendererClass();
                        ((IRasterStretch2) rasterRGBRenderer).StretchType =
                            esriRasterStretchTypesEnum.esriRasterStretch_NONE;
                        rl.Renderer = rasterRGBRenderer;
                    }

                    rl.Renderer.ResamplingType = rstResamplingTypes.RSP_BilinearInterpolation;
                    // Now set the spatial reference to the dataframe spatial reference!
                    // Do not remove this line...
                    rl.SpatialReference = _layerSpatialReference;

                    timer.Stop();
                    Logger.Debug(file + "读取花费时间:" + timer.Elapsed.Milliseconds);
                    layers.Add(file,rl);
                    layerNames.Enqueue(file);
                    if (layerNames.Count > 100){
                        string tempname = layerNames.Dequeue();
                        layers.Remove(tempname);
                    }
                }
                else{
                    layers.TryGetValue(file, out rl);
                    timer.Stop();
                    Logger.Debug(file+"查询花费时间:" + timer.Elapsed.Milliseconds);
                }
                timer.Reset();

                //rl.Draw(ESRI.ArcGIS.esriSystem.esriDrawPhase.esriDPGeography, (IDisplay)activeView.ScreenDisplay, null);
                rl.Draw(esriDrawPhase.esriDPGeography, _display, null);
                //activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, trackCancel, env);
                timer.Stop();
                Logger.Debug(file + "绘制花费时间:" + timer.Elapsed.Milliseconds);
                //Logger.Debug("End drawing tile.");

            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch (Exception)
            {
                // what to do now...
                // just try to load next tile...
            }
        }
 public IFunctionRasterDataset reprojectRasterFunction(object inRaster,ISpatialReference spatialReference)
 {
     IRaster2 rs = (IRaster2)returnRaster(inRaster);
     IRasterGeometryProc3 geoP3 = new RasterGeometryProcClass();
     object cellSize = Type.Missing;
     geoP3.ProjectFast(spatialReference,rstResamplingTypes.RSP_NearestNeighbor,cellSize,(IRaster)rs);
     return createIdentityRaster(rs);
 }