views:

594

answers:

2

Given a latitude and longitude, and distance, I want to find a bounding box where the distances are less than the given distance.

This questions was asked here: http://stackoverflow.com/questions/238260/how-to-calculate-the-bounding-box-for-a-given-lat-lng-location

I donot want this partcularly accurate, so I have modified and simplified it to

def boundingBox(latitudeInDegrees, longitudeInDegrees, halfSideInKm):
    lat = math.radians(latitudeInDegrees)
    lon = math.radians(longitudeInDegrees)
    halfSide = 1000*halfSideInKm

    RADIUS_OF_EARTH  = 6371
    # Radius of the parallel at given latitude
    pradius = radius*math.cos(lat)

    latMin = lat - halfSide/radius
    latMax = lat + halfSide/radius
    lonMin = lon - halfSide/pradius
    lonMax = lon + halfSide/pradius
    rad2deg = math.degrees
    return (rad2deg(latMin), rad2deg(lonMin), rad2deg(latMax), rad2deg(lonMax))

But I cant understand how this is working, in particular this line makes no sense to me halfSide = 1000*halfSideInKm

+1  A: 

That line is converting the bounding box units from kilometres to metres.

Dominic Rodger
Heh.. obvious now that you mention it, but then `latMin = lat - halfSide/radius` seems wrong. 1Km != 1000/6371 latitude distance as 1deg change in latitude is ~110 km change in distance.
uswaretech
A: 

what is halfside............

susheel