-
Notifications
You must be signed in to change notification settings - Fork 50
/
spatial_joins.py
37 lines (29 loc) · 984 Bytes
/
spatial_joins.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import ee
import geemap
# Create a map centered at (lat, lon).
Map = geemap.Map(center=[40, -100], zoom=4)
# Load a primary 'collection': protected areas (Yosemite National Park).
primary = ee.FeatureCollection("WCMC/WDPA/current/polygons") \
.filter(ee.Filter.eq('NAME', 'Yosemite National Park'))
# Load a secondary 'collection': power plants.
powerPlants = ee.FeatureCollection('WRI/GPPD/power_plants')
# Define a spatial filter, with distance 100 km.
distFilter = ee.Filter.withinDistance(**{
'distance': 100000,
'leftField': '.geo',
'rightField': '.geo',
'maxError': 10
})
# Define a saveAll join.
distSaveAll = ee.Join.saveAll(**{
'matchesKey': 'points',
'measureKey': 'distance'
})
# Apply the join.
spatialJoined = distSaveAll.apply(primary, powerPlants, distFilter)
# Print the result.
# print(spatialJoined.getInfo())
Map.centerObject(spatialJoined, 10)
Map.addLayer(ee.Image().paint(spatialJoined, 1, 3), {}, 'Spatial Joined')
# Display the map.
Map