将 Google Earth Engine 翻译成 Python API:空间连接

Translating Google Earth Engine to Python API: Spatial joins

我目前正在将我的 GEE 从 Javascript 翻译成 Python API。我最初遇到的一个问题是空间连接。我基本上有一个 shapefile 和一系列随机点,我正在尝试生成一个特征集合,它报告每个点的 shapefile 值。语法如下:


#1. A shapefile of sub-Saharan Africa, which I made open for public usage 
SSA = ee.FeatureCollection('users/salem043/Africa_Districts')

#2. 100 random points within the SSA shapefile
points = ee.FeatureCollection.randomPoints(SSA, 100)

#3. The properties I want to retain from the SSA shapefile (admin. districts)
properties = ["ADM0","ADM1", "ADM2"]

#4. This spatial filter function which used to work in Javascript
spatialFilter = ee.Filter.intersects({leftField: '.geo', rightField: '.geo'})

#5. Using the spatial filter and the join command I then create a feature var 

joinAll = ee.Join.saveAll('matched').apply(points, SSA, spatialFilter)


对于 SSA shapefile,link 是:https://code.earthengine.google.com/?asset=users/salem043/Africa_Districts

我收到的错误发生在第 4 步:Python 报告 "name 'leftField' is not defined"。如果你能帮我弄清楚如何将第 4 步(和第 5 步,如果这也会成为问题)中的 Javascript 转换为 Python,我将不胜感激!

使用Python,你需要用"包围字典键。
替换
spatialFilter = ee.Filter.intersects({leftField: '.geo', rightField: '.geo'})
通过
spatialFilter = ee.Filter.intersects({"leftField": '.geo', "rightField": '.geo'})