[OSM-dev] FW: [OSM-newbies] Calculating bounding box of a clipped rectangle

Andy Robinson (blackadder-lists) ajrlists at googlemail.com
Fri May 9 15:07:38 BST 2008


Forwarded to the Dev list.

-----Original Message-----
From: newbies-bounces at openstreetmap.org
[mailto:newbies-bounces at openstreetmap.org] On Behalf Of Vishwa
Sent: 09 May 2008 1:46 PM
To: newbies
Subject: [OSM-newbies] Calculating bounding box of a clipped rectangle

Hi,

I am developing an application using C#.Net. I have to display map for a
given location and I have built the code to calculate grid of tiles that I
need to pull from tile server and display. However, I have to crop out a
rectangle within the square grid of the map tiles. Also, I have to calculate
the bounding box for the inner rectangle.

Here is my approach:

1) I get the lat lon values for the top-left corner and the bottom-left
corner of the square tile grid
     
     latlon1
     latlon2

2) Convert the lat/lon coordinates to UTM coordinates so that we can find
out a radius value of a imaginative circle circumscribing the square
tilegrid:

   radius_in_meters = utm2.Easting - utm1.Easting

3) For the inner rectangle sides calculate the fractions:
   
    viewX = (rectangle.width/256 * number_of_tiles_in_grid)
    viewY = (rectangle.height/256 * number_of_tiles_in_grid)

4) Radius for the fractions:

     radiusX = (radius_in_meters/ 1000) * viewX
     radiusY = (radius_in_meters/ 1000) * viewY

5) Convert to degrees:

      degreesOfRadiusX = (radiusX / 111.111)
      degreesOfRadiusY = (radiusY / 111.111)

      degreesOfLatY = degreesOfRadiusY * Math.Cos((center.lat* Math.PI) /
180);

6) Calculate bounding box:

  longitudes:
        bbox_lon[0] = (center.lon- degreesOfRadiusX)
        bbox_lon[1] = (center.lon+ degreesOfRadiusX)

  latitudes:
          bbox_lat[0] = (center.lat- degreesOfLatY);
          bbox_lat[1] = (center.lat+ degreesOfLatY);
 
My question:

The bounding box seem to be ok but not accurate. Each location within the
box is off by quite a tens of meters (20-30). 
Is there a better (or simpler?) way of calculating the bounding box for a
clipped rectangle within the square grid of the map tilegrid?
I referred to the opelayers javascript but could not find a function for the
OSM layer.

Any suggestions would be of great help, thanks...

- Vishwa

  





No virus found in this incoming message.
Checked by AVG.
Version: 8.0.100 / Virus Database: 269.23.11/1422 - Release Date: 08/05/2008
5:24 PM


-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: ATT00025.txt
URL: <http://lists.openstreetmap.org/pipermail/dev/attachments/20080509/1b21ca87/attachment.txt>


More information about the dev mailing list