Lat/long measurements in degrees are multiplied by 1000 to increase the precision with which we can place them. - Java 2D Graphics

Java examples for 2D Graphics:Graphics

Description

Lat/long measurements in degrees are multiplied by 1000 to increase the precision with which we can place them.

Demo Code


import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.WritableRaster;

public class Main{
    public static final int LONGITUDE_DEGREES_MULTIPLIED = LONGITUDE_DEGREES
            * RESOLUTION_FACTOR;/*w  w w .ja  va 2  s  .  c  o m*/
    public static final int LATITUDE_DEGREES_MULTIPLIED = LATITUDE_DEGREES
            * RESOLUTION_FACTOR;
    /**
     * Lat/long measurements in degrees are multiplied by 
     * 1000 to increase the precision with which we can 
     * place them.
     * 
     * A corresponding transformation must be applied to
     * the graphics object which draws points with reference
     * to the image's pixel dimensions. 
     * 
     * The translation means that negative measurements 
     * will be drawn with reference to the centre point of
     * the image.
     */
    public static void scaleGraphics2D(Graphics2D g2d, int width, int height) {
        g2d.scale((float) width / (float) LONGITUDE_DEGREES_MULTIPLIED,
                (float) height / (float) LATITUDE_DEGREES_MULTIPLIED);
        g2d.translate((LONGITUDE_DEGREES_MULTIPLIED) / 2,
                (LATITUDE_DEGREES_MULTIPLIED) / 2);
    }
}

Related Tutorials