Applying a Join between Features in Google Earth Engine.

Joins are used to combine elements from different collections (e.g. Image Collection or Feature Collection) based on a condition specified by an ee.Filter. The filter is constructed with arguments for the properties in each collection that are related to each other. Specifically, left Field specifies the property in the primary collection that is related to the right Field in the secondary collection. The type of filter (e.g. equals, greater Than Or Equals, less Than, etc.) indicates the relationship between the fields. The type of join indicates one-to-many or one-to-one relationships between the elements in the collections and how many matches to retain. The output of a join is produced by join.apply() and will vary according to the type.

A simple join returns elements from the primary collection that match any element in the secondary collection according to the match condition in the filter. To perform a simple join, use an ee.Join.simple(). This might be useful for finding the common elements among different collections or filtering one collection by another. This article focuses on outlining the process of applying a simple join between two collections in google earth engine.

Select an area of interest.

In Google earth engine, select the area of interest. It can be a point, line or polygon using the geometry tool.

Load table for local parks and location.

Parks are the primary feature collection and the location of the user is the secondary feature.

var location = ee.FeatureCollection(geometry);
var parks = ee.FeatureCollection('users/mutindarisper/nationalparks');
Create a filter.

Apply a filter to pass the left features within a specified distance of the right features. In this case, a distance of 20km is used.

var joinFilter = ee.Filter.withinDistance({
  distance: 20000,
  leftField: 'parks',
  rightField: 'location'
}); 
Apply the join.

The ‘leftfield’ corresponds to the primary collection and the ‘right Field’ corresponds to the secondary collection.  The matching condition is specified by the filter.

var closeParks = ee.Join.simple().apply({
  primary: parks,
  secondary: location,
  condition: joinFilter
});
var bufferedLocation = location.map(function(f) { return f.buffer(20000, 100); });
Display final results.
Map.setCenter(36.06, -0.29, 13);
Map.addLayer(bufferedLocation, {color: 'b0b0b0'}, 'location');
Map.addLayer(closeParks, {color: '008000'}, 'close parks');
Map.addLayer(table, {color: '007000'}, 'All parks');
Location
National Parks
Previous Post

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.