[geotk] Re: Get envelope for a scale

Martin Desruisseaux martin.desruisseaux at geomatys.fr
Tue Sep 8 07:11:03 EDT 2009


Hello Theuns

Your reasoning seems correct to me. I don't know where this 14% difference come 
from. I would need to investigate the rendering chain to get a better picture.

You can derive the DPI from the following API:

http://java.sun.com/javase/6/docs/api/java/awt/GraphicsConfiguration.html#getNormalizingTransform%28%29

Get the scale of that affine transform and multiply by 1/72. To get the aspect 
ratio, you can compute scaleY/scaleX from the above transform. Actually to take 
in account the aspect ratio, we only need to concatenate the initial affine 
transform by the above one as explained in the documentation.

Actually I wonder if it is not already done by the current GO2 renderer - we 
need to ask to Johan. It seems to me that the legacy one (in GeoTools 
pre-streaming renderer days) was already doing that.

There is different way to get a GraphicsConfiguration. One possible path is:

http://java.sun.com/javase/6/docs/api/java/awt/GraphicsDevice.html#getDefaultConfiguration%28%29
http://java.sun.com/javase/6/docs/api/java/awt/GraphicsEnvironment.html#getDefaultScreenDevice%28%29
http://java.sun.com/javase/6/docs/api/java/awt/GraphicsEnvironment.html#getLocalGraphicsEnvironment%28%29

	Martin


theuns a écrit :
> Hi All
> 
> I did a few experiments, and it looks like the pixels per inch is a
> issue.
> 
> I have in my possession a 1:50 000 scale map as a hard copy of the area
> i am looking at, the hard copy map have a UTM grid on it, and one UTM
> block on the map represents 1km.
> The physical size of the UTM block on the printed map is 2cm x 2cm.
> 
> For the same area i have shapefile data like roads, rivers etc. and a
> 1:50 000 UTM grid shapefile.
> 
> Please correct me if i am wrong but my understanding is that if i
> display the data on the screen , and zoom to a scale of 1:50 000 , the
> UTM blocks should also be 2cm x 2cm?
> 
> I implemented the code below to get the current map scale and use for a
> start the 1/72 pixels per inch (PPI).
> Then use the following method to zoom to the correct scale.
> 
> double scaleChange = MapScale / 50000;
> mapWidget.getCanvas().getController().scale(scaleChange, point);
> 
> When measuring the physical length and width of the UTM grid block on
> the screen , i get the following values.
> 
> 1. 1/72.0 PPI is +- 3mm short
> 2. 1/98.30691947 PPI is +- 3mm to long
> 3. 1/86.0 PPI spot on.
> 
> The 1/98 PPI i got from the formulas on
> http://en.wikipedia.org/wiki/Pixels_per_inch 
> 
> My laptop values is 1280 wide 800 high and the diagonal width is
> 15.354331 inches.
> 
> The 1/86.0 i just played with until i get a value that works.
> 
> Now before i get shot, is there any fault in my reasoning?
> And the PPI value should surely not be hardcoded, how to get that for
> different size monitors?
> And does aspect ratio play a role?
> If it does how will i use it to incorporate the aspect ration into the
> calculations? 



More information about the Geotoolkit mailing list