Python处特定经纬度点的输出值
Output value of a specific latitude and longitude point at Python
由于我的解释较短,我在 2020/01/20 编辑了这个问题。抱歉原来的回答者。
我想要特定纬度/经度波段的TOA反射率值。
我可以通过下面的代码用 javascript 做到这一点,但我不能用 python 做同样的事情。
我很高兴能得到你未来的帮助。
var start = '2018-01-01'
var end = '2018-01-16'
var lon = 134.01
var lat = 34.04
var p = ee.Geometry.Point(lon, lat)
var imageCollection = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
.filterDate(start, end)
.filterBounds(p)
var im1 = imageCollection
.first()
var image = ee.Image(im1);
// Extract the data
var data_b1 = im1.select("B1").reduceRegion(ee.Reducer.mean(),p,10).get("B1")
print('B1 T1_TOA: ', data_b1)
Javascript 输出是这个 TOA 反射率:
B1 T1_TOA:
0.25892749428749084
但在 Python 时效果不佳。
输出为 ComputedObject,但不包含 TOA 反射率值。
import ee
ee.Initialize()
start = '2018-01-01'
end = '2018-01-16'
lon = 134.01
lat = 34.04
p = ee.Geometry.Point([lon, lat])
imageCollection = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA').filterDate(start, end).filterBounds(p)
im1 = imageCollection.first()
data_b1 = im1.select("B1").reduceRegion(ee.Reducer.mean(),p,10).get("B1")
print(data_b1)
输出低于 json,不包括 TOA 反射率值“0.25892749428749084”:
ee.ComputedObject({
"type": "Invocation",
"arguments": {
"dictionary": {
"type": "Invocation",
"arguments": {
"image": {
"type": "Invocation",
"arguments": {
"input": {
"type": "Invocation",
"arguments": {
"collection": {
"type": "Invocation",
"arguments": {
"collection": {
"type": "Invocation",
"arguments": {
"collection": {
"type": "Invocation",
"arguments": {
"id": "LANDSAT/LC08/C01/T1_TOA"
},
"functionName": "ImageCollection.load"
},
"filter": {
"type": "Invocation",
"arguments": {
"rightField": "system:time_start",
"leftValue": {
"type": "Invocation",
"arguments": {
"start": "2018-01-01",
"end": "2018-01-16"
},
"functionName": "DateRange"
}
},
"functionName": "Filter.dateRangeContains"
}
},
"functionName": "Collection.filter"
},
"filter": {
"type": "Invocation",
"arguments": {
"leftField": ".all",
"rightValue": {
"type": "Invocation",
"arguments": {
"geometry": {
"type": "Point",
"coordinates": [
134.01,
34.04
]
}
},
"functionName": "Feature"
}
},
"functionName": "Filter.intersects"
}
},
"functionName": "Collection.filter"
}
},
"functionName": "Collection.first"
},
"bandSelectors": [
"B1"
]
},
"functionName": "Image.select"
},
"reducer": {
"type": "Invocation",
"arguments": {},
"functionName": "Reducer.mean"
},
"geometry": {
"type": "Point",
"coordinates": [
134.01,
34.04
]
},
"scale": 10
},
"functionName": "Image.reduceRegion"
},
"key": "B1"
},
"functionName": "Dictionary.get"
})
我发现您的 python 代码有效。首先,我在此 link https://earthengine.google.com 注册了 Google Earth Engine。然后我在 Google Colab 上安装 earthengine-api 包。当您执行代码时,您会看到一条消息,要求您授权 Earth Engine 所需的访问权限。请按照说明进行操作。
Python代码:
import ee
# Trigger the authentication flow.
ee.Authenticate()
# Initialize the library.
ee.Initialize()
lat = 35.1000
lon = 135.2000
p = ee.Geometry.Point([lon, lat])
start = '2017-11-21'
end = '2017-12-30'
imageCollection = ee.ImageCollection('LANDSAT/LC08/C01/T1').filterDate(start, end).filterBounds(p)
im1 = imageCollection.sort('CLOUD_COVER', True).first()
data_b1 = im1.select("B1").reduceRegion(ee.Reducer.mean(),p,10).get("B1")
print(data_b1)
执行代码时的消息提示示例
输出结果。
您需要将服务器端对象转换为客户端对象。尝试:
print(data_b1.getInfo())
有关使用 Python API 打印 Earth Engine 对象的更多信息,请参阅此 guide。
由于我的解释较短,我在 2020/01/20 编辑了这个问题。抱歉原来的回答者。
我想要特定纬度/经度波段的TOA反射率值。 我可以通过下面的代码用 javascript 做到这一点,但我不能用 python 做同样的事情。 我很高兴能得到你未来的帮助。
var start = '2018-01-01'
var end = '2018-01-16'
var lon = 134.01
var lat = 34.04
var p = ee.Geometry.Point(lon, lat)
var imageCollection = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
.filterDate(start, end)
.filterBounds(p)
var im1 = imageCollection
.first()
var image = ee.Image(im1);
// Extract the data
var data_b1 = im1.select("B1").reduceRegion(ee.Reducer.mean(),p,10).get("B1")
print('B1 T1_TOA: ', data_b1)
Javascript 输出是这个 TOA 反射率:
B1 T1_TOA:
0.25892749428749084
但在 Python 时效果不佳。 输出为 ComputedObject,但不包含 TOA 反射率值。
import ee
ee.Initialize()
start = '2018-01-01'
end = '2018-01-16'
lon = 134.01
lat = 34.04
p = ee.Geometry.Point([lon, lat])
imageCollection = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA').filterDate(start, end).filterBounds(p)
im1 = imageCollection.first()
data_b1 = im1.select("B1").reduceRegion(ee.Reducer.mean(),p,10).get("B1")
print(data_b1)
输出低于 json,不包括 TOA 反射率值“0.25892749428749084”:
ee.ComputedObject({
"type": "Invocation",
"arguments": {
"dictionary": {
"type": "Invocation",
"arguments": {
"image": {
"type": "Invocation",
"arguments": {
"input": {
"type": "Invocation",
"arguments": {
"collection": {
"type": "Invocation",
"arguments": {
"collection": {
"type": "Invocation",
"arguments": {
"collection": {
"type": "Invocation",
"arguments": {
"id": "LANDSAT/LC08/C01/T1_TOA"
},
"functionName": "ImageCollection.load"
},
"filter": {
"type": "Invocation",
"arguments": {
"rightField": "system:time_start",
"leftValue": {
"type": "Invocation",
"arguments": {
"start": "2018-01-01",
"end": "2018-01-16"
},
"functionName": "DateRange"
}
},
"functionName": "Filter.dateRangeContains"
}
},
"functionName": "Collection.filter"
},
"filter": {
"type": "Invocation",
"arguments": {
"leftField": ".all",
"rightValue": {
"type": "Invocation",
"arguments": {
"geometry": {
"type": "Point",
"coordinates": [
134.01,
34.04
]
}
},
"functionName": "Feature"
}
},
"functionName": "Filter.intersects"
}
},
"functionName": "Collection.filter"
}
},
"functionName": "Collection.first"
},
"bandSelectors": [
"B1"
]
},
"functionName": "Image.select"
},
"reducer": {
"type": "Invocation",
"arguments": {},
"functionName": "Reducer.mean"
},
"geometry": {
"type": "Point",
"coordinates": [
134.01,
34.04
]
},
"scale": 10
},
"functionName": "Image.reduceRegion"
},
"key": "B1"
},
"functionName": "Dictionary.get"
})
我发现您的 python 代码有效。首先,我在此 link https://earthengine.google.com 注册了 Google Earth Engine。然后我在 Google Colab 上安装 earthengine-api 包。当您执行代码时,您会看到一条消息,要求您授权 Earth Engine 所需的访问权限。请按照说明进行操作。
Python代码:
import ee
# Trigger the authentication flow.
ee.Authenticate()
# Initialize the library.
ee.Initialize()
lat = 35.1000
lon = 135.2000
p = ee.Geometry.Point([lon, lat])
start = '2017-11-21'
end = '2017-12-30'
imageCollection = ee.ImageCollection('LANDSAT/LC08/C01/T1').filterDate(start, end).filterBounds(p)
im1 = imageCollection.sort('CLOUD_COVER', True).first()
data_b1 = im1.select("B1").reduceRegion(ee.Reducer.mean(),p,10).get("B1")
print(data_b1)
执行代码时的消息提示示例
输出结果。
您需要将服务器端对象转换为客户端对象。尝试:
print(data_b1.getInfo())
有关使用 Python API 打印 Earth Engine 对象的更多信息,请参阅此 guide。