All Lightspeed views provide a getImage()
method. It returns a BufferedImage
containing a screenshot of the map. You can easily save this image to a PNG or JPEG file using ImageIO
. To save the image to a georeferenced format such as GeoTIFF, a few additional steps are required:
-
Compute the geographic bounds of the image
-
Convert the
BufferedImage
to anALcdImage
-
Encode the
ILcdModel
usingTLcdGeoTIFFModelEncoder
This approach only works for 2D views, where you can use the world reference of the view as the georeference for the GeoTIFF file. |
The following code snippet shows how you can export an image of the Lightspeed view to a GeoTIFF file:
// First, get the screenshot.
ALspAWTView view = ...
BufferedImage screenshot = view.getImage();
// Transform the view's pixel bounds to world coordinates.
TLcdXYBounds viewBounds = new TLcdXYBounds(
0, 0, view.getWidth(), view.getHeight()
);
TLcdXYZBounds worldBounds = new TLcdXYZBounds();
view.getViewXYZWorldTransformation().viewBounds2worldSFCT(viewBounds, worldBounds);
// Construct the ALcdImage using the view's world reference and the computed bounds.
ALcdImage image = TLcdImageBuilder
.newBuilder()
.image(screenshot)
.imageReference((ILcdModelReference) view.getXYZWorldReference())
.bounds(worldBounds)
.buildBasicImage();
// Insert the image into a model.
TLcd2DBoundsIndexedModel model = new TLcd2DBoundsIndexedModel(
image.getConfiguration().getImageReference(),
new TLcdImageModelDescriptor()
);
model.addElement(image, ILcdModel.NO_EVENT);
// Save the model to a GeoTIFF.
TLcdGeoTIFFModelEncoder encoder = new TLcdGeoTIFFModelEncoder();
encoder.export(model, "map.tif");