Ejemplo n.º 1
0
        private void AddTileToBitmap(Bitmap map, List <Stream> tileStreamList, ReportDefintion reportDefinition, TileDefinition tile, List <TileDefinition> tiles)
        {
            int x = tiles.Where(t => (t.col < tile.col) && (t.row == tile.row)).Sum(t => t.TileWidth);
            int y = tiles.Where(t => (t.row > tile.row) && (t.col == tile.col)).Sum(t => t.TileHeight);

            foreach (Stream tileStream in tileStreamList)
            {
                using (Graphics graphics = Graphics.FromImage(map))
                {
                    graphics.SmoothingMode = SmoothingMode.HighQuality;
                    Bitmap temp = new Bitmap(tileStream);
                    //graphics.DrawImage(temp, tilePosition.xPos, tilePosition.yPos, map.Width / reportDefinition.numberOfTiles, map.Height / reportDefinition.numberOfTiles);
                    graphics.DrawImage(temp, x, y, tile.TileWidth, tile.TileHeight);
                    temp.Dispose();
                    tileStream.Close();
                    tileStream.Dispose();
                }
            }
        }
Ejemplo n.º 2
0
        private SizeF DrawString(Graphics graphics, string text, System.Drawing.Point position, ReportDefintion reportDefinition, int fontType = 0, bool drawString = true)
        {
            Font       font;
            SolidBrush brush = new SolidBrush(Color.Black);

            graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
            switch (fontType)
            {
            case 1:
                font = Fontstyles.getHadlineFont();
                break;

            default:
                font = Fontstyles.getDefaultFont();
                break;
            }
            SizeF size = graphics.MeasureString(text, font);

            if (drawString)
            {
                StringFormat format = new StringFormat();
                format.Trimming = StringTrimming.None;
                RectangleF rect = new RectangleF(position, size);
                graphics.DrawString(text, font, brush, rect);
            }


            return(size);
        }
Ejemplo n.º 3
0
        private SizeF CalcAndDrawInfoImage(Bitmap infoImage, string[] layers, EmsgGisReportParameter reportparams, bool drawImage, ReportDefintion reportDefinition)
        {
            InfoImageHeightAndCurrentPosition currentPosAndSize       = new InfoImageHeightAndCurrentPosition(reportDefinition.dpi);
            ServerConfigurationProvider       serverConfigurationProv = new ServerConfigurationProvider();

            using (Graphics graphics = Graphics.FromImage(infoImage))
            {
                graphics.SmoothingMode = SmoothingMode.HighQuality;
                #region setFilterparams

                currentPosAndSize.IncreaseSizeAndPositionY(DrawString(graphics, localizationService.GetLocalizedLegendLabel("Filterparameter"), currentPosAndSize.GetCurrentPosition(), reportDefinition, 1, drawImage));
                currentPosAndSize.IncreaseHeightAndPositionY(SpaceAndOffsets.getSpaceYBetweenHeadline(reportDefinition.dpi));

                float valueOffset = 0;
                if (reportparams != null)
                {
                    foreach (FilterListPo filterItem in reportparams.Filterparams)
                    {
                        valueOffset = Math.Max(valueOffset, graphics.MeasureString(filterItem.Name, Fontstyles.getDefaultFont()).Width);
                    }

                    foreach (FilterListPo filterItem in reportparams.Filterparams)
                    {
                        Point filterNamePos  = new Point(currentPosAndSize.GetCurrentPosition().X, currentPosAndSize.GetCurrentPosition().Y);
                        Point filterValuePos = new Point(currentPosAndSize.GetCurrentPosition().X + Convert.ToInt32(valueOffset), currentPosAndSize.GetCurrentPosition().Y);

                        SizeF filterparamSize = DrawString(graphics, filterItem.Name + ":", filterNamePos, reportDefinition, drawString: drawImage);
                        SizeF filterValueSize = DrawString(graphics, " " + filterItem.Value, filterValuePos, reportDefinition, drawString: drawImage);

                        SizeF lineSize = new SizeF(filterparamSize.Width + filterValueSize.Width,
                                                   filterparamSize.Height < filterValueSize.Height ? filterValueSize.Height : filterparamSize.Height);

                        currentPosAndSize.IncreaseSizeAndPositionY(lineSize);
                        currentPosAndSize.IncreaseHeightAndPositionY(SpaceAndOffsets.getSpaceYBetweenLayers(reportDefinition.dpi));
                    }
                }

                #endregion

                Point lineStart = new Point(0, currentPosAndSize.GetCurrentPosition().Y + SpaceAndOffsets.getSpaceYBetweenLegendAndFilter(reportDefinition.dpi) / 2);
                Point lineEnd   = new Point(infoImage.Width - 2, currentPosAndSize.GetCurrentPosition().Y + SpaceAndOffsets.getSpaceYBetweenLegendAndFilter(reportDefinition.dpi) / 2);
                graphics.DrawLine(new Pen(Color.Black, (int)Math.Ceiling(0.01 * reportDefinition.dpi)), lineStart, lineEnd);

                currentPosAndSize.IncreaseHeightAndPositionY(SpaceAndOffsets.getSpaceYBetweenLegendAndFilter(reportDefinition.dpi));

                #region set legend

                if (!layers.IsEmpty())
                {
                    currentPosAndSize.IncreaseSizeAndPositionY(DrawString(graphics, localizationService.GetLocalizedLegendLabel("Legende"), currentPosAndSize.GetCurrentPosition(), reportDefinition, 1, drawImage));
                    currentPosAndSize.IncreaseHeightAndPositionY(SpaceAndOffsets.getSpaceYBetweenHeadline(reportDefinition.dpi));


                    foreach (var layer in layers)
                    {
                        string layername = layer;
                        Tuple <string, string> info;
                        if (this.layerInfo.TryGetValue(layername, out info))
                        {
                            layername = info.Item2;
                        }
                        currentPosAndSize.IncreaseSizeAndPositionY(DrawString(graphics, layername, currentPosAndSize.GetCurrentPosition(), reportDefinition, 2, drawImage));
                        Bitmap bm = new Bitmap(this.GetLegendStream(layer, dpi: reportDefinition.dpi, reportParameter: reportparams));
                        bm.SetResolution(reportDefinition.dpi, reportDefinition.dpi);
                        if (drawImage)
                        {
                            graphics.DrawImage(bm, currentPosAndSize.GetCurrentPosition().X, currentPosAndSize.GetCurrentPosition().Y);
                        }
                        currentPosAndSize.IncreaseSizeAndPositionY(new SizeF(bm.Width, bm.Height));
                        currentPosAndSize.IncreaseHeightAndPositionY(SpaceAndOffsets.getSpaceYBetweenLayers(reportDefinition.dpi));
                    }

                    lineStart = new Point(0, currentPosAndSize.GetCurrentPosition().Y + SpaceAndOffsets.getSpaceYBetweenLegendAndFilter(reportDefinition.dpi) / 2);
                    lineEnd   = new Point(infoImage.Width - 2, currentPosAndSize.GetCurrentPosition().Y + SpaceAndOffsets.getSpaceYBetweenLegendAndFilter(reportDefinition.dpi) / 2);
                    graphics.DrawLine(new Pen(Color.Black, (int)Math.Ceiling(0.01 * reportDefinition.dpi)), lineStart, lineEnd);

                    currentPosAndSize.IncreaseHeightAndPositionY(SpaceAndOffsets.getSpaceYBetweenLegendAndFilter(reportDefinition.dpi));
                    currentPosAndSize.IncreaseSizeAndPositionY(DrawString(graphics, localizationService.GetLocalizedLegendLabel("MapReportRedBox"), currentPosAndSize.GetCurrentPosition(), reportDefinition, drawString: drawImage));
                    //margin: resolutions not in multiple of 300 dpi may cause rounding errors resulting in 1 pixel of the MapReportRedBox text to be cut of, therefore safity margin
                    currentPosAndSize.IncreaseHeightAndPositionY(SpaceAndOffsets.getSpaceYMargin(reportDefinition.dpi));
                }
                #endregion
            }

            return(currentPosAndSize.GetInfoImageSize());
        }
Ejemplo n.º 4
0
        public Bitmap FormatLegendForReport(string layerList, EmsgGisReportParameter reportparams, ReportDefintion reportDefinition)
        {
            ServerConfigurationProvider serverConfigurationProv = new ServerConfigurationProvider();

            string[] layerToShow = layerList.Split(',');
            //calc legendBitmap
            Bitmap legendBitmap = new Bitmap(5, 5);

            legendBitmap.SetResolution(reportDefinition.dpi, reportDefinition.dpi);
            SizeF legendBitmapSize = CalcAndDrawInfoImage(legendBitmap, layerToShow, reportparams, false, reportDefinition);

            //create/draw legendBitmap
            legendBitmapSize.Width += (float)Math.Ceiling(0.05 * reportDefinition.dpi); //add buffer
            legendBitmap            = new Bitmap(Convert.ToInt32(legendBitmapSize.Width), Convert.ToInt32(legendBitmapSize.Height));
            legendBitmap.SetResolution(reportDefinition.dpi, reportDefinition.dpi);
            CalcAndDrawInfoImage(legendBitmap, layerToShow, reportparams, true, reportDefinition);

            return(legendBitmap);
        }
Ejemplo n.º 5
0
 public Bitmap FormatLegendForReport(string layerList, EmsgGisReportParameter reportparams, ReportDefintion reportDefinition)
 {
     return(null);
 }
Ejemplo n.º 6
0
        public List <Stream> PrepareAndSendWMSRequests(EmsgGisReportParameter emsgGisReportParameter, TileDefinition tile, int dpi, bool isPreview)
        {
            List <Stream>        responseStreamList = new List <Stream>();
            List <Thread>        threads            = new List <Thread>();
            List <RequestWorker> workers            = new List <RequestWorker>();

            #region request background tile
            if (!string.IsNullOrEmpty(emsgGisReportParameter.BackgroundLayers))
            {
                WMSParameter wmsBackrParameter = new WMSParameter(LAYERS: emsgGisReportParameter.BackgroundLayers,
                                                                  BBOX: tile.ExtentToString(),
                                                                  HEIGHT: tile.TileHeight.ToString(),
                                                                  WIDTH: tile.TileWidth.ToString(),
                                                                  FORMAT: isPreview ? "jpeg" : "png24");
                //HttpResponseObject tileResponseBackground = createWMSRequest.WMSRequest(WMSRequestType.BackgroundLayer, wmsBackrParameter);
                RequestWorker worker = new RequestWorker(0, wmsBackrParameter, this.createWMSRequest, HttpContext.Current, WMSRequestType.BackgroundLayer);
                Thread        thread = new Thread(new ThreadStart(worker.Run));
                thread.Start();
                threads.Add(thread);
                workers.Add(worker);
                //if (ValidateResponse(tileResponseBackground))
                //    responseStreamList.Add(tileResponseBackground.responseStream);
            }
            else
            {
                WMSParameter wmsAVBackgroundParameter = new WMSParameter(LAYERS: emsgGisReportParameter.LayersAVBackground,
                                                                         BBOX: tile.ExtentToString(),
                                                                         HEIGHT: tile.TileHeight.ToString(),
                                                                         WIDTH: tile.TileWidth.ToString(),
                                                                         FORMAT: "image/png");

                //HttpResponseObject tileResponseAVBackground = createWMSRequest.WMSRequest(WMSRequestType.AVCLayer, wmsAVBackgroundParameter);
                RequestWorker worker = new RequestWorker(0, wmsAVBackgroundParameter, this.createWMSRequest, HttpContext.Current, WMSRequestType.AVCLayer);
                Thread        thread = new Thread(new ThreadStart(worker.Run));
                thread.Start();
                threads.Add(thread);
                workers.Add(worker);
                //if(ValidateResponse(tileResponseAVBackground))
                //    responseStreamList.Add(tileResponseAVBackground.responseStream);
            }
            #endregion



            #region request AV tile
            if (emsgGisReportParameter.LayersAV != null)
            {
                var reportDefinition = new ReportDefintion(dpi);

                bool containsHausnummernLayer = false;

                var avLayer = emsgGisReportParameter.LayersAV.Split(',').ToList();

                containsHausnummernLayer = avLayer.Remove(new ServerConfigurationProvider().AvUeberlagerndLayers);

                //the Layer "Hausnummer" aka "ch.bfs.gebaeude_wohnungs_register-label" this layer only contains labels Because we request high resolution images this labels become unreadable small so this layer is requested with "low dpi" and then resized
                #region request Hausnummer tile
                if (containsHausnummernLayer)
                {
                    int reducedTileHeight = (int)Math.Ceiling((tile.TileHeight / reportDefinition.dpi * 120d));
                    int reducedTileWidth  = (int)Math.Ceiling((tile.TileWidth / reportDefinition.dpi * 120d));

                    WMSParameter wmsAVHNParameter = new WMSParameter(LAYERS: new ServerConfigurationProvider().AvUeberlagerndLayers,
                                                                     BBOX: tile.ExtentToString(),
                                                                     HEIGHT: reducedTileHeight.ToString(),
                                                                     WIDTH: reducedTileWidth.ToString());

                    //HttpResponseObject tileResponseAVHN = createWMSRequest.WMSRequest(WMSRequestType.AVLayer, wmsAVHNParameter);
                    RequestWorker worker = new RequestWorker(1, wmsAVHNParameter, this.createWMSRequest, HttpContext.Current, WMSRequestType.AVLayer);
                    Thread        thread = new Thread(new ThreadStart(worker.Run));
                    thread.Start();
                    threads.Add(thread);
                    workers.Add(worker);
                    //if (ValidateResponse(tileResponseAVHN))
                    //    responseStreamList.Add(resizeBitmap(tileResponseAVHN.responseStream, tile.TileHeight, tile.TileWidth));
                }


                string avLayerToDownload = string.Join(",", avLayer);

                WMSParameter wmsAVParameter = new WMSParameter(LAYERS: avLayerToDownload,
                                                               BBOX: tile.ExtentToString(),
                                                               HEIGHT: tile.TileHeight.ToString(),
                                                               WIDTH: tile.TileWidth.ToString());

                //HttpResponseObject tileResponseAV = createWMSRequest.WMSRequest(WMSRequestType.AVLayer, wmsAVParameter);
                RequestWorker avworker = new RequestWorker(2, wmsAVParameter, this.createWMSRequest, HttpContext.Current, WMSRequestType.AVLayer);
                Thread        avthread = new Thread(new ThreadStart(avworker.Run));
                avthread.Start();
                threads.Add(avthread);
                workers.Add(avworker);
                //if (ValidateResponse(tileResponseAV))
                //    responseStreamList.Add(resizeBitmap(tileResponseAV.responseStream, tile.TileHeight, tile.TileWidth));



                #endregion request Hausnummer tile
            }
            #endregion

            #region request EMSG feature tile
            if (emsgGisReportParameter.Layers != null)
            {
                var emsgLayers = emsgGisReportParameter.Layers.Split(',').ToList();
                emsgLayers.Reverse();
                string emsgLayersToDownload = string.Join(",", emsgLayers);

                WMSRestParameter wmsParameter = new WMSRestParameter(emsgLayersToDownload,
                                                                     tile.ExtentToString(),
                                                                     tile.TileSizeToString(),
                                                                     layerdefs: emsgGisReportParameter.LayerDefs,
                                                                     dpi: dpi.ToString());

                //HttpResponseObject tileResponseEMSGFeatures = createWMSRequest.WMSRequest(WMSRequestType.OverlayEMSGLayer, wmsParameter);
                RequestWorker worker = new RequestWorker(3, wmsParameter, this.createWMSRequest, HttpContext.Current, WMSRequestType.OverlayEMSGLayer);
                Thread        thread = new Thread(new ThreadStart(worker.Run));
                thread.Start();
                threads.Add(thread);
                workers.Add(worker);

                //if (ValidateResponse(tileResponseEMSGFeatures))
                //    responseStreamList.Add(tileResponseEMSGFeatures.responseStream);
            }
            #endregion


            foreach (Thread thread in threads)
            {
                thread.Join();
            }
            workers = workers.OrderBy(w => w.order).ToList();
            foreach (RequestWorker worker in workers)
            {
                if (worker.exception != null)
                {
                    throw worker.exception;
                }
                if (ValidateResponse(worker.response))
                {
                    responseStreamList.Add(worker.response.responseStream);
                }
            }


            return(responseStreamList);
        }
Ejemplo n.º 7
0
        public string GenerateReportBitmap(EmsgGisReportParameter emsgGisReportParameter)
        {
            Size webPreviewSize = new Size(int.Parse(emsgGisReportParameter.MapSize.Split(',')[0]),
                                           int.Parse(emsgGisReportParameter.MapSize.Split(',')[1]));
            int             dpi = emsgGisReportParameter.IsPreview ? 72 : 300;
            ReportDefintion reportDefinition = new ReportDefintion(dpi);

            Bitmap legendBitmap = legendService.FormatLegendForReport(emsgGisReportParameter.Layers, emsgGisReportParameter, reportDefinition);

            //reportDefinition.widthInPixel -= legendBitmap.Width;
            Bitmap map = new Bitmap(Convert.ToInt32(reportDefinition.widthInPixel - legendBitmap.Width), Convert.ToInt32(reportDefinition.heightInPixel));

            emsgGisReportParameter.BoundingBox = UpdateExtent(map.Size, emsgGisReportParameter.BoundingBox);

            List <TileDefinition> tiles = DivideIntoTiles(reportDefinition.numberOfTiles, map.Size, emsgGisReportParameter.BoundingBox);



            List <Thread> threads = new List <Thread>();

            List <TileWorker> workers = new List <TileWorker>();

            foreach (TileDefinition tile in tiles)
            {
                TileWorker worker = new TileWorker(emsgGisReportParameter, tile, dpi, this, HttpContext.Current, emsgGisReportParameter.IsPreview);
                //List<Stream> responseList = PrepareAndSendWMSRequests(emsgGisReportParameter, tile, reportDefinition.dpi);
                Thread thread = new Thread(new ThreadStart(worker.Run));
                thread.Start();
                threads.Add(thread);
                workers.Add(worker);

                //AddTileToBitmap(map, responseList, reportDefinition, tilePosition);
            }

            foreach (Thread thread in threads)
            {
                thread.Join();
            }
            foreach (TileWorker worker in workers)
            {
                if (worker.exception != null)
                {
                    throw worker.exception;
                }
                AddTileToBitmap(map, worker.response, reportDefinition, worker.tile, tiles);
            }


            Bitmap all = AddMapInfosToMapBitmap(map,
                                                legendBitmap,
                                                emsgGisReportParameter,
                                                reportDefinition.dpi,
                                                webPreviewSize
                                                );

            //return all;
            //return map;
            string extension = emsgGisReportParameter.IsPreview ? ".jpg" : ".png";
            string tempPath  = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + extension);

            if (emsgGisReportParameter.IsPreview)
            {
                System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
                ImageCodecInfo    jpgEncoder             = GetEncoder(ImageFormat.Jpeg);
                EncoderParameters myEncoderParameters    = new EncoderParameters(1);

                EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 80L);
                myEncoderParameters.Param[0] = myEncoderParameter;
                all.Save(tempPath, jpgEncoder, myEncoderParameters);
            }
            else
            {
                all.Save(tempPath, ImageFormat.Png);
            }
            return(tempPath);
        }