Class ImageGenerator
- java.lang.Object
-
- org.hortonmachine.gears.utils.images.ImageGenerator
-
public class ImageGenerator extends Object
An utility class for simple image map generation.A sample usage could be the overlay of vector layers.
ImageGenerator imgGen = new ImageGenerator(); imgGen.addFeaturePath(reticolo, null); imgGen.setLayers(); imgGen.dumpPngImage(imagePath, bounds, 300, 300, 100);
- Since:
- 0.7.3
- Author:
- Andrea Antonello (www.hydrologis.com)
-
-
Constructor Summary
Constructors Constructor Description ImageGenerator(IHMProgressMonitor monitor, org.opengis.referencing.crs.CoordinateReferenceSystem forceCrs)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCoveragePath(String coveragePath)Add a new coverage file path.voidaddCoverageRegion(org.geotools.coverage.grid.GridGeometry2D coverageRegion)Add a coverage read region (this has to have same index as addCoveragePath.voidaddFeaturePath(String featurePath, String filter)Add a new feature file path.voidaddShapesPath(String shapesPath)Method to add a file that contains a list of shapes/texts to add.voiddispose()voiddrawImage(Graphics2D g2d, org.geotools.geometry.jts.ReferencedEnvelope ref, int imageWidth, int imageHeight, double buffer)BufferedImagedrawImage(org.geotools.geometry.jts.ReferencedEnvelope ref, int imageWidth, int imageHeight, double buffer)Draw the map on an image.BufferedImagedrawImageWithNewMapContent(org.geotools.geometry.jts.ReferencedEnvelope ref, int imageWidth, int imageHeight, double buffer)Draw the map on an image creating a new MapContent.voiddump2Graphics2D(Graphics2D graphics2d, org.geotools.geometry.jts.ReferencedEnvelope bounds, double scale, EPaperFormat paperFormat, Double dpi, BufferedImage legend, int legendX, int legendY, String scalePrefix, float scaleSize, int scaleX, int scaleY)Create an image for a given paper size and scale.voiddumpJpgImage(String imagePath, org.geotools.geometry.jts.ReferencedEnvelope bounds, int imageWidth, int imageHeight, double buffer, int[] rgbCheck)Writes an image of maps drawn to a jpg file.voiddumpPngImage(String imagePath, org.geotools.geometry.jts.ReferencedEnvelope bounds, int imageWidth, int imageHeight, double buffer, int[] rgbCheck)Writes an image of maps drawn to a png file.voiddumpPngImageForScaleAndPaper(String imagePath, org.geotools.geometry.jts.ReferencedEnvelope bounds, double scale, EPaperFormat paperFormat, Double dpi, BufferedImage legend, int legendX, int legendY, String scalePrefix, float scaleSize, int scaleX, int scaleY)Create an image for a given paper size and scale.BufferedImagegetImageWithCheck(org.geotools.geometry.jts.ReferencedEnvelope bounds, int imageWidth, int imageHeight, double buffer, int[] rgbCheck)Draw the map on an image.org.geotools.geometry.jts.ReferencedEnvelopesetLayers()Set the layers that have to be drawn.voidsetWMS(String wmsURL)Set a WMS service to handle as raster layer.
-
-
-
Constructor Detail
-
ImageGenerator
public ImageGenerator(IHMProgressMonitor monitor, org.opengis.referencing.crs.CoordinateReferenceSystem forceCrs)
-
-
Method Detail
-
addCoveragePath
public void addCoveragePath(String coveragePath)
Add a new coverage file path.The order will be considered. First paths are drawn first.
- Parameters:
coveragePath- the path to add.
-
addCoverageRegion
public void addCoverageRegion(org.geotools.coverage.grid.GridGeometry2D coverageRegion)
Add a coverage read region (this has to have same index as addCoveragePath.- Parameters:
coverageRegion- the region to read.
-
setWMS
public void setWMS(String wmsURL)
Set a WMS service to handle as raster layer.- Parameters:
wmsURL- the WMS url and layer name in the format: http://wmsurl#layername
-
addFeaturePath
public void addFeaturePath(String featurePath, String filter)
Add a new feature file path.The order will be considered. First paths are drawn first.
- Parameters:
featurePath- the path to add.
-
addShapesPath
public void addShapesPath(String shapesPath)
Method to add a file that contains a list of shapes/texts to add.This is applied on top of the final image. Positions are in pixel.
Supported are:
- text;x;y;mytext;colorrgba;size
- box;x;y;w;h;strokewidth;fillrgba;strokergba
- roundedbox;x;y;w;h;round;strokewidth;fillrgba;strokergba
- ...
-
setLayers
public org.geotools.geometry.jts.ReferencedEnvelope setLayers() throws ExceptionSet the layers that have to be drawn.This has to be called before the drawing process.
- Returns:
- the max envelope of the data.
- Throws:
Exception
-
drawImage
public BufferedImage drawImage(org.geotools.geometry.jts.ReferencedEnvelope ref, int imageWidth, int imageHeight, double buffer)
Draw the map on an image.- Parameters:
bounds- the area of interest.imageWidth- the width of the image to produce.imageHeight- the height of the image to produce.buffer- the buffer to add around the map bounds in map units.- Returns:
- the image.
-
drawImage
public void drawImage(Graphics2D g2d, org.geotools.geometry.jts.ReferencedEnvelope ref, int imageWidth, int imageHeight, double buffer)
-
drawImageWithNewMapContent
public BufferedImage drawImageWithNewMapContent(org.geotools.geometry.jts.ReferencedEnvelope ref, int imageWidth, int imageHeight, double buffer)
Draw the map on an image creating a new MapContent.- Parameters:
bounds- the area of interest.imageWidth- the width of the image to produce.imageHeight- the height of the image to produce.buffer- the buffer to add around the map bounds in map units.- Returns:
- the image.
-
dispose
public void dispose()
-
dumpPngImage
public void dumpPngImage(String imagePath, org.geotools.geometry.jts.ReferencedEnvelope bounds, int imageWidth, int imageHeight, double buffer, int[] rgbCheck) throws IOException
Writes an image of maps drawn to a png file.- Parameters:
imagePath- the path to which to write the image.bounds- the area of interest.imageWidth- the width of the image to produce.imageHeight- the height of the image to produce.buffer- the buffer to add around the map bounds in map units.rgbCheck- an rgb tripled. If notnulland the image generated is composed only of that color, then the tile is not generated. This can be useful to avoid generation of empty tiles.- Throws:
IOException
-
dumpJpgImage
public void dumpJpgImage(String imagePath, org.geotools.geometry.jts.ReferencedEnvelope bounds, int imageWidth, int imageHeight, double buffer, int[] rgbCheck) throws IOException
Writes an image of maps drawn to a jpg file.- Parameters:
imagePath- the path to which to write the image.bounds- the area of interest.imageWidth- the width of the image to produce.imageHeight- the height of the image to produce.buffer- the buffer to add around the map bounds in map units.rgbCheck- an rgb tripled. If notnulland the image generated is composed only of that color, then the tile is not generated. This can be useful to avoid generation of empty tiles.- Throws:
IOException
-
getImageWithCheck
public BufferedImage getImageWithCheck(org.geotools.geometry.jts.ReferencedEnvelope bounds, int imageWidth, int imageHeight, double buffer, int[] rgbCheck) throws IOException
Draw the map on an image.- Parameters:
bounds- the area of interest.imageWidth- the width of the image to produce.imageHeight- the height of the image to produce.buffer- the buffer to add around the map bounds in map units.rgbCheck- an rgb tripled. If notnulland the image generated is composed only of that color, then the tile is not generated. This can be useful to avoid generation of empty tiles.- Throws:
IOException
-
dumpPngImageForScaleAndPaper
public void dumpPngImageForScaleAndPaper(String imagePath, org.geotools.geometry.jts.ReferencedEnvelope bounds, double scale, EPaperFormat paperFormat, Double dpi, BufferedImage legend, int legendX, int legendY, String scalePrefix, float scaleSize, int scaleX, int scaleY) throws Exception
Create an image for a given paper size and scale.- Parameters:
imagePath- the path to which to write the image.bounds- the area of interest. In this case only the center is considered. The bounds are recalculated based in paper size and scale.scale- the scale wanted for the map.paperFormat- the paper format to use.dpi- the wanted dpi. Ifnull, 72dpi is used as default.legend- an optional legendimage.legendX- the X position of the legend in the final image.legendY- the Y position of the legend in the final image.scalePrefix- if notnull, this string will be added before the scale definition. Ifnull, no scale definition will be added.scaleSize- a size for the scale.scaleX- the X position of the scale in the final image.scaleY- the X position of the scale in the final image.- Throws:
Exception- Since:
- 0.7.6
-
dump2Graphics2D
public void dump2Graphics2D(Graphics2D graphics2d, org.geotools.geometry.jts.ReferencedEnvelope bounds, double scale, EPaperFormat paperFormat, Double dpi, BufferedImage legend, int legendX, int legendY, String scalePrefix, float scaleSize, int scaleX, int scaleY) throws Exception
Create an image for a given paper size and scale.- Parameters:
imagePath- the path to which to write the image.bounds- the area of interest. In this case only the center is considered. The bounds are recalculated based in paper size and scale.scale- the scale wanted for the map.paperFormat- the paper format to use.dpi- the wanted dpi. Ifnull, 72dpi is used as default.legend- an optional legendimage.legendX- the X position of the legend in the final image.legendY- the Y position of the legend in the final image.scalePrefix- if notnull, this string will be added before the scale definition. Ifnull, no scale definition will be added.scaleSize- a size for the scale.scaleX- the X position of the scale in the final image.scaleY- the X position of the scale in the final image.- Throws:
Exception- Since:
- 0.7.6
-
-