[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.
From: newbies-bounces at openstreetmap.org
[mailto:newbies-bounces at openstreetmap.org] On Behalf Of Vishwa
Sent: 09 May 2008 1:46 PM
Subject: [OSM-newbies] Calculating bounding box of a clipped rectangle
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
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
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) /
6) Calculate bounding box:
bbox_lon = (center.lon- degreesOfRadiusX)
bbox_lon = (center.lon+ degreesOfRadiusX)
bbox_lat = (center.lat- degreesOfLatY);
bbox_lat = (center.lat+ degreesOfLatY);
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?
Any suggestions would be of great help, thanks...
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
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
More information about the dev