ThinkGeo.com    |     Documentation    |     Premium Support

Printing with exact scale

Hi,

I’m playing with PrintPreview sample.
Now I’m wondering what to do to get an exact PrintOut at Scale 1:10.000 on Paper/PDF?

I have a PostGIS-Table with one geometry (Polygon 1.000 x 1.000 Meters).
Projection is EPSG 25832.

I have changed the example as follows:

private void AddMapLayer()
        {
            // Create the MapPrinterLayer and set the position
            MapPrinterLayer mapPrinterLayer = new MapPrinterLayer();
            mapPrinterLayer.MapUnit = GeographyUnit.Meter;
            mapPrinterLayer.BackgroundMask = new AreaStyle(new GeoPen(GeoColor.StandardColors.Black, 1));
            mapPrinterLayer.Open();

            // Set the maps position slightly below the pages center and 8 inches wide and 7 inches tall
            RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch);
            mapPrinterLayer.SetPosition(8, 7, pageBoundingbox.GetCenterPoint().X, pageBoundingbox.GetCenterPoint().Y + 1, PrintingUnit.Inch);

            // Setup the intial extent and ensure they snap to the default ZoomLevel
            ZoomLevelSet zoomLevelSet = new ZoomLevelSet();
            
            // Add the MapPrinterLayer to the PrinterInteractiveOverlay
            PrinterInteractiveOverLay printerInteractiveOverLay = (PrinterInteractiveOverLay)winformsMap1.InteractiveOverlays["PrintPreviewOverlay"];
            printerInteractiveOverLay.PrinterLayers.Add("MapLayer", mapPrinterLayer);

            //####################################################################
            PostgreSqlFeatureLayer newLayer = new PostgreSqlFeatureLayer();

            newLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            newLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.SimpleColors.Red, 2);
            newLayer.GeometryColumnName = "the_geom";
            newLayer.ConnectionString = "Server=localhost;User Id=postgres;Password=gisme;DataBase=cuxhaven";
            newLayer.FeatureIdColumn = "gid";
            newLayer.TableName = "atest";
            newLayer.Name = "test";
            newLayer.Srid = 25832;
            Proj4Projection layerProjection = new Proj4Projection();
            layerProjection.ExternalProjectionParametersString = Proj4Projection.GetSphericalMercatorParametersString();
            layerProjection.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(25832);
            layerProjection.Open();
            newLayer.FeatureSource.Projection = layerProjection;

            newLayer.Transparency = 255;

            newLayer.Open();
            mapPrinterLayer.Layers.Add(newLayer);
            mapPrinterLayer.MapExtent = newLayer.GetBoundingBox();        
            //####################################################################

        }

When printing to PDF the Polygon width will be 169,07 mm on ANSI A.

Question:
How to set the extent/scale of winformsMap to get a correct printing result at a scale 1:10.000 or any other scale as PDF and Paper?

Regard
Hardy

Hi Hardy,

Sorry to say I was failed to recreate this issue as we don’t have the data, but I found some hints here. Maybe you can refer to MapPrinterLayer not printing to scale to see if it’s helped.

NOTE: could you please tell me what tools you using to measure the size?

Thanks,
Peter

Hi Peter,

I have loaded the example “ScaleBarTest” and checked the printing…
I have changed the “SetScale” Sub to

Dim oExtent As RectangleShape = ExtentHelper.ZoomToScale(10000, moPageLayoutMap.MapExtent, moPageLayoutMap.MapUnit, dWidth, dHeight)

So ScaleBar should display correct Width for 500 Meter at printing area.

When printing to PDF I get a very bad result: The ScaleBar Displays 500m at a scale of 1:10000.
But the width is 57.66 mm (measured on PDF with Pdf-Tools).

Please have a look at my attachement.
3.pdf (85.5 KB)

I’m expecting an exact result. 500m must be 50mm at 1:10000 Scale.

What to do?

Hardy

atest.zip (1.3 KB)Peter,

attached you’ll find my data as SQL-script for testing the issue from my first post.

Hi Hardy,

Sorry for the delay. I’ve just come back from holiday. It seems that there’s a syntax error for SQL-script showing as below. (NOTE: I use pgAdmin client and postgreSQL 9.5)

Could you please append it here again? Also, Is it possible for you to attached a sample here? so we can reproduce this issue quickly.

Thanks,
Peter

Hi Peter,

I used Postgres 9.0.

Attached a backup with the table in.

Regards
Hardyatest.zip (2.7 KB)

Hi Hardy,

We tried to restore your backup in our machine (it’s 9.5 version) but it failed like this.

I am not so familiar with postgres, so I cannot make sure whether that’s because the database version.

I am trying to install a 9.0 version Postgres and retry that, if you have any information about it please let me know.

Regards,

Don

Hi Don,
I used the following command to enter the test geometry:
INSERT INTO atest(
the_geom)
VALUES (geomfromtext(‘POLYGON((480400 5967500,481400 5967500,481400 5968500,480400 5968500,480400 5967500))’,25832));

To create the table:

CREATE TABLE atest
(
gid serial NOT NULL,
fc character varying(50),
uri character varying(255),
rotation double precision DEFAULT 0,
txtrotation double precision DEFAULT 0,
txtdx double precision DEFAULT 0,
txtdy double precision DEFAULT 0,
fid integer DEFAULT 0,
editor integer DEFAULT 0,
constructor integer DEFAULT 0,
created date DEFAULT (‘now’::text)::date,
lastupdate date DEFAULT (‘now’::text)::date,
mandant integer DEFAULT 0,
parentinfo character varying(255),
parentformel integer DEFAULT 0,
parent character varying(50),
text01 character varying(50),
text02 character varying(50),
text03 character varying(50),
the_geom geometry,
CONSTRAINT atest_pk PRIMARY KEY (gid),
CONSTRAINT enforce_dims_the_geom CHECK (st_ndims(the_geom) = 2),
CONSTRAINT enforce_srid_the_geom CHECK (st_srid(the_geom) = 25832)
)
WITH (
OIDS=FALSE
);
ALTER TABLE atest OWNER TO postgres;

– Index: atest_fid_idx

– DROP INDEX atest_fid_idx;

CREATE INDEX atest_fid_idx
ON atest
USING btree
(fid);

– Index: atest_geom_idx

– DROP INDEX atest_geom_idx;

CREATE INDEX atest_geom_idx
ON atest
USING gist
(the_geom);

That should work with Postgres 9.x.

Hope that helps.

Regards
Hardy

Hi Hardy,

Sorry for the delay. This time I create the table successfully, but failed to insert the data into the database as it returns an error “function geomfromtext(unknown, integer) does not exist”. I do some research but don’t find out the solution for this. Please forgive me for being a beginner on postgresql.

Thanks,
Peter

Peter,
any News on that Task?

Hi Hardy,

It’s still in progress as I don’t find the function geomfromtext. I see the script and there is only one record in atest table. Is it possible for you to convert the record into WKT, so I can use it to recreate the issue?

Sorry for the inconvenience.

Thanks,
Peter

Peter,

as Attachement you’ll find the geometry as shape file.

Regards
HardyMapSuite.zip (1.5 KB)

Peter,
is my shape file usefull to solve the Problem?
I need way to print exact maps on paper.

Waiting to get an answer…
Hardy

Hi Hardy,

Thanks for your shape file, because our forum issue we hadn’t get the update of this post. Peter is busy and cannot work on support team near future, so I will look into your problem and reply you after get any progress.

It looks the other guy who met the same issue before, I will try to find the topic also to see whether that’s helpful.

Regards,

Don

Hi Don,

any (good) news?
We need a solution and time is running…

Hope you can support me with a peace of code to solve the problem next days.

Regards
Hardy

Hi Hardy,

I still cannot update about this issue, but I will ask our developer about the status again and see whether we can get more time on this problem.

It’s hard to make sure where is the problem, because that maybe because projection conversion, scale calculation, printing convert or scaleline calculation incorrect.

And the new release takes many sources, our developer cannot get enough time on support these days, so the process looks not good.

Regards,

Don

Hi Hardy,

Sorry for the delay.

I do test based on your shape file and find the width of square is about 1690m instead of your expected 1000m, showing like below.

I modified the sample to create a feature with size: 1000m * 1000m.

Here is the sample PrintPreview.zip (1.6 MB), just click “To PDF” button to export the map to a pdf file, you should get the result like below.

The code snippet I modified shows like below:

  1. We need to get the drawing extent for current MapPrinterLayer.

  2. Zoom the drawing extent to 1000 what we expected.

    MapPrinterLayer mapPrinterLayer = (MapPrinterLayer)printerInteractiveOverLay.PrinterLayers[“MapLayer”];

    var currentBoundingBox = mapPrinterLayer.GetBoundingBox();
    RectangleShape adjustedWorldExtent = ExtentHelper.GetDrawingExtent(mapPrinterLayer.MapExtent, (float)currentBoundingBox.Width, (float)currentBoundingBox.Height);

mapPrinterLayer.MapExtent = ExtentHelper.ZoomToScale(10000, adjustedWorldExtent, GeographyUnit.Meter, (float)currentBoundingBox.Width, (float)currentBoundingBox.Height);

Hope it’s helpful.

Thanks,
Peter

Peter,

thanks for your information.
But the square is 1000m x 1000m, when using epsg:=25832.
So you must set projection when reading the layer from shape-file.
Maybe that’s the/one error when printing to paper and scaling is going wrong.

Did you use projection?

Regards
Hardy

Hi Hardy,

I apply projection to shapefilefeaturelayer. I remove projection and get the correct result as below:

Please try using the sample I attached before.

Thanks,
Peter

Hi Peter,

I checked that, button what you have done is to define a square with 1000 x 1000m using an inMemoryFeaturLayer.
Please use the shape file. When using the shape file I’m getting a length of 203,20 mm. That’s wrong!

I like to get an exact length by setting a map scale (for example 1:50000).