I used the following code from this github repo I know it take a point coodinates and return area of 10 sequare Km around it by transforming Km to degree, but I need to make this area to 5 sequare Km for example. how can I achieve that? The only number I found is (3.75) but I'm not sure what it represents and how to change it to get the area I need. I know this might sound obvious for some, but I have zero background in GIS and GEO data and I played around with the code but the results I had didn't make any sense at least for me.

import math

# Distances are measured in kilometers.
# Longitudes and latitudes are measured in degrees.
# Earth is assumed to be perfectly spherical.

earth_radius = 6271.0
degrees_to_radians = math.pi/180.0
radians_to_degrees = 180.0/math.pi

def change_in_latitude(kms):
    "Given a distance north, return the change in latitude."
    return (kms/earth_radius)*radians_to_degrees

def change_in_longitude(latitude, kms):
    "Given a latitude and a distance west, return the change in longitude."
    # Find the radius of a circle around the earth at given latitude.
    r = earth_radius*math.cos(latitude*degrees_to_radians)
    return (kms/r)*radians_to_degrees

def ten_km_square(latitude, longitude):
    slat, nlat = latitude+change_in_latitude(-3.75), latitude+change_in_latitude(3.75)
    wlon = longitude+change_in_longitude(latitude,-3.75)
    elon = longitude+change_in_longitude(latitude, 3.75)
    return(nlat, wlon, slat, elon)

def main(lon, lat):
    '''First argument degrees longitude (E is positive, W negative)
        of the landslide location,
        second argument latitude (N positive, S negative),
        in decimal format(not minutes etc.)'''
    nlat, wlon, slat, elon = ten_km_square(lat,lon)
    #print("(NLat:{:.4f},WLon:{:.4f}),(SLat:{:.4f},ELon:{:.4f});".format(nlat, wlon, slat, elon))
    print("var region = '[[{:.4f},{:.4f}], [{:.4f},{:.4f}], [{:.4f},{:.4f}], [{:.4f},{:.4f}]]';".format(wlon,nlat,elon,nlat,wlon,slat,elon,slat))
    print("var rectangle = [{:.4f},{:.4f},{:.4f},{:.4f}];".format(wlon,slat,elon,nlat))

#change these to longitude, latitude
  • This definitely doesn't make a 10km² square or a square with 10km sides However it does make a square with ~7.5 km (3.75*2) sides and an area of ~58km² (7.5²)
    – Kalak
    Commented Aug 26, 2020 at 6:39

1 Answer 1


Using the code you provided, to get a ~5km² square area you would need a value of 1.118 km instead of 3.75 km

sqrt(5) ~= 2.236 (side of square) / 2 = 1.118 km

  • Thank you! I'm planning to read more about the subject and have a better understanding on how it is calculated :)
    – salRad
    Commented Aug 26, 2020 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.