I'm trying to determine ratios of width and height
based on 2 coordinates. I thought this was working
well, but I've run into trouble when I want to
encompass the entire planet.
I'm using GeodeticCalculator to calculate the
difference between the "x"s and "y"s. Unfortunately,
I'm not able to get it working. Any assistance would
be appreciated.
Here's the code - the comments describe where the
problem lies:
public static int calculateImageHeight(int
targetWidth, Coordinate min, Coordinate max, String
crs){
int retVal = targetWidth;
try {
GeographicCRS geoCRS =DefaultGeographicCRS.WGS84;
DefaultEllipsoid e = (DefaultEllipsoid)
CRSUtilities.getHeadGeoEllipsoid(geoCRS);
GeodeticCalculator calc = new
GeodeticCalculator(e);
double minx = min.x;
double miny = min.y;
double maxx = max.x;
double maxy = max.y;
//Get the median
double horz = maxy-((maxy-miny)/2d);
//returns 0, as expected
//Just to make sure the points are different
if (minx==-180&&maxx==180)minx=-179.99999999;
//The order of the Anchor and Dest
//doesn't seem to matter - using
//maxx for the Anchor and minx for
//Dest returns the same value
calc.setAnchorPoint(minx, horz);
calc.setDestinationPoint(maxx, horz);
double w_dist = calc.getOrthodromicDistance();
//result is 0.0011131.....
//This seems a little short
//reset this before recalculating median
minx=min.x;
horz = maxx-((maxx-minx)/2d);
calc.setAnchorPoint(horz, miny);
calc.setDestinationPoint(horz, maxy);
double h_dist = calc.getOrthodromicDistance();
//returns 20003931.4586..
//This seems a lot more reasonable
retVal = (int)((targetWidth/w_dist)*h_dist);
} catch (IllegalArgumentException e) {
logger.error(e, new Throwable(e));
} catch (IllegalStateException e) {
logger.error(e, new Throwable(e));
}
return retVal;
}
The only "dumb question" is the one you were too afraid to ask.
________________________________________
Check out RouteRuler - Free software for runners, cyclists, walkers, etc.
http://routeruler.sourceforge.net
________________________________________
Get a handle on your data with "pocOLAP", the "little" OLAP project
http://pocolap.sourceforge.net
________________________________________
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users