[geotk] Re: Get envelope for a scale
theuns
theunsheydenrych at gmail.com
Thu Sep 10 07:49:00 EDT 2009
Thanks for this information Martin.
I tried the suggestion and the getNormalizingTransform returns a
identity matrix?
So what i did further is to create on a normal JFrame a line of 72
pixels long and measure the length in milimeters, and work out the
relation of the length of the line to one inch (25.4 mm).
Here is the code:
Graphics2D g2 = (Graphics2D) g;
GraphicsConfiguration gc = g2.getDeviceConfiguration();
g2.setTransform(gc.getDefaultTransform());
AffineTransform nm = gc.getNormalizingTransform();
g2.transform(nm);
Line2D lin = new Line2D.Float(100, 100, 72, 100);
g2.draw(lin);
The line measured 10.0 mm , so did the following:
Graphics2D g2 = (Graphics2D) g;
GraphicsConfiguration gc = g2.getDeviceConfiguration();
g2.setTransform(gc.getDefaultTransform());
AffineTransform nm = gc.getNormalizingTransform();
double Scale_72 = 25.4 / 10;
nm.scale(Scale_72, 1.0);
g2.transform(nm);
Line2D lin = new Line2D.Float(100, 100, 72, 100);
g2.draw(lin);
Now the line measured +-25.4mm, am i correct in my thinking, Martin?
So i tried to do the same with the
org.geotoolkit.display2d.canvas.J2DCanvasVolatile in the
private void render(Shape paintingDisplayShape) method, with the output
Graphichs2D , but it does not seemed to work?
Is this the correct place for it Johann?
Regards
Theuns
On Tue, 2009-09-08 at 13:11 +0200, Martin Desruisseaux wrote:
> 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