de.fhg.igd.gps.maps
Class MapInfo

java.lang.Object
  extended byde.fhg.igd.gps.maps.MapInfo

public class MapInfo
extends Object

This class allows to specify a world map clipping by giving either

Subsequently, this class provides conversion methods and methods to easily move the clipping by means of its center position or to zoom.

Furthermore, the specified map can be obtained as bitmap image through a given map requester.

The geo-coordinates as well as distances within a map clipping are interpolated in a linear manner between the upper left and lower right corner, assuming that the clipping area is small against the world's total surface. The scale of a map is given in meters per pixel, whereas this scale is decisive for both horizontal and vertical map resolution.

Author:
Jan Peters

Field Summary
private  WGS84Coordinate center_
          Center coordinate of the map clipping.
private  int height_
          The height of the map clipping in pixels.
static int HORIZONTAL
          Flag to use as parameter in methods getMetersPerDegree(), getPixelsPerDegree(), and getDegreesPerPixel().
private  WGS84Coordinate lowerRight_
          Lower right corner of the map clipping.
private  MapRequester mapRequester_
          Reference to the map requester
private  double scale_
          The scale of the map clipping in meters per pixel.
private  WGS84Coordinate upperLeft_
          Upper left corner of the map clipping.
static int VERTICAL
          Flag to use as parameter in methods getMetersPerDegree(), getPixelsPerDegree(), and getDegreesPerPixel().
private  int width_
          The width of the map clipping in pixels.
 
Constructor Summary
MapInfo(MapRequester mr)
          Creates a new instance of this class with the given MapRequester as reference class for map retrieval and scale validation.
 
Method Summary
 Point coordinate2point(WGS84Coordinate position)
          Converts a geo-coordinate within the map clipping, into a corresponding pixel position, given as point relative to the clipping's upper left corner.
 WGS84Coordinate getCenterPosition()
          Returns the center coordinate of the map clipping.
 double getDegreesPerPixel(int orientation)
          Returns the amount of degrees per degree, dependent of the current map clipping and the given orientation.
 int getHeight()
          Returns the height of the map clipping in pixels.
 WGS84Coordinate getLowerRightPosition()
          Returns the lower right corner of the map clipping.
 BufferedImage getMap()
          Returns a map corresponding to the specified map clipping, making use of the reference MapRequester.
 double getMetersPerDegree(int orientation)
          Returns the length of one degree (latitude resp.
static double getMetersPerDegree(Latitude latitude, Longitude longitude, int orientation)
          Returns the length of one degree (latitude resp.
static double getMetersPerDegree(WGS84Coordinate location, int orientation)
          Returns the length of one degree (latitude resp.
 double getPixelsPerDegree(int orientation)
          Returns the amount of pixels per degree, dependent of the current map clipping and the given orientation.
 double getScale()
          Returns the scale of the map clipping in meters per pixel.
 WGS84Coordinate getUpperLeftPosition()
          Returns the upper left corner of the map clipping.
 int getWidth()
          Returns the width of the map clipping in pixels.
 void init(Latitude latitude, Longitude longitude, double scale, int width, int height)
          Initializes the world map clipping with the given geo-coordinate of the center and the map's scale together with its height and width in pixels.
 void init(Latitude latUpperLeft, Longitude lonUpperLeft, Latitude latLowerRight, Longitude lonLowerRight, int width, int height)
          Initializes the world map clipping with the geo-coordinates of the upper left and lower right corner together with the map's height and width in pixels.
 void init(WGS84Coordinate center, double scale, int width, int height)
          Initializes the world map clipping with the given geo-coordinate of the center and the map's scale together with its height and width in pixels.
 void init(WGS84Coordinate upperLeft, WGS84Coordinate lowerRight, int width, int height)
          Initializes the world map clipping with the geo-coordinates of the upper left and lower right corner together with the map's height and width in pixels.
 boolean isWithin(Point point)
          Checks if the given point lies within the map clipping or not.
 boolean isWithin(WGS84Coordinate position)
          Checks if the given geo-coordinate lies within the map clipping or not.
 boolean move(double xFactor, double yFactor)
          Moves the center of the map clipping according to the translation given by the vector (xFactor|yFactor.
 WGS84Coordinate point2coordinate(Point point)
          Converts a point within the map clipping, which has to be given as pixel position relative to the clipping's upper left corner, into the corresponding geo-coordinate.
 double radiusInMetersToScale(int width, int height, int radius)
          Calculates the scale according to the given width and height, so that an environment arround the center with the given radius in meters is visible on a corresponding map clipping.
 String toString()
          Returns the string representation of the class.
 double validateScale(double scale)
          Validates the given scale, making use of the reference MapRequester (see constructer of the class), and then adjusts it if necessary.
 boolean zoom(double factor)
          Method to zoom into the map clipping resp.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HORIZONTAL

public static final int HORIZONTAL
Flag to use as parameter in methods getMetersPerDegree(), getPixelsPerDegree(), and getDegreesPerPixel().

See Also:
Constant Field Values

VERTICAL

public static final int VERTICAL
Flag to use as parameter in methods getMetersPerDegree(), getPixelsPerDegree(), and getDegreesPerPixel().

See Also:
Constant Field Values

mapRequester_

private MapRequester mapRequester_
Reference to the map requester


center_

private WGS84Coordinate center_
Center coordinate of the map clipping.


upperLeft_

private WGS84Coordinate upperLeft_
Upper left corner of the map clipping.


lowerRight_

private WGS84Coordinate lowerRight_
Lower right corner of the map clipping.


scale_

private double scale_
The scale of the map clipping in meters per pixel.


height_

private int height_
The height of the map clipping in pixels.


width_

private int width_
The width of the map clipping in pixels.

Constructor Detail

MapInfo

public MapInfo(MapRequester mr)
Creates a new instance of this class with the given MapRequester as reference class for map retrieval and scale validation.

Parameters:
mr - the reference MapRequester.
Method Detail

getMetersPerDegree

public static double getMetersPerDegree(WGS84Coordinate location,
                                        int orientation)
Returns the length of one degree (latitude resp. longitude) in meters, according to the current location and orientation.

Parameters:
location - the current location.
orientation - HORIZONTAL to get the length of one degree on the current latitude line, or VERTICAL to get the length of one degree on the current longitude line.
Returns:
length of one degree in meters, or -1 if an error occured.

getMetersPerDegree

public static double getMetersPerDegree(Latitude latitude,
                                        Longitude longitude,
                                        int orientation)
Returns the length of one degree (latitude resp. longitude) in meters, according to the current location given by latitude and longitude, and orientation.

Parameters:
latitude - the latitude of the current location.
longitude - the longitude of the current location.
orientation - HORIZONTAL to get the length of one degree on the current latitude line, or VERTICAL to get the length of one degree on the current longitude line.
Returns:
length of one degree in meters, or -1 if an error occured.

init

public void init(Latitude latitude,
                 Longitude longitude,
                 double scale,
                 int width,
                 int height)
Initializes the world map clipping with the given geo-coordinate of the center and the map's scale together with its height and width in pixels. The scale will be validated, making use of the reference MapRequester, and then adjusted if necessary.

Parameters:
latitude - latitude of the map clipping's center.
longitude - longitude of the map clipping's center.
scale - the scale of the map in meters per pixel.
width - width of the map clipping in pixels.
height - height of the map clipping in pixels.

init

public void init(WGS84Coordinate center,
                 double scale,
                 int width,
                 int height)
Initializes the world map clipping with the given geo-coordinate of the center and the map's scale together with its height and width in pixels. The scale will be validated, making use of the reference MapRequester, and then adjusted if necessary.

Parameters:
center - coordinate of the map clipping's center.
scale - the scale of the map in meters per pixel.
width - width of the map clipping in pixels.
height - height of the map clipping in pixels.

init

public void init(Latitude latUpperLeft,
                 Longitude lonUpperLeft,
                 Latitude latLowerRight,
                 Longitude lonLowerRight,
                 int width,
                 int height)
Initializes the world map clipping with the geo-coordinates of the upper left and lower right corner together with the map's height and width in pixels. The scale will be validated, making use of the reference MapRequester, and then adjusted if necessary.

Parameters:
latUpperLeft - latitude of the map clipping's upper left corner.
lonUpperLeft - longitude of the map clipping's upper left corner.
latLowerRight - latitude of the map clipping's lower right corner.
lonLowerRight - longitude of the map clipping's lower right corner.
width - width of the map clipping in pixels.
height - height of the map clipping in pixels.

init

public void init(WGS84Coordinate upperLeft,
                 WGS84Coordinate lowerRight,
                 int width,
                 int height)
Initializes the world map clipping with the geo-coordinates of the upper left and lower right corner together with the map's height and width in pixels. The scale will be validated, making use of the reference MapRequester, and then adjusted if necessary.

Parameters:
upperLeft - coordinate of the map clipping's upper left corner.
lowerRight - coordinate of the map clipping's lower right corner.
width - width of the map clipping in pixels.
height - height of the map clipping in pixels.

getCenterPosition

public WGS84Coordinate getCenterPosition()
Returns the center coordinate of the map clipping.

Returns:
center coordinate.

getUpperLeftPosition

public WGS84Coordinate getUpperLeftPosition()
Returns the upper left corner of the map clipping.

Returns:
upper left corner coordinate.

getLowerRightPosition

public WGS84Coordinate getLowerRightPosition()
Returns the lower right corner of the map clipping.

Returns:
upper lower right coordinate.

getScale

public double getScale()
Returns the scale of the map clipping in meters per pixel.

Returns:
scale of the map clipping.

getHeight

public int getHeight()
Returns the height of the map clipping in pixels.

Returns:
height of the map clipping.

getWidth

public int getWidth()
Returns the width of the map clipping in pixels.

Returns:
width of the map clipping.

point2coordinate

public WGS84Coordinate point2coordinate(Point point)
Converts a point within the map clipping, which has to be given as pixel position relative to the clipping's upper left corner, into the corresponding geo-coordinate.

Parameters:
point - the pixel position within the map clipping.
Returns:
the corresponding geo-coordinate, or null if the class has not been initialized, yet.

coordinate2point

public Point coordinate2point(WGS84Coordinate position)
Converts a geo-coordinate within the map clipping, into a corresponding pixel position, given as point relative to the clipping's upper left corner.

Parameters:
position - the geo-coordinate within the map clipping.
Returns:
the corresponding point, or null if the class has not been initialized, yet.

isWithin

public boolean isWithin(Point point)
Checks if the given point lies within the map clipping or not.

Parameters:
point - the pixel position relative to the upper left corner.
Returns:
true if the given point lies within the clipping, false otherwise.

isWithin

public boolean isWithin(WGS84Coordinate position)
Checks if the given geo-coordinate lies within the map clipping or not.

Parameters:
position - the geo-coordinate.
Returns:
true if the given coordinate lies within the clipping, false otherwise.

zoom

public boolean zoom(double factor)
Method to zoom into the map clipping resp. zoom out. Dependent of the given factor the map clipping's scale is adjusted. The center, width, and height of the clipping remain unchanged. The class has to be initialized first. The scale will be validated, making use of the reference MapRequester, and then adjusted if necessary.

Parameters:
factor - a factor greater than 1 to zoom in, a factor less than 1 to zoom out (negative factors are not allowed).
Returns:
true if the opperation ended successfully, false otherwise.

move

public boolean move(double xFactor,
                    double yFactor)
Moves the center of the map clipping according to the translation given by the vector (xFactor|yFactor. The scale, width, and height of the clipping remain unchanged. The class has to be initialized first.

Parameters:
xFactor - the translation factor on the horizontal axis, given as factor of the clipping's width.
Returns:
true if the opperation ended successfully, false otherwise.

getPixelsPerDegree

public double getPixelsPerDegree(int orientation)
Returns the amount of pixels per degree, dependent of the current map clipping and the given orientation.

Parameters:
orientation - HORIZONTAL to get the amount of pixels per degree on a latitude line, or VERTICAL to get the amount of pixels per degree on a longitude line.
Returns:
the amount of pixels per degree.

getDegreesPerPixel

public double getDegreesPerPixel(int orientation)
Returns the amount of degrees per degree, dependent of the current map clipping and the given orientation.

Parameters:
orientation - HORIZONTAL to get the amount of degrees per pixel on a latitude line, or VERTICAL to get the amount of degrees per pixel on a longitude line.
Returns:
the amount of degrees per pixel.

validateScale

public double validateScale(double scale)
Validates the given scale, making use of the reference MapRequester (see constructer of the class), and then adjusts it if necessary. If the reference MapRequester is null the given scale is returned unchanged.

Parameters:
scale - the scale to validate.
Returns:
the validated scale, adjusted if necessary.

radiusInMetersToScale

public double radiusInMetersToScale(int width,
                                    int height,
                                    int radius)
Calculates the scale according to the given width and height, so that an environment arround the center with the given radius in meters is visible on a corresponding map clipping. The scale will be validated, making use of the reference MapRequester, and then adjusted if necessary.

Parameters:
width - width of the map clipping.
radius - radius in meters.
Returns:
the scale to initialize a corresponding map clipping.

getMetersPerDegree

public double getMetersPerDegree(int orientation)
Returns the length of one degree (latitude resp. longitude) in meters, according to the current location given by the map clipping's center, and the orientation.

Parameters:
orientation - HORIZONTAL to get the length of one degree on the current latitude line, or VERTICAL to get the length of one degree on the current longitude line.
Returns:
length of one degree in meters, or -1 if an error occured.

getMap

public BufferedImage getMap()
                     throws IOException
Returns a map corresponding to the specified map clipping, making use of the reference MapRequester.

Returns:
the map as BufferedImage, or null if the reference MapRequester or the class has not been initialized, yet
Throws:
IOException - if an error occures while requesting resp. generating the map.

toString

public String toString()
Returns the string representation of the class.

Returns:
the string representation of the class.


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.