Hi,
I'm trying to calculate a new envelope based on an existing envelope
and a new scale denominator. I thought I had it all worked out, but I
seem to have a problem. The code I'm using looks like this:
public static Envelope calcEnvelope(Envelope e,
CoordinateReferenceSystem crs, double scaleDenom, int width,
int height) throws FactoryException, TransformException {
// Find the diagonal size of the canvas
GeodeticCalculator calculator = new GeodeticCalculator(crs);
double pixelWidth = width / DPI * 2.54 / 100; // 2.54 = cm/inch,
// 100= cm/m
double pixelHeight = height / DPI * 2.54 / 100;
Unit unit = calculator.getEllipsoid().getAxisUnit();
if (unit != SI.METER) {
Converter convert = SI.METER.getConverterTo(unit);
pixelWidth = convert.convert(pixelWidth);
pixelHeight = convert.convert(pixelHeight);
}
double worldWidth = pixelWidth * scaleDenom;
double worldHeight = pixelHeight * scaleDenom;
double centerX = e.getMinX() + e.getWidth() / 2;
double centerY = e.getMinY() + e.getHeight() / 2;
calculator.setAnchorPoint(centerX, centerY);
calculator.setDirection(-90, worldWidth / 2);
Point2D widthPoint = calculator.getDestinationPoint();
calculator.setAnchorPoint(widthPoint.getX(), widthPoint.getY());
calculator.setDirection(0, worldHeight / 2);
Point2D minPoint = calculator.getDestinationPoint();
calculator.setAnchorPoint(minPoint.getX(), minPoint.getY());
double diagonalDist = Math.sqrt(worldWidth * worldWidth + worldHeight
* worldHeight);
calculator.setDirection(45, diagonalDist);
Point2D maxPoint = calculator.getDestinationPoint();
Envelope newEnvelope = new Envelope(minPoint.getX(), maxPoint.getX(),
minPoint.getY(), maxPoint.getY());
return newEnvelope;
}
public static void main(String[] args) throws Exception {
Envelope e = new Envelope(-87.6, -87.4, 44.1, 44.4);
OrderedAxisAuthorityFactory.register("EPSG");
CoordinateReferenceSystem crs = CRS.decode("EPSG:4326");
System.out.println(RendererUtilities.calculateScale(e, crs, 600, 600,
90));
for (int i = 100000; i >= 1000; i = i / 10) {
Envelope env = ScaleUtil.calcEnvelope(e, crs, i, 600, 600);
System.out.println(env);
System.out.println(RendererUtilities.calculateScale(env, crs, 600,
600, 90));
}
}
but when I calculate the new envelope using this, and then use
RendererUtils to calculate the scale denominator I get a different
answer than what I inputed. I'm a bit inexperienced when it comes to
working with things like world to screen transforms and the curvature
of the earth, so any insight any one can provide would be very
helpful. thanks.
-Tom
|