public final class RendererUtilities extends Object
Modifier and Type | Method and Description |
---|---|
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 Point |
getPolygonCentroid(Polygon geom)
Finds a centroid for a polygon catching any exceptions resulting from generalization or other
polygon irregularities.
|
static double |
getStyle2DSize(Style2D style) |
protected static double |
rollLatitude(double x) |
protected static double |
rollLongitude(double x) |
static Point |
sampleForInternalPoint(Polygon geom,
Point centroid,
PreparedGeometry pg,
GeometryFactory gf,
double stepSize,
int numSamples)
Uses a sampling technique to obtain a central point that lies inside the specified polygon.
|
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.
|
public static AffineTransform worldToScreenTransform(Envelope mapExtent, Rectangle paintArea)
ReferencedEnvelope
that doe not assume
anything on axes order.((Taken from the old LiteRenderer))
mapExtent
- the map extentpaintArea
- the size of the rendering output areapublic static AffineTransform worldToScreenTransform(ReferencedEnvelope mapExtent, Rectangle paintArea)
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!!!
mapExtent
- the map extentpaintArea
- the size of the rendering output areapublic static Envelope createMapEnvelope(Rectangle paintArea, AffineTransform worldToScreen) throws NoninvertibleTransformException
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 areaNoninvertibleTransformException
public static ReferencedEnvelope createMapEnvelope(Rectangle paintArea, AffineTransform worldToScreen, CoordinateReferenceSystem crs) throws NoninvertibleTransformException
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!!!
worldToScreen
- a transform which converts World coordinates to screen pixel
coordinates.paintArea
- the size of the rendering output areaNoninvertibleTransformException
public static double calculateScale(Envelope envelope, CoordinateReferenceSystem coordinateReferenceSystem, int imageWidth, int imageHeight, double DPI) throws TransformException, FactoryException
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.
envelope
- coordinateReferenceSystem
- imageWidth
- imageHeight
- DPI
- screen dots per inch (OGC standard is 90)TransformException
FactoryException
public static double calculatePixelsPerMeterRatio(double scaleDenominator, Map hints)
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.public static double calculateOGCScale(ReferencedEnvelope envelope, int imageWidth, Map hints)
In GeoTools 12 this method started to take into account units of measure, if this is not desirable in your application you can set the system variable "org.geotoools.render.lite.scale.unitCompensation" to false.
envelope
- imageWidth
- public static double calculateOGCScaleAffine(CoordinateReferenceSystem crs, AffineTransform worldToScreen, Map hints)
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.public static double calculateScale(ReferencedEnvelope envelope, int imageWidth, int imageHeight, Map hints) throws TransformException, FactoryException
calculateScale(Envelope, CoordinateReferenceSystem, int, int, double)
. If the hints
contains a DPI then that DPI is used otherwise 90 is used (the OGS default).TransformException
FactoryException
public static double getDpi(Map hints)
hints
- public static double calculateScale(ReferencedEnvelope envelope, int imageWidth, int imageHeight, double DPI) throws TransformException, FactoryException
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.
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).
TransformException
FactoryException
protected static double rollLongitude(double x)
protected static double rollLatitude(double x)
public static AffineTransform worldToScreenTransform(Envelope mapExtent, Rectangle paintArea, CoordinateReferenceSystem destinationCrs) throws TransformException
Note that this method takes into account also the OGC standard with respect to the relation between pixels and sample.
mapExtent
- The envelope of the map in lon,latpaintArea
- The area to paint as a rectangledestinationCrs
- TransformException
public static Geometry getCentroid(Geometry g)
g
- public static double getStyle2DSize(Style2D style)
public static Point getPolygonCentroid(Polygon geom)
geom
- The polygon.public static Point sampleForInternalPoint(Polygon geom, Point centroid, PreparedGeometry pg, GeometryFactory gf, double stepSize, int numSamples)
Sampling occurs horizontally along the middle of the polygon obtained from the y coordinate of the polygon centroid.
geom
- The polygon.centroid
- The centroid of the polygon, can be null in which case it will be computed
from getPolygonCentroid(Polygon)
.pg
- The prepared version of geom, can be null in which case it will be computed on
demand.gf
- The geometry factory, can be null in which case the polygons factory will be used.Copyright © 1996–2019 Geotools. All rights reserved.