Convert Lat /Lon of User input to Lat/Lon of Open Data I have data from a public data set in gridded form 2.5 degree x 2.5 degree(lat,lon). 
Latitude goes from 90 N to -90 S. Longitude goes from 0 to 357.5. It is stored every 2.5 degrees and there are no intermediate values. 

My user will want to download data from this data set. However they are not restricted from entering only the values that the public data set possesses. My goal then is to convert the data they enter to the "nearest" latitude and longitude of the public data set. For example while data may exist at 5 N and 60 E(and the next pont is 7.5 N and 62.5E) they may enter 6 N and 61.3 E. 

How do I map the user input to the nearest latitude and longitude ? Note - user input will be in the form of a rectangle - lat_min,lat_max, lon_min and lon_max. 

I took a shot at this and I hope I can find a better algorithm through DS SE.

lat_min = floor(lat_min/2.5) * 2.5

lat_max = ceiling(lat_max/2.5) * 2.5

lon_min = floor(lon_min/2.5) * 2.5

lon_max = ceiling(lon_max/2.5) * 2.5
What's wrong with what you've suggested?  It seems fine.

You've supplied four of possible points, essentially:


(latmin, lonmin)
(latmin, lonmax)
(latmax, lonmin)
(latmax, lonmax)


Clearly one of them is the closest grid point to the user input. Then just use whatever distance calculation you like (e.g. Haversine distance, or better measurements if you have access to them) and pick which of the four points is closest to what the user specified.  It'll be accurate and performant.