Re: [OpenMap Users] Calculate scale from Rectangle

From: Ken Anderson <kanderson_at_bbn.com>
Date: Mon, 09 Aug 2004 14:09:46 -0400

Well, this line
 dlon *= Math.abs(Math.cos(((lat1 + lat2) / 2)));
looks supicious since you don't use any longitude information. I also don't see what i the cos() is for.

If you're using a Proj instance, why can't you just use getScale()?

For great circle distance computatons i'd use
 com.bbn.openmap.geo.Geo

kAt 12:20 PM 8/9/2004 +0200, Gubler, Rüdiger wrote:

>Hi there,
>
>i wrote the following code to calculate scale from a given boundingbox (represented by UpperLeft and LowerRight).
>Unfortunately the result is not really good. Can someone find the error?
>
>public float getScale(LatLonPoint ul, LatLonPoint lr, Projection projection)
>{
> float pixPerDegree = ((Proj) projection).getPlanetPixelCircumference() / 360;
>
> // windowsize
> float height = projection.getHeight();
> float width = projection.getWidth();
>
> // Look at latitude
> float lat1 = ul.getLatitude();
> float lat2 = lr.getLatitude();
> float dlat = Math.abs(lat2 - lat1);
>
> // Look at longitude
> float dlon;
> float lon1 = ul.getLongitude();
> float lon2 = lr.getLongitude();
> // allow for crossing dateline
> if (lon1 > lon2)
> {
> dlon = (180 - lon1) + (180 + lon2);
> }
> else
> {
> dlon = lon2 - lon1;
> }
> dlon *= Math.abs(Math.cos(((lat1 + lat2) / 2)));
>
> float quotientLat = height / dlat;
> float quotientLon = width / dlon;
>
> // The new scale...
> return pixPerDegree / Math.min(quotientLat, quotientLon);
>}
>
>Yours Ruediger

--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Mon Aug 09 2004 - 14:10:24 EDT

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:05 EDT