Properties projProps = new Properties();
projProps.put(ProjectionFactory.CENTER, new LatLonPoint(0f, 0f));
projProps.setProperty(ProjectionFactory.WIDTH, Integer.toString(parameters.width));
projProps.setProperty(ProjectionFactory.HEIGHT, Integer.toString(parameters.height));
Proj projection = parameters.crs.createProjection(projProps);
parameters.crs.prepareProjection(projection);
projection.setScale(projection.getMinScale());
LatLonPoint llp1 = parameters.bboxLatLonMinXY;
LatLonPoint llp2 = parameters.bboxLatLonMaxXY;
System.out.println("bbox toLatLon: 1: " + llp1 + ", 2: " + llp2 + ", center: " + parameters.bboxLatLonCenter);
// guess a center value
// TODO: calculate this from bbox values instead of after latlon converting?
//float centerLat = ((llp2.getLatitude() - llp1.getLatitude()) / 2) + llp1.getLatitude();
//float centerLon = ((llp2.getLongitude() - llp1.getLongitude()) / 2) + llp1.getLongitude();
//projection.setCenter(centerLat, centerLon);
projection.setCenter(parameters.bboxLatLonCenter);
// Debug.output("L1: " + llp1.toString()+", L2: " + llp2.toString();
// TODO: need to set projection.center before using the projection
int intnewwidth = parameters.width;
int intnewheight = parameters.height;
float newscale = projection.getScale(llp1, llp2, new Point(0, 0), new Point(intnewwidth,
intnewheight));
projection.setScale(newscale);
// OGC 01-068r3 (wms 1.1.1) 7.2.3.8. "In the case where the aspect ratio
// of the BBOX and the ratio width/height are different, the WMS shall
// stretch the returned map so that the resulting
// pixels could themselves be rendered in the aspect ratio of the BBOX"
Point xyp1 = projection.forward(llp1);
Point xyp2 = projection.forward(llp2);
int w = xyp2.x - xyp1.x;
int h = xyp1.y - xyp2.y;
if (Math.abs(w - parameters.width) > 2 || Math.abs(h - parameters.height) > 2) {
Debug.output("use aspect ratio fix");
projection.setWidth(w);
projection.setHeight(h);
projection.setCenter(parameters.bboxLatLonCenter);
float underlyingScale = projection.getScale(llp1, llp2, new Point(0, 0),
new Point(w, h));
projection.setScale(underlyingScale);
AspectRatioProjection p = new AspectRatioProjection(projection, parameters.width,
parameters.height);
projection = p;
}