# RE: [OpenMap Users] Calculate scale from Rectangle

From: Gubler, Rüdiger <rgubler_at_init-ka.de>
Date: Tue, 10 Aug 2004 08:13:46 +0200

Hi Ken,

i must set the scale at a value to display a spezified rectangle.
The cos is to correct the different distance between lons at different
lats (Closer to the poles distance is smaller).

Yours Ruediger

> -----Original Message-----
> From: Ken Anderson [mailto:kanderson_at_bbn.com]
> Sent: Monday, August 09, 2004 8:10 PM
> To: Gubler, Rüdiger
> Cc: openmap-users_at_bbn.com; dietrick_at_bbn.com
> Subject: Re: [OpenMap Users] Calculate scale from Rectangle
>
> 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 Tue Aug 10 2004 - 02:17:00 EDT

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