map image quality when printing

Topics: SharpMap v0.9 / v1.x, WinForms Controls
Feb 12, 2009 at 11:01 AM

I’ve been using SharpMap (v0.9) for a while now (for a desktop app – not web based) and it is great, but I’m having a problem with the map image quality - it’s fine enough for onscreen, but when printing everything is a bit blurry. 

 

I’m a GIS person, still learning to program, so it very well may be that I just need to learn more advanced ways to go from screen to paper, but all the printing methods I've tried so far don’t seem to help and I wanted to make sure it’s not an issue with how I’m drawing the map, or that I’m trying for an image quality that isn’t possible with SharpMap, particularly v0.9.   

Are there any ways of optimizing the map image quality when drawing? – I’ve tried changing the smoothing mode, textrenderinghint, etc. for the layers and the printeventhandler graphics, but this doesn’t have any effect on screen or on the printed version.   I don’t need to resize at this point, but I’ve tried varying sizes, resolutions and that’s not making a difference either.  Would switching to v2 help, and if so, in what way? Any other suggestions for how to improve the image quality, either on screen or when printing?   

Any info or pointers to other resources would be very much appreciated – thank you, Michelle

 

Some examples of how I’m drawing the layers, and one way of printing…

 

    public void DrawMap(MapView mv)

    {

                //add Major rivers background layer to Map (_reportMap)

                if (mv.MajorRiversSDW.DrawLayer)

                {

                    VectorLayer majorRiversLayer = new VectorLayer("GIS_MajorRivers");

                    ProcessLayer(majorRiversLayer);

                    AssignStyle(majorRiversLayer, BackgroundLineStyle);

                    _reportMap.Layers.Add(majorRiversLayer);

                }

 

                //add towns labels layer to Map

                if (mv.TownsSDW.DrawLabel)

                {

                    LabelLayer townsLabelLayer = new LabelLayer("GIS_Capitals");

                    ProcessBackgroundLabelLayer(townsLabelLayer, mv.TownsSDW);

                    _reportMap.Layers.Add(townsLabelLayer);

                }

   

    ..add the rest of the layers

 

    mv.mapBox1.Map = _reportMap;

    }

 

        public VectorLayer ProcessLayer(VectorLayer layerName)

        {

            ///  Creates datasource and assigns it to the layer passed in

            string tableToDraw = layerName.LayerName;            
            SharpMap.Data.Providers.MsSql mySQLDataProvider = new SharpMap.Data.Providers.MsSql(_sqlConnString, tableToDraw, "Shape", "OID");

            layerName.DataSource = mySQLDataProvider;

            layerName.SmoothingMode = SmoothingMode.HighQuality;

            return layerName;

        }

 

        public VectorLayer AssignStyle(VectorLayer layerName, CustomTheme.GetStyleMethod getStyleMethod)

        {

            // Create custom theme from get style method and assign to layer's theme

 

            CustomTheme shadingTheme = new CustomTheme(getStyleMethod);

            layerName.Theme = shadingTheme;

            return layerName;

        }

 

       public VectorStyle BackgroundLineStyle(FeatureDataRow row)

        {

            //  Vector style used when drawing background layers of line type.

            Boolean drawGeometry;

            if (drawQueriedAreaOnly == "yes")

            {

                string districtIDColumn = "DistrictCode";                  
                string districtID = row[districtIDColumn].ToString();

                drawGeometry = MapController.Instance.getDrawGeometry(districtID);

            }

            else

            {

                drawGeometry = true;

            }

 

            if (drawGeometry)

            {

                vectorstyle.EnableOutline = _enableOutline;

                vectorstyle.Outline = _linePen;

                vectorstyle.Line = _linePen;

            }

            else

            {

                vectorstyle.EnableOutline = false;

                vectorstyle.Line = transparentPen;

            }

            return vectorstyle;        }

 

       public LabelLayer ProcessBackgroundLabelLayer(LabelLayer labelLayerName, StyleDelegateWrapper selectedSDW)

        {

            //  Sets style for drawing label layer

            //  Creates datasource and assigns it to the label layer passed in - used for background layers

 

            //label data

            string tableToDraw = labelLayerName.LayerName;

            SharpMap.Data.Providers.MsSql labelDataProvider = new SharpMap.Data.Providers.MsSql(_sqlConnString, tableToDraw, "Shape", "OID");

            labelLayerName.DataSource = labelDataProvider;

 

            labelLayerName.LabelStringDelegate = delegate(FeatureDataRow fdr)

            {

               Boolean drawGeometry;

                if (selectedSDW.DrawQueriedAreaOnly == "yes")

                {

                    string districtIDColumn = "DistrictCode";                     
                    string districtID = fdr[districtIDColumn].ToString();

                    drawGeometry = this.getDrawGeometry(districtID);

                }

                else                  {

                    drawGeometry = true;

                }

 

                string label;

                if (drawGeometry)

                    label = (string)fdr["Label"];

                else

                    label = "";

 

                return label;

};

            //label font

            labelLayerName.Style.ForeColor = selectedSDW.LabelColor;

            labelLayerName.Style.Font = selectedSDW.LabelFont;

            
            labelLayerName.SmoothingMode = SmoothingMode.HighQuality;

            labelLayerName.TextRenderingHint = TextRenderingHint.AntiAlias;

 

            return labelLayerName;

        }

 

        private void Document_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)

        {

            Image printImage = mapBox1.Map.GetMap();

            e.Graphics.DrawImage(printImage, 0, 0);

        }

 

        public void PrintMapViewFull()

        {

                PrintDocument mapDocument = new PrintDocument();

                mapDocument.DefaultPageSettings.Landscape = true;

                PrintDialog prtDlg = new PrintDialog();

                prtDlg.Document = mapDocument;

                mapDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.Document_PrintPage);

 

                if (prtDlg.ShowDialog() == DialogResult.OK)

                {

                    prtDlg.Document.Print();

                }

       

        }

Feb 12, 2009 at 3:17 PM
check this http://www.codeplex.com/SharpMap/Thread/View.aspx?ThreadId=42437

best

Peter
Feb 14, 2009 at 7:11 AM
Thanks Peter - I had tried your solution before with no luck, but I must have not been getting the resizing quite right then.  Tried it again and it is now improving the quality quite a lot - thanks very much for your help, Michelle