org.geotools.renderer.lite
Class RendererUtilities

Object
  extended by RendererUtilities

public final class RendererUtilities
extends Object

Class for holding utility functions that are common tasks for people using the "StreamingRenderer/Renderer".

Author:
dblasby, Simone Giannecchini

Method Summary
static double calculateOGCScale(ReferencedEnvelope envelope, int imageWidth, Map hints)
          This method performs the computation using the methods suggested by the OGC SLD specification, page 26.
static double calculateOGCScaleAffine(CoordinateReferenceSystem crs, AffineTransform worldToScreen, Map hints)
          This method performs the computation using the methods suggested by the OGC SLD specification, page 26.
static double calculatePixelsPerMeterRatio(double scaleDenominator, Map hints)
          Calculates the pixels per meter ratio based on a scale denominator.
static double calculateScale(Envelope envelope, CoordinateReferenceSystem coordinateReferenceSystem, int imageWidth, int imageHeight, double DPI)
          Deprecated.  
static double calculateScale(ReferencedEnvelope envelope, int imageWidth, int imageHeight, double DPI)
          Find the scale denominator of the map.
static double calculateScale(ReferencedEnvelope envelope, int imageWidth, int imageHeight, Map hints)
          First searches the hints for the scale denominator hint otherwise calls calculateScale(Envelope, CoordinateReferenceSystem, int, int, double).
static Envelope createMapEnvelope(Rectangle paintArea, AffineTransform worldToScreen)
          Creates the map's bounding box in real world coordinates.
static ReferencedEnvelope createMapEnvelope(Rectangle paintArea, AffineTransform worldToScreen, CoordinateReferenceSystem crs)
          Creates the map's bounding box in real world coordinates

NOTE It is worth to note that here we do not take into account the half a pixel translation stated by ogc for coverages bounds.

static Geometry getCentroid(Geometry g)
          Finds the centroid of the input geometry if input = point, line, polygon --> return a point that represents the centroid of that geom if input = geometry collection --> return a multipoint that represents the centoid of each sub-geom
static double getDpi(Map hints)
          Either gets a DPI from the hints, or return the OGC standard, stating that a pixel is 0.28 mm (the result is a non integer DPI...)
static double getStyle2DSize(Style2D style)
           
protected static double rollLatitude(double x)
           
protected static double rollLongitude(double x)
           
static AffineTransform worldToScreenTransform(Envelope mapExtent, Rectangle paintArea)
          Deprecated. Uses the alternative based on ReferencedEnvelope that doe not assume anything on axes order.
static AffineTransform worldToScreenTransform(Envelope mapExtent, Rectangle paintArea, CoordinateReferenceSystem destinationCrs)
          This worldToScreenTransform method makes the assumption that the crs is in Lon,Lat or Lat,Lon.
static AffineTransform worldToScreenTransform(ReferencedEnvelope mapExtent, Rectangle paintArea)
          Sets up the affine transform

NOTE It is worth to note that here we do not take into account the half a pixel translation stated by ogc for coverages bounds.

 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

worldToScreenTransform

public static AffineTransform worldToScreenTransform(Envelope mapExtent,
                                                     Rectangle paintArea)
Deprecated. Uses the alternative based on ReferencedEnvelope that doe not assume anything on axes order.

Sets up the affine transform

((Taken from the old LiteRenderer))

Parameters:
mapExtent - the map extent
paintArea - the size of the rendering output area
Returns:
a transform that maps from real world coordinates to the screen

worldToScreenTransform

public static AffineTransform worldToScreenTransform(ReferencedEnvelope mapExtent,
                                                     Rectangle paintArea)
Sets up the affine transform

NOTE It is worth to note that here we do not take into account the half a pixel translation stated by ogc for coverages bounds. One reason is that WMS 1.1.1 does not follow it!!!

Parameters:
mapExtent - the map extent
paintArea - the size of the rendering output area
Returns:
a transform that maps from real world coordinates to the screen

createMapEnvelope

public static Envelope createMapEnvelope(Rectangle paintArea,
                                         AffineTransform worldToScreen)
                                  throws NoninvertibleTransformException
Creates the map's bounding box in real world coordinates.

Parameters:
worldToScreen - a transform which converts World coordinates to screen pixel coordinates. No assumptions are done on axis order as this is assumed to be pre-calculated. The affine transform may specify an rotation, in case the envelope will encompass the complete (rotated) world polygon.
paintArea - the size of the rendering output area
Returns:
the envelope in world coordinates corresponding to the screen rectangle.
Throws:
NoninvertibleTransformException

createMapEnvelope

public static ReferencedEnvelope createMapEnvelope(Rectangle paintArea,
                                                   AffineTransform worldToScreen,
                                                   CoordinateReferenceSystem crs)
                                            throws NoninvertibleTransformException
Creates the map's bounding box in real world coordinates

NOTE It is worth to note that here we do not take into account the half a pixel translation stated by ogc for coverages bounds. One reason is that WMS 1.1.1 does not follow it!!!

Parameters:
worldToScreen - a transform which converts World coordinates to screen pixel coordinates.
paintArea - the size of the rendering output area
Throws:
NoninvertibleTransformException

calculateScale

public static double calculateScale(Envelope envelope,
                                    CoordinateReferenceSystem coordinateReferenceSystem,
                                    int imageWidth,
                                    int imageHeight,
                                    double DPI)
                             throws TransformException,
                                    FactoryException
Deprecated. 

Find the scale denominator of the map. Method: 1. find the diagonal distance (meters) 2. find the diagonal distance (pixels) 3. find the diagonal distance (meters) -- use DPI 4. calculate scale (#1/#2) NOTE: return the scale denominator not the actual scale (1/scale = denominator) TODO: (SLD spec page 28): Since it is common to integrate the output of multiple servers into a single displayed result in the web-mapping environment, it is important that different map servers have consistent behaviour with respect to processing scales, so that all of the independent servers will select or deselect rules at the same scales. To insure consistent behaviour, scales relative to coordinate spaces must be handled consistently between map servers. For geographic coordinate systems, which use angular units, the angular coverage of a map should be converted to linear units for computation of scale by using the circumference of the Earth at the equator and by assuming perfectly square linear units. For linear coordinate systems, the size of the coordinate space should be used directly without compensating for distortions in it with respect to the shape of the real Earth. NOTE: we are actually doing a a much more exact calculation, and accounting for non-square pixels (which are allowed in WMS) ADDITIONAL NOTE from simboss: I added soe minor fixes. See below.

Parameters:
envelope -
coordinateReferenceSystem -
imageWidth -
imageHeight -
DPI - screen dots per inch (OGC standard is 90)
Throws:
TransformException
FactoryException

calculatePixelsPerMeterRatio

public static double calculatePixelsPerMeterRatio(double scaleDenominator,
                                                  Map hints)
Calculates the pixels per meter ratio based on a scale denominator.

Parameters:
scaleDenominator - The scale denominator value.
hints - The hints used in calculation. if "dpi" key is present, it uses it's Integer value as the dpi of the current device. if not it uses 90 that is the OGC default value.
Returns:
The pixels per meter ratio for the given scale denominator.

calculateOGCScale

public static double calculateOGCScale(ReferencedEnvelope envelope,
                                       int imageWidth,
                                       Map hints)
This method performs the computation using the methods suggested by the OGC SLD specification, page 26.

Parameters:
envelope -
imageWidth -
Returns:

calculateOGCScaleAffine

public static double calculateOGCScaleAffine(CoordinateReferenceSystem crs,
                                             AffineTransform worldToScreen,
                                             Map hints)
This method performs the computation using the methods suggested by the OGC SLD specification, page 26.

Parameters:
CRS - the coordinate reference system. Used to check if we are operating in degrees or meters.
worldToScreen - the transformation mapping world coordinates to screen coordinates. Might specify a rotation in addition to translation and scaling.
Returns:

calculateScale

public static double calculateScale(ReferencedEnvelope envelope,
                                    int imageWidth,
                                    int imageHeight,
                                    Map hints)
                             throws TransformException,
                                    FactoryException
First searches the hints for the scale denominator hint otherwise calls calculateScale(Envelope, CoordinateReferenceSystem, int, int, double). If the hints contains a DPI then that DPI is used otherwise 90 is used (the OGS default).

Throws:
TransformException
FactoryException

getDpi

public static double getDpi(Map hints)
Either gets a DPI from the hints, or return the OGC standard, stating that a pixel is 0.28 mm (the result is a non integer DPI...)

Parameters:
hints -
Returns:
DPI as doubles, to avoid issues with integer trunking in scale computation expression

calculateScale

public static double calculateScale(ReferencedEnvelope envelope,
                                    int imageWidth,
                                    int imageHeight,
                                    double DPI)
                             throws TransformException,
                                    FactoryException
Find the scale denominator of the map. Method: 1. find the diagonal distance (meters) 2. find the diagonal distance (pixels) 3. find the diagonal distance (meters) -- use DPI 4. calculate scale (#1/#2) NOTE: return the scale denominator not the actual scale (1/scale = denominator) TODO: (SLD spec page 28): Since it is common to integrate the output of multiple servers into a single displayed result in the web-mapping environment, it is important that different map servers have consistent behaviour with respect to processing scales, so that all of the independent servers will select or deselect rules at the same scales. To insure consistent behaviour, scales relative to coordinate spaces must be handled consistently between map servers. For geographic coordinate systems, which use angular units, the angular coverage of a map should be converted to linear units for computation of scale by using the circumference of the Earth at the equator and by assuming perfectly square linear units. For linear coordinate systems, the size of the coordinate space should be used directly without compensating for distortions in it with respect to the shape of the real Earth. NOTE: we are actually doing a a much more exact calculation, and accounting for non-square pixels (which are allowed in WMS) ADDITIONAL NOTE from simboss: I added soe minor fixes. See below.

Parameters:
envelope -
imageWidth -
imageHeight -
DPI - screen dots per inch (OGC standard is 90) TODO should I take into account also the destination CRS? Otherwise I am just assuming that the final crs is lon,lat that is it maps lon to x (n raster space) and lat to y (in raster space).
Throws:
TransformException
FactoryException

rollLongitude

protected static double rollLongitude(double x)

rollLatitude

protected static double rollLatitude(double x)

worldToScreenTransform

public static AffineTransform worldToScreenTransform(Envelope mapExtent,
                                                     Rectangle paintArea,
                                                     CoordinateReferenceSystem destinationCrs)
                                              throws TransformException
This worldToScreenTransform method makes the assumption that the crs is in Lon,Lat or Lat,Lon. If the provided envelope does not carry along a crs the assumption that the map extent is in the classic Lon,Lat form. In case the provided envelope is of type. Note that this method takes into account also the OGC standard with respect to the relation between pixels and sample.

Parameters:
mapExtent - The envelope of the map in lon,lat
paintArea - The area to paint as a rectangle
destinationCrs -
Throws:
TransformException

getCentroid

public static Geometry getCentroid(Geometry g)
Finds the centroid of the input geometry if input = point, line, polygon --> return a point that represents the centroid of that geom if input = geometry collection --> return a multipoint that represents the centoid of each sub-geom

Parameters:
g -

getStyle2DSize

public static double getStyle2DSize(Style2D style)


Copyright © 1996-2014 Geotools. All Rights Reserved.