[OSM-newbies] Calculating bounding box of a clipped rectangle
Vishwa
rnvishwa at gmail.com
Fri May 9 13:46:02 BST 2008
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/newbies/attachments/20080509/f7ab9d9a/attachment.html>
More information about the newbies
mailing list