本文整理汇总了Python中ee.Feature方法的典型用法代码示例。如果您正苦于以下问题:Python ee.Feature方法的具体用法?Python ee.Feature怎么用?Python ee.Feature使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ee
的用法示例。
在下文中一共展示了ee.Feature方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: featurePropertiesOutput
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Feature [as 别名]
def featurePropertiesOutput(feat):
""" generates a string for features properties """
info = feat.getInfo()
properties = info['properties']
theid = info.get('id')
if theid:
stdout = '<h3>ID {}</h3></br>'.format(theid)
else:
stdout = '<h3>Feature has no ID</h3></br>'
if properties:
for prop, value in properties.items():
stdout += '<b>{}</b>: {}</br>'.format(prop, value)
else:
stdout += '<b>Feature has no properties</b>'
return stdout
示例2: testDictionary
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Feature [as 别名]
def testDictionary(self):
"""Verifies basic behavior of ee.Dictionary."""
src = {'a': 1, 'b': 2, 'c': 'three'}
dictionary = ee.Dictionary(src)
self.assertEquals({'type': 'Dictionary', 'value': src},
ee.Serializer(False)._encode(dictionary))
f = ee.Feature(None, {'properties': src})
computed = ee.Dictionary(f.get('properties'))
self.assertTrue(isinstance(computed, ee.Dictionary))
# The 4 types of arguments we expect
cons = (ee.Dictionary(src),
ee.Dictionary(f.get('properties')),
ee.Dictionary(),
ee.Dictionary(('one', 1)))
for d in cons:
self.assertTrue(isinstance(d, ee.ComputedObject))
示例3: testPromotion
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Feature [as 别名]
def testPromotion(self):
"""Verifies object promotion rules."""
self.InitializeApi()
# Features and Images are both already Elements.
self.assertTrue(isinstance(ee._Promote(ee.Feature(None), 'Element'),
ee.Feature))
self.assertTrue(isinstance(ee._Promote(ee.Image(0), 'Element'), ee.Image))
# Promote an untyped object to an Element.
untyped = ee.ComputedObject('foo', {})
self.assertTrue(isinstance(ee._Promote(untyped, 'Element'), ee.Element))
# Promote an untyped variable to an Element.
untyped = ee.ComputedObject(None, None, 'foo')
self.assertTrue(isinstance(ee._Promote(untyped, 'Element'), ee.Element))
self.assertEquals('foo', ee._Promote(untyped, 'Element').varName)
示例4: map
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Feature [as 别名]
def map(self, collection, **kwargs):
""" Map the score over a collection
:param col: collection
:type col: satcol.Collection
:param geom: boundaries geometry
:type geom: ee.Geometry or ee.Feature
"""
col = kwargs.get('col')
geom = kwargs.get('geom')
minscale = min([band.scale for band in col.bands])
def wrap(img):
score = self.compute(img, geometry=geom, scale=minscale,
count_zeros=self.count_zeros)
prop = score.get(self.name)
return img.addBands(score).set(self.name, prop)
return collection.map(wrap)
示例5: GetImageInfoTimeSeries
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Feature [as 别名]
def GetImageInfoTimeSeries(aoi):
def GetImageInfo(img):
return ee.Feature(None, {
'id': img.get('system:id'),
'time': img.get('system:time_start'),
'cloud_cover': img.get('CLOUD_COVER')
})
def ToFeatureCollection(imageCollectionName):
return ee.FeatureCollection(ee.ImageCollection(imageCollectionName).filterBounds(aoi).map(GetImageInfo))
collectionNames = [
'LANDSAT/LT4_L1T_TOA',
'LANDSAT/LT5_L1T_TOA',
'LANDSAT/LE7_L1T_TOA',
'LANDSAT/LC8_L1T_TOA'
]
fc = ee.FeatureCollection([])
for n in collectionNames:
fc = fc.merge(ToFeatureCollection(n))
info = fc.sort('time').getInfo()
return [i['properties'] for i in info['features']]
示例6: feature
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Feature [as 别名]
def feature(info):
""" Dispatch a ee.Feature """
geom = info.get('geometry')
geomtype = geom.get('type')
props = info.get('properties')
# Contruct an accordion with the geometries
acc = geometry(geom)
children = list(acc.children)
# Properties
if props:
# dispatch properties
prop_acc = dispatch(props)
else:
prop_acc = dispatch('Feature has no properties')
# Append properties as a child
children.append(prop_acc.widget)
acc.set_title(1, 'properties')
acc.children = children
acc.selected_index = None
# Geometry Type
typewid = dispatch(geomtype)
return acc
示例7: getGeojsonTile
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Feature [as 别名]
def getGeojsonTile(geometry, name=None,
inspect={'data':None, 'reducer':None, 'scale':None}):
''' Get a GeoJson giving a ee.Geometry or ee.Feature '''
if isinstance(geometry, ee.Feature):
feat = geometry
geometry = feat.geometry()
else:
feat = None
info = geometry.getInfo()
type = info['type']
gjson_types = ['Polygon', 'LineString', 'MultiPolygon',
'LinearRing', 'MultiLineString', 'MultiPoint',
'Point', 'Polygon', 'Rectangle',
'GeometryCollection']
# newname = name if name else "{} {}".format(type, map.added_geometries)
if type in gjson_types:
data = inspect['data']
if feat:
default_popup = featurePropertiesOutput(feat)
else:
default_popup = type
red = inspect.get('reducer','first')
sca = inspect.get('scale', None)
popval = getData(geometry, data, red, sca, name) if data else default_popup
geojson = geometry.getInfo()
return {'geojson':geojson,
'pop': popval}
# 'name': newname}
else:
print('unrecognized object type to add to map')
示例8: getData
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Feature [as 别名]
def getData(geometry, obj, reducer='first', scale=None, name=None):
''' Get data from an ee.ComputedObject using a giving ee.Geometry '''
accepted = (ee.Image, ee.ImageCollection, ee.Feature, ee.FeatureCollection)
reducers = {'first': ee.Reducer.first(),
'mean': ee.Reducer.mean(),
'median': ee.Reducer.median(),
'sum':ee.Reducer.sum()}
if not isinstance(obj, accepted):
return "Can't get data from that Object"
elif isinstance(obj, ee.Image):
t = geometry.type().getInfo()
# Try to get the image scale
scale = obj.select([0]).projection().nominalScale().getInfo() \
if not scale else scale
# Reduce if computed scale is too big
scale = 1 if scale > 500 else scale
if t == 'Point':
values = tools.image.getValue(obj, geometry, scale, 'client')
val_str = '<h3>Data from {}'.format(name)
for key, val in values.items():
val_str += '<b>{}:</b> {}</br>'.format(key, val)
return val_str
elif t == 'Polygon':
red = reducer if reducer in reducers.keys() else 'first'
values = obj.reduceRegion(reducers[red], geometry, scale, maxPixels=1e13).getInfo()
val_str = '<h3>{}:</h3>\n'.format(red)
for key, val in values.items():
val_str += '<b>{}:</b> {}</br>'.format(key, val)
return val_str
示例9: paint
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Feature [as 别名]
def paint(geometry, outline_color='black', fill_color=None, outline=2):
""" Paint a Geometry, Feature or FeatureCollection """
def overlap(image_back, image_front):
mask_back = image_back.mask()
mask_front = image_front.mask()
entire_mask = mask_back.add(mask_front)
mask = mask_back.Not()
masked = image_front.updateMask(mask).unmask()
return masked.add(image_back.unmask()).updateMask(entire_mask)
if isinstance(geometry, ee.Feature) or isinstance(geometry, ee.FeatureCollection):
geometry = geometry.geometry()
if fill_color:
fill = ee.Image().paint(geometry, 1).visualize(palette=[fill_color])
if outline_color:
out = ee.Image().paint(geometry, 1, outline).visualize(palette=[outline_color])
if fill_color and outline_color:
rgbVector = overlap(out, fill)
elif fill_color:
rgbVector = fill
else:
rgbVector = out
return rgbVector
示例10: addFeature
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Feature [as 别名]
def addFeature(self, feature, visParams=None, name=None, show=True,
opacity=None, replace=True,
inspect={'data':None, 'reducer':None, 'scale':None}):
""" Add a Feature to the Map
:param feature: the Feature to add to Map
:type feature: ee.Feature
:param visParams:
:type visParams: dict
:param name: name for the layer
:type name: str
:param inspect: when adding a geometry or a feature you can pop up data
from a desired layer. Params are:
:data: the EEObject where to get the data from
:reducer: the reducer to use
:scale: the scale to reduce
:type inspect: dict
:return: the name of the added layer
:rtype: str
"""
thename = name if name else 'Feature {}'.format(self.addedGeometries)
# Check if layer exists
if thename in self.EELayers.keys():
if not replace:
print("Layer with name '{}' exists already, please choose another name".format(thename))
return
else:
self.removeLayer(thename)
params = getGeojsonTile(feature, thename, inspect)
layer = ipyleaflet.GeoJSON(data=params['geojson'],
name=thename,
popup=HTML(params['pop']))
self._add_EELayer(thename, {'type': 'Feature',
'object': feature,
'visParams': None,
'layer': layer})
return thename
示例11: sampling
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Feature [as 别名]
def sampling(sample):
lat = sample.get('latitude')
lon = sample.get('longitude')
ch4 = sample.get('ch4')
return ee.Feature(ee.Geometry.Point([lon, lat]), {'ch4': ch4})
# Import two weeks of S5P methane and composite by mean.
示例12: extract_landsat
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Feature [as 别名]
def extract_landsat(feature):
geom = ee.Feature(feature).geometry()
image = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR') \
.filterDate('2019-01-01', '2019-12-31') \
.filterBounds(geom) \
.median() \
.clip(geom)
return image
# Select the first five U.S. counties
示例13: getGeom
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Feature [as 别名]
def getGeom(image):
return ee.Feature(image.geometry().centroid(), {'foo': 1})
# Load a Landsat 8 collection.
示例14: createFeature
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Feature [as 别名]
def createFeature(transition_class_stats):
transition_class_stats = ee.Dictionary(transition_class_stats)
class_number = transition_class_stats.get('transition_class_value')
result = {
'transition_class_number': class_number,
'transition_class_''name': lookup_names.get(class_number),
'transition_class_''palette': lookup_palette.get(class_number),
'area_m2': transition_class_stats.get('sum')
}
return ee.Feature({}, result) # Creates a feature without a geometry.
# Create a JSON dictionary that defines piechart colors based on the
# transition class palette.
# https:#developers.google.com/chart/interactive/docs/gallery/piechart
示例15: makefeature
# 需要导入模块: import ee [as 别名]
# 或者: from ee import Feature [as 别名]
def makefeature(data):
''' for exporting as CSV to Drive '''
return ee.Feature(None, {'data': data})