Class RasterMapEntry

java.lang.Object
org.ka2ddo.yaac.gui.rastermap.RasterMapEntry
All Implemented Interfaces:
Serializable

public class RasterMapEntry extends Object implements Serializable
This class describes one raster map image file and the translation information needed to render it on the screen with the correct registration.

Because of the distortion caused by projecting a nearly-spherical Earth onto a flat map panel view, the image re-registration algorithm assumes a trapezoidal distortion as a good-enough approximation for rasters in units of meters (or other linear length), so the Java AffineTransform is insufficient to project raster map images into the map viewport. Instead, the following equations are used to map viewport pixel coordinates into raster map image pixel coordinates: xi = x0 + x1 * xv + x2 * yv + x3 * xv * yv yi = y0 + y1 * yv + y2 * xv + y3 * yv * xv

To compute the coefficients of the above equations, the least squares method is used to fit a series of pinpoints (associations between image pixels and geographical map coordinates) into the mapping between viewport pixel coordinates and image pixel coordinates.

If the raster image pixel step is in units of fractional degrees (for example, US National Weather Service radar maps), the full Mercator projection is needed to convert between degree-based image coordinates and linear pixel-based viewport coordinates.

xi = x0 + x1 * xv yi = y0 + y1 * atan(sinh(y3 * yv + y2)) and, unlike the linear formula, the Mercator formula does not allow for any relative rotation of coordinate systems.
Author:
Andrew Pavlin, KA2DDO
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    This class contains one association between a pixel in the image and its latitude/longitude position on the planet.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    boolean
    Flag indicating whether this particular raster overlay should be displayed in the map.
    int
    Height of raster image in pixels.
    The image as a renderable object (assuming it can be loaded successfully).
    Timestamp when the image was created (used to detect an updated image for automatic refreshing).
    boolean
    Indicates that the steps between pixels are in units of linear distance (meters), rather than in angular distance (degrees) across the approximately spherical Earth.
    boolean
    Indicates whether local storage is available for image so it can be quickly reloaded.
    Pathname to where the image file is stored on this computer.
    boolean
    Flag indicating whether this particular raster overlay should be persisted over YAAC restarts.
    The list of PinPoints matching image pixels with global lat/lon positions.
    int
    The level of transparency fading to apply to the raster map (alpha component).
    The color of the raster image that is to be replaced with full transparency, so the map behind the raster image can still be seen.
    int
    Width of raster image in pixels.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    getPinPointAt(int vx, int vy, com.bbn.openmap.proj.Projection proj)
    Find which (if any) PinPoint that the specified viewport coordinates are upon.
    getViewportBounds2DOfImage(int vWidth, int vHeight, com.bbn.openmap.proj.Mercator projection)
    Get the coordinates within the viewport that intersect the raster image.
    void
    Read a serialized dump of this object from an input stream for restoration.
    void
    Remove this RasterMapEntry from the Preferences persistence cache.
    Returns a string representation of the object.
    transformImageToViewport(float xi, float yi, Point2D.Float dstPt, com.bbn.openmap.proj.Mercator projection)
    Convert coordinates within an image into viewport coordinates.
    transformViewportToImage(float vx, float vy, Point2D.Float dstPt, com.bbn.openmap.proj.Mercator projection)
    Convert viewport coordinates into a position within the raster image.
    void
    Write a serialized dump of this object to an output stream for storage and later restoration.
    void
    Write a serialized dump of this object to Java Preferences.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • pathname

      public String pathname
      Pathname to where the image file is stored on this computer.
    • img

      public transient BufferedImage img
      The image as a renderable object (assuming it can be loaded successfully).
    • width

      public int width
      Width of raster image in pixels.
    • height

      public int height
      Height of raster image in pixels.
    • transparentColor

      public Color transparentColor
      The color of the raster image that is to be replaced with full transparency, so the map behind the raster image can still be seen.
    • transparency

      public int transparency
      The level of transparency fading to apply to the raster map (alpha component).
    • enabled

      public boolean enabled
      Flag indicating whether this particular raster overlay should be displayed in the map.
    • persist

      public boolean persist
      Flag indicating whether this particular raster overlay should be persisted over YAAC restarts.
    • imgCreationDate

      public transient Date imgCreationDate
      Timestamp when the image was created (used to detect an updated image for automatic refreshing).
    • isLinear

      public boolean isLinear
      Indicates that the steps between pixels are in units of linear distance (meters), rather than in angular distance (degrees) across the approximately spherical Earth. This affects the formula used for Mercator projection of the image into the viewport.
    • keepImg

      public boolean keepImg
      Indicates whether local storage is available for image so it can be quickly reloaded. Should be true for network-provided images that would be expensive to reload.
    • pinpointList

      public final ArrayList<RasterMapEntry.PinPoint> pinpointList
      The list of PinPoints matching image pixels with global lat/lon positions.
  • Constructor Details

    • RasterMapEntry

      public RasterMapEntry()
  • Method Details

    • transformViewportToImage

      public final Point2D.Float transformViewportToImage(float vx, float vy, Point2D.Float dstPt, com.bbn.openmap.proj.Mercator projection)
      Convert viewport coordinates into a position within the raster image.
      Parameters:
      vx - X coordinate of point in the viewport
      vy - Y coordinate of point in the viewport
      dstPt - Point2D.Float object to contain the answer, or null to allocate a new Point2D.Float object
      projection - Mercator projection used to translate coordinates (only needed for degree-scaled rasters)
      Returns:
      raster image pixel coordinates corresponding to the viewport coordinates
    • transformImageToViewport

      public Point2D.Float transformImageToViewport(float xi, float yi, Point2D.Float dstPt, com.bbn.openmap.proj.Mercator projection)
      Convert coordinates within an image into viewport coordinates.
      Parameters:
      xi - X coordinate of pixel within the raster image
      yi - Y coordinate of pixel within the raster image
      dstPt - Point2D.Float object to contain the answer, or null to allocate a new Point2D.Float object
      projection - Mercator projection used to translate coordinates (only needed for degree-scaled rasters)
      Returns:
      viewport coordinates for the specified position within the image
    • getViewportBounds2DOfImage

      public Rectangle2D.Float getViewportBounds2DOfImage(int vWidth, int vHeight, com.bbn.openmap.proj.Mercator projection)
      Get the coordinates within the viewport that intersect the raster image.
      Parameters:
      vWidth - viewport width in pixels
      vHeight - viewport height in pixels
      projection - Mercator projection used to translate coordinates (only needed for degree-scaled rasters)
      Returns:
      Rectangle2D of viewport coordinates bounding the image, or null if no intersection
    • getPinPointAt

      public RasterMapEntry.PinPoint getPinPointAt(int vx, int vy, com.bbn.openmap.proj.Projection proj)
      Find which (if any) PinPoint that the specified viewport coordinates are upon.
      Parameters:
      vx - viewport X coordinate
      vy - viewport Y coordinate
      proj - Projection of the current viewport
      Returns:
      PinPoint at the specified viewport coordinates, or null if no matching PinPoint found
    • read

      public void read(DataInput dis) throws IOException
      Read a serialized dump of this object from an input stream for restoration.
      Parameters:
      dis - DataInput object to read the object data from
      Throws:
      IOException - if read fails for any reason
    • write

      public void write(DataOutput dos) throws IOException
      Write a serialized dump of this object to an output stream for storage and later restoration. Note this does not write the persist flag, as this code wouldn't be getting called if the record wasn't supposed to be persisted.
      Parameters:
      dos - DataOutput object to write the RasterMapEntry to
      Throws:
      IOException - if write fails for any reason
    • writeToPreferences

      public void writeToPreferences(Preferences prefs)
      Write a serialized dump of this object to Java Preferences.
      Parameters:
      prefs - Preferences object to store this object
    • removePersistence

      public void removePersistence(Preferences prefs)
      Remove this RasterMapEntry from the Preferences persistence cache.
      Parameters:
      prefs - Preferences object supposedly containing an entry for this RasterMapEntry
    • toString

      public String toString()
      Returns a string representation of the object.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the RasterMapEntry.