hamidrezaomidvar / LINDER

LINDER (Land use INDexER) is an open-source machine-learning based land use/land cover (LULC) classifier using Sentinel 2 satellite imagery
13 stars 2 forks source link

raise error if lat and long are top and bottom are reveresed #15

Open hamidrezaomidvar opened 4 years ago

hamidrezaomidvar commented 4 years ago

based on @matlipson feedback

matlipson commented 4 years ago

Another solution is a function which takes lat/lon centre and distance and calculates square box, then use those outputs, e.g. :

def calc_box(loc=(51.5846,-1.7981),dist=1000):
    '''calculate latitude and longitude of square box
    Inputs:
        loc: (lat/lon) of location in degrees
        dist: size of box in metres
    Outputs:
        topleft(lat,lon): top left latitude and longitude
        botright(lat,lon): bottom right latitude and longitude
    '''
    earth_radius = 6.3781E6
    lat,lon = loc[0],loc[1]
    lat_rad = lat*np.pi/180.

    ratio_of_circumf = dist/(2*np.pi*earth_radius)
    lat_offset = 0.5*(ratio_of_circumf*360.)
    lon_offset = 0.5*(ratio_of_circumf*360./np.cos(lat_rad))

    topleft = (lat+lat_offset,lon-lon_offset)
    botright = (lat-lat_offset,lon+lon_offset)

    return topleft,botright
hamidrezaomidvar commented 4 years ago

Thanks a lot. very useful. I think it would be good to give two options to users. I will work on this.