org.deegree.coverage.raster.geom
Class RasterGeoReference

java.lang.Object
  extended by org.deegree.coverage.raster.geom.RasterGeoReference

public class RasterGeoReference
extends Object

The RasterGeoReference defines methods for transformations between a raster crs and a world crs. For this purpose the origin of the upper left raster grid and the size in world coordinate units of a raster grid (pixel) must be specified. Alternatively an angle between the x axis and a rectangular base axis (as well as y rotation between the y axis and the rectangular basis) may be defined. This implementation is world crs axis order aware. See http://wiki.deegree.org/deegreeWiki/deegree3/RasterInnerOuterIssue for a discussion on the location of the origin on a raster grid.

Version:
$Revision: 31644 $, $Date: 2011-08-24 22:27:43 +0200 (Wed, 24 Aug 2011) $
Author:
Rutger Bezema, last edited by: $Author: mschneider $

Nested Class Summary
static class RasterGeoReference.OriginLocation
          The OriginLocation defines the mapping location of the world origin to the underlying raster.
 
Constructor Summary
RasterGeoReference(RasterGeoReference.OriginLocation location, double resolutionX, double resolutionY, double origin0, double origin1)
          Constructs a raster reference with given resolutions and origin.
RasterGeoReference(RasterGeoReference.OriginLocation location, double resolutionX, double resolutionY, double rotationX, double rotationY, double origin0, double origin1, ICRS crs)
          Constructs a raster reference with given resolutions, origin and rotations.
RasterGeoReference(RasterGeoReference.OriginLocation location, double resolutionX, double resolutionY, double origin0, double origin1, ICRS crs)
          Constructs a raster reference with given resolutions and origin.
 
Method Summary
 RasterRect convertEnvelopeToRasterCRS(Envelope envelope)
          Converts an envelope in world coordinates to raster coordinates, note the envelope in world coordinates is defined over min/max (lower left/upper right), whereas a RasterRect is defined as min(upperleft) with a width and height.
static RasterGeoReference create(RasterGeoReference.OriginLocation location, Envelope envelope, double resolution0, double resolution1)
          Create a raster reference which has it's origin at the min[0] and max[1] of the given Envelope.
static RasterGeoReference create(RasterGeoReference.OriginLocation location, Envelope envelope, int width, int height)
          Create a raster reference which has it's origin at the min[0] and max[1] of the given Envelope.
 RasterGeoReference createRelocatedReference(Envelope envelope)
          Returns new RasterGeoReference with the origin set to the min[0],max[1] of the envelope but other values are taken from this instance.
 RasterGeoReference createRelocatedReference(RasterGeoReference.OriginLocation targetLocation)
          Returns new RasterGeoReference with the origin set to the given target location.
 RasterGeoReference createRelocatedReference(RasterGeoReference.OriginLocation targetLocation, Envelope envelope)
          Returns new RasterGeoReference with the origin set to the min[0],max[1] of the envelope and the OriginLocation to the given one.
 ICRS getCrs()
           
 Envelope getEnvelope(int width, int height, ICRS crs)
          Returns an Envelope for a raster with given size.
 Envelope getEnvelope(RasterGeoReference.OriginLocation targetLocation, int width, int height, ICRS crs)
          Returns an Envelope for a raster with given size.
 Envelope getEnvelope(RasterGeoReference.OriginLocation targetLocation, RasterRect rasterRect, ICRS crs)
          Returns an Envelope for a raster with given size and given x,y raster location.
 Envelope getEnvelope(RasterRect rasterRect, ICRS crs)
          Returns an Envelope for a raster with given size and given x,y raster location.
 double[] getOrigin()
           
 double[] getOrigin(RasterGeoReference.OriginLocation target)
           
 double getOriginEasting()
           
 RasterGeoReference.OriginLocation getOriginLocation()
           
 double getOriginNorthing()
           
 int[] getRasterCoordinate(double worldX, double worldY)
          Return the raster coordinate denoted by the given world coordinate.
 double[] getRasterCoordinateUnrounded(double worldX, double worldY)
          Return the raster coordinate denoted by the given world coordinate.
 double getResolutionX()
           
 double getResolutionY()
           
 double getRotationX()
           
 double getRotationY()
           
 int[] getSize(Envelope env)
          Returns the size in pixel of a raster that extends within given Envelope.
 double[] getWorldCoordinate(double rasterX, double rasterY)
          Return the world coordinate denoted by the given raster position.
static RasterGeoReference merger(RasterGeoReference geoRef1, RasterGeoReference geoRef2)
          Merge two Raster references.
 Envelope relocateEnvelope(RasterGeoReference.OriginLocation targetLocation, Envelope envelope)
          Relocates the given minimum and maximum points of the given envelope to the target origin location definition.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RasterGeoReference

public RasterGeoReference(RasterGeoReference.OriginLocation location,
                          double resolutionX,
                          double resolutionY,
                          double rotationX,
                          double rotationY,
                          double origin0,
                          double origin1,
                          ICRS crs)
Constructs a raster reference with given resolutions, origin and rotations. The origin maps to the pixel location given by location.

Parameters:
location - of the origin on the upper left pixel.
resolutionX - the resolution of one pixel on the x axis in the raster
resolutionY - the resolution of one pixel on the y axis in the raster
rotationX - rotation about x-axis
rotationY - rotation about y-axis
origin0 - ordinate of the origin of the first axis defined in the world crs
origin1 - ordinate of the origin of the second axis defined in the world crs
crs - in which the origin is defined.

RasterGeoReference

public RasterGeoReference(RasterGeoReference.OriginLocation location,
                          double resolutionX,
                          double resolutionY,
                          double origin0,
                          double origin1,
                          ICRS crs)
Constructs a raster reference with given resolutions and origin. The origin maps to the pixel location given by location.

Parameters:
location - of the origin on the upper left pixel.
resolutionX - the resolution of one pixel on the x axis in the raster
resolutionY - the resolution of one pixel on the y axis in the raster
origin0 - ordinate of the origin of the first axis defined in the world crs
origin1 - ordinate of the origin of the second axis defined in the world crs
crs - in which the origin is defined.

RasterGeoReference

public RasterGeoReference(RasterGeoReference.OriginLocation location,
                          double resolutionX,
                          double resolutionY,
                          double origin0,
                          double origin1)
Constructs a raster reference with given resolutions and origin. The origin maps to the pixel location given by location. No world CRS is defined.

Parameters:
location - of the origin on the upper left pixel.
resolutionX - the resolution of one pixel on the x axis in the raster
resolutionY - the resolution of one pixel on the y axis in the raster
origin0 - ordinate of the origin of the first axis defined in the world crs
origin1 - ordinate of the origin of the second axis defined in the world crs
Method Detail

create

public static RasterGeoReference create(RasterGeoReference.OriginLocation location,
                                        Envelope envelope,
                                        int width,
                                        int height)
Create a raster reference which has it's origin at the min[0] and max[1] of the given Envelope. The resolution will be determined by getting the easting axis/width and northing-axis/height. If no CRS is available from the Envelope axisorder XY is assumed.

Parameters:
location - of the origin can be center or outer
envelope - to get the appropriate values from.
width - of the underlying raster needed to calculate the resolution.
height - of the underlying raster needed to calculate the resolution.
Returns:
a new RasterGeoReference of null if the given envelope is null

create

public static RasterGeoReference create(RasterGeoReference.OriginLocation location,
                                        Envelope envelope,
                                        double resolution0,
                                        double resolution1)
Create a raster reference which has it's origin at the min[0] and max[1] of the given Envelope. If no CRS is available from the Envelope axisorder XY is assumed.

Parameters:
location - of the origin can be center or outer
envelope - to get the appropriate values from.
resolution0 - of the first axis.
resolution1 - of the second axis.
Returns:
a new RasterGeoReference of null if the given envelope is null

getRasterCoordinate

public int[] getRasterCoordinate(double worldX,
                                 double worldY)
Return the raster coordinate denoted by the given world coordinate. This method is CENTER and OUTER aware.

Parameters:
worldX - x position in the world coordinate system, for which raster coordinates should be calculated.
worldY - y position in the world coordinate system, for which raster coordinates should be calculated.
Returns:
the (rounded) raster coordinate which the given world coordinate maps to.

getRasterCoordinateUnrounded

public double[] getRasterCoordinateUnrounded(double worldX,
                                             double worldY)
Return the raster coordinate denoted by the given world coordinate. This method is CENTER and OUTER aware.

Parameters:
worldX - x position in the world coordinate system, for which raster coordinates should be calculated.
worldY - y position in the world coordinate system, for which raster coordinates should be calculated.
Returns:
the raster coordinate which the given world coordinate maps to.

getWorldCoordinate

public double[] getWorldCoordinate(double rasterX,
                                   double rasterY)
Return the world coordinate denoted by the given raster position. This method is CENTER and OUTER aware.

Parameters:
rasterX - x position in the raster for which world coordinates should be calculated.
rasterY - y position in the raster for which world coordinates should be calculated.
Returns:
the world coordinate which the given raster coordinate maps to.

convertEnvelopeToRasterCRS

public RasterRect convertEnvelopeToRasterCRS(Envelope envelope)
Converts an envelope in world coordinates to raster coordinates, note the envelope in world coordinates is defined over min/max (lower left/upper right), whereas a RasterRect is defined as min(upperleft) with a width and height.

Parameters:
envelope - envelope in world coordinates
Returns:
RasterRect

getEnvelope

public Envelope getEnvelope(int width,
                            int height,
                            ICRS crs)
Returns an Envelope for a raster with given size. The calculation considers the origin and resolution of the raster.

Parameters:
width - in raster coordinates
height - in raster coordinates
crs - the coordinate system for the envelope
Returns:
the calculated envelope

getEnvelope

public Envelope getEnvelope(RasterRect rasterRect,
                            ICRS crs)
Returns an Envelope for a raster with given size and given x,y raster location. The calculation considers the origin and resolution of the this raster.

Parameters:
rasterRect - defining the x,y raster coordinates (as integers) as well as the width and height of the raster.
crs - the coordinate system for the envelope
Returns:
the calculated envelope

getEnvelope

public Envelope getEnvelope(RasterGeoReference.OriginLocation targetLocation,
                            RasterRect rasterRect,
                            ICRS crs)
Returns an Envelope for a raster with given size and given x,y raster location. The calculation considers the origin and resolution of the raster.

Parameters:
targetLocation - of the origin, specifies if the the newly created envelope should consider the origin located at the OUTER or CENTER of a pixel.
rasterRect - defining the x,y raster coordinates (as integers) as well as the width and height of the raster.
crs - the coordinate system for the envelope
Returns:
the calculated envelope

getEnvelope

public Envelope getEnvelope(RasterGeoReference.OriginLocation targetLocation,
                            int width,
                            int height,
                            ICRS crs)
Returns an Envelope for a raster with given size. The calculation considers the origin and resolution of the raster.

Parameters:
targetLocation - of the origin, specifies if the the newly created envelope should consider the origin located at the OUTER or CENTER of a pixel.
width - in raster coordinates
height - in raster coordinates
crs - the coordinate system for the envelope
Returns:
the calculated envelope

getSize

public int[] getSize(Envelope env)
Returns the size in pixel of a raster that extends within given Envelope.

Parameters:
env - Envelope for the
Returns:
array with width and height of the raster

merger

public static RasterGeoReference merger(RasterGeoReference geoRef1,
                                        RasterGeoReference geoRef2)
Merge two Raster references. Returns a new RasterReference where the upper-left corner is set to the values of the smallest upper and smallest left ordinate. The resolution is set to the minimum value (i.e. the highest resolution [unit/pixel]). Some assumptions are made (not checked):

Parameters:
geoRef1 -
geoRef2 -
Returns:
new RasterReference

createRelocatedReference

public RasterGeoReference createRelocatedReference(Envelope envelope)
Returns new RasterGeoReference with the origin set to the min[0],max[1] of the envelope but other values are taken from this instance. Attention, the resulting origin is snapped to the location (center/outer) of the underlying grid, so the min[0] and max[1] values are only approximations to the new origin!

Parameters:
envelope - to get the origin from.
Returns:
new RasterGeoReference or null if the envelope is null

createRelocatedReference

public RasterGeoReference createRelocatedReference(RasterGeoReference.OriginLocation targetLocation,
                                                   Envelope envelope)
Returns new RasterGeoReference with the origin set to the min[0],max[1] of the envelope and the OriginLocation to the given one. Other values are taken from this instance. Attention, the resulting origin is snapped to the location (center/outer) of the underlying grid, so the min[0] and max[1] values are only approximations to the new origin!

Parameters:
targetLocation -
envelope - to get the origin from.
Returns:
new RasterGeoReference or null if the envelope is null

createRelocatedReference

public RasterGeoReference createRelocatedReference(RasterGeoReference.OriginLocation targetLocation)
Returns new RasterGeoReference with the origin set to the given target location. Other values are taken from this instance.

Parameters:
targetLocation - of the new reference
Returns:
new RasterGeoReference or this if the target location is null or equals this one.

relocateEnvelope

public Envelope relocateEnvelope(RasterGeoReference.OriginLocation targetLocation,
                                 Envelope envelope)
Relocates the given minimum and maximum points of the given envelope to the target origin location definition. This method does nothing if the given location equals this RasterGeoReference's origin location. This method effectively adds or subtracts half a resolution of the ordinates of the given Envelope. Different CRS's are supported.

Parameters:
targetLocation - the preferred location of the origin. *
envelope - to relocate.
Returns:
a new Envelope which is aligned with the target location or null if the envelope is null

getOrigin

public double[] getOrigin()
Returns:
the world coordinate of the origin of the geo referenced raster.

getOrigin

public double[] getOrigin(RasterGeoReference.OriginLocation target)
Parameters:
target - the location the new origin, may be null
Returns:
the world coordinate of the origin of the geo referenced raster.

getResolutionX

public double getResolutionX()
Returns:
the resolution on the X axis of the raster, e.g. the units/pixel.

getResolutionY

public double getResolutionY()
Returns:
the resolution on the Y axis of the raster, e.g. the units/pixel.

getRotationX

public double getRotationX()
Returns:
the rotation angle (in radians) for the x axis of the raster.

getRotationY

public double getRotationY()
Returns:
the rotation angle (in radians) for the y axis of the raster.

getOriginLocation

public RasterGeoReference.OriginLocation getOriginLocation()
Returns:
the location of the origin on the upper left pixel of a raster.

toString

public String toString()
Overrides:
toString in class Object

getCrs

public final ICRS getCrs()
Returns:
the crs

getOriginNorthing

public double getOriginNorthing()
Returns:
the northing (y) value of the origin.

getOriginEasting

public double getOriginEasting()
Returns:
the easting (x) value of the origin.


Copyright © 2011. All Rights Reserved.