Day 171(Remote Sensing) — Haversine distance & Buffer bounds

For this post, let’s discuss some interesting terms around how to compute the distance between two geolocations(lat & lon) and also how to clip a buffer from the map. As we all basically know if we want to compute the distance between two points, we just subtract them. But the same logic cannot be applied to geolocations represented in terms of latitude and longitude. Let’s take two places (lat = 11.4119347, lon = 76.6584018) and (lat = 11.0120145, lon = 76.8271459) and our objective is to find out the distance between these two points in kilometres. It is also called a great circle distance between two points on the earth.

To calculate such interspace, we use something called Haversine distance(between two points on the spherical earth). The formula for this can be found here. But in python, we have a package that is readily available. The input to the code should be in the format of (latitude, longitude). Let’s check how it is done in the actual code,

from haversine import haversinepoint1 = (11.4119347, 76.6584018)
point2 = (11.0120145, 76.8271459)
haversine(point2, point1)48.12757428881208

Buffer Bounds: Let’s say we are interested in a particular coverage area around geolocation, in order to visualize that in geemap, we have something called buffer and clipping option. We can take a sample scene(image) id “COPERNICUS/S2/20190519T050659_20190519T052127_T43PFN’ where the geopoint [76.6584018,11.4119347] resides.

Now plotting the NDVI index for the entire area and displaying that in geemap,

image_id = 'COPERNICUS/S2/20190519T050659_20190519T052127_T43PFN'Map = geemap.Map()#let's display the ndvi of the first image
image = ee.Image(image_id)
nir = image.select('B5')
red = image.select('B4')
ndvi = nir.subtract(red).divide(nir.add(red)).rename('NDVI')
palette = ['FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901','66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01','012E01', '011D01', '011301']ndviParams = {'min': 0, 'max': 0.5, 'palette': palette}Map.setCenter(76.6584018,11.4119347, 8)
Map.addLayer(ndvi, ndviParams, 'false color composite')
# Display the map
Map

The above picture shows the entire scene which contains the geolocation. But if we want to clip the area based on the buffer size around that point, we can do that by adding another layer (i.e) clip.

roi = ee.Geometry.Point([76.6584018,11.4119347]).buffer(20000)
clipped = image.clip(roi)
Map.addLayer(clipped)

Recommended Reading:

https://pypi.org/project/haversine/

https://www.geeksforgeeks.org/haversine-formula-to-find-distance-between-two-points-on-a-sphere/

AI Enthusiast | Blogger✍