GEE中FeatureCollection对中文属性select无法取值的解决方法

GEE中FeatureCollection对中文属性select无法取值的解决方法

问题发现

将含有中文列的csv上传至GEE后,使用select函数取出中文列,代码如下所示:

// An highlighted block
var sampleTraining = validated.select(['粮食产量(万吨)', 'classification']);

上述代码中,sampleTraining是FeatureCollection,其properties中是含有该中文列名的,但是运行代码后却没有中文列。

问题解决

经过调试,发现是中文列名中的括号需要进行转义,将上述代码改成如下形式即可:

// An highlighted block
var sampleTraining = validated.select(['粮食产量\\(万吨\\)', 'classification']);
在Colab中调用Google Earth Engine(GEE)里自己的FeatureCollection的Point集合,可按以下步骤操作: ### 1. 安装并初始化Google Earth Engine Python API 首先,要在Colab环境里安装Google Earth Engine Python API,并且完成初始化工作。 ```python import ee # 安装Google Earth Engine Python API !pip install earthengine-api # 初始化Google Earth Engine ee.Authenticate() ee.Initialize() ``` ### 2. 调用自己的FeatureCollection的Point集合 假设已将Point集合保存到GEE的资产中,可使用`ee.FeatureCollection`函数来调用。 ```python # 替换为你自己的FeatureCollection资产ID feature_collection_id = 'users/your_username/your_feature_collection' # 调用FeatureCollection point_collection = ee.FeatureCollection(feature_collection_id) ``` ### 3. 验证是否成功调用 可以通过打印一些基本信息来验证是否成功调用Point集合。 ```python # 打印Point集合的数量 count = point_collection.size().getInfo() print(f'Point集合中的要素数量: {count}') # 打印Point集合的第一个要素 first_point = point_collection.first().getInfo() print('第一个Point要素信息:') print(first_point) ``` ### 完整代码示例 ```python import ee # 安装Google Earth Engine Python API !pip install earthengine-api # 初始化Google Earth Engine ee.Authenticate() ee.Initialize() # 替换为你自己的FeatureCollection资产ID feature_collection_id = 'users/your_username/your_feature_collection' # 调用FeatureCollection point_collection = ee.FeatureCollection(feature_collection_id) # 打印Point集合的数量 count = point_collection.size().getInfo() print(f'Point集合中的要素数量: {count}') # 打印Point集合的第一个要素 first_point = point_collection.first().getInfo() print('第一个Point要素信息:') print(first_point) ``` ### 注意事项 - 要把`users/your_username/your_feature_collection`替换成你自己的FeatureCollection资产ID。 - 运行`ee.Authenticate()`时,会弹出验证链接,按照提示完成验证操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值