I'm trying to correctly render some features I read from a featuretable of a PostGIS enabled database with GeoTools to an image.
My configuration:
Rendering some features inside a bounding box works fine so far.
The issue: I get a result that is
The features I want to render are based on this CoordinateReferenceSystem
GEOGCS["WGS 84",
DATUM["World Geodetic System 1984",
SPHEROID["WGS 84", 6378137.0, 298.257223563, AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]],
UNIT["degree", 0.017453292519943295],
AXIS["Geodetic latitude", NORTH],
AXIS["Geodetic longitude", EAST],
AUTHORITY["EPSG","4326"]]
I'm aware of excuting an affine transformation, so I have written the following piece of code:
public void render(final MapContext mapContext, final Graphics2D graphics) throws IOException
{
Rectangle renderingArea = new Rectangle(this.mapWidth, this.mapHeight);
GTRenderer renderer = new StreamingRenderer();
renderer.setContext(mapContext);
//move the result to a visisble area
AffineTransform translate = AffineTransform.getTranslateInstance(mapHeight, mapWidth);
//rotate 180° anti-clockwise
AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI);
//exchange x and y
AffineTransform mirror = new AffineTransform(0, 1, 1, 0, 0, 0);
AffineTransform transform = new AffineTransform(translate);
transform.concatenate(rotate);
transform.concatenate(mirror);
graphics.transform(transform);
renderer.paint(graphics, renderingArea, mapContext.getAreaOfInterest());
}
This works and makes the features look fine! On the other hand, this does not feel quite right. The question is, why I can't use the same transformation I applied on the graphics
-object as a method parameter of the renderer's paint
-method?
e.g.
//move the result to a visisble area
AffineTransform translate = AffineTransform.getTranslateInstance(mapHeight, mapWidth);
//rotate 180° anti-clockwise
AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI);
//exchange x and y
AffineTransform mirror = new AffineTransform(0, 1, 1, 0, 0, 0);
AffineTransform transform = new AffineTransform(translate);
transform.concatenate(rotate);
transform.concatenate(mirror);
renderer.paint(graphics, renderingArea, mapContext.getAreaOfInterest(), transform);
This always leads to an empty screen. I think, it is rendered somewhere outside the visible area. I know about the tutorials at the geotools website, but I miss some place where everything is put together.
I'm looking forward to any helpful hints.
The most likely problem is Axis-Order, read this page http://docs.geotools.org/latest/userguide/library/referencing/order.html and see if that solves your problem. If that isn't the issue then you'll probably want to look at the referencing faq - I've never had to write my own affine transform to render features so I would expect the issue to be answered there or in one of the other tutorials.