本文整理汇总了Python中ee.FeatureCollection方法的典型用法代码示例。如果您正苦于以下问题:Python ee.FeatureCollection方法的具体用法?Python ee.FeatureCollection怎么用?Python ee.FeatureCollection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ee
的用法示例。
在下文中一共展示了ee.FeatureCollection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addMarker
# 需要导入模块: import ee [as 别名]
# 或者: from ee import FeatureCollection [as 别名]
def addMarker(self, marker, visParams=None, name=None, show=True,
opacity=None, replace=True,
inspect={'data':None, 'reducer':None, 'scale':None}):
""" General method to add Geometries, Features or FeatureCollections
as Markers """
if isinstance(marker, ee.Geometry):
self.addGeometry(marker, visParams, name, show, opacity, replace,
inspect)
elif isinstance(marker, ee.Feature):
self.addFeature(marker, visParams, name, show, opacity, replace,
inspect)
elif isinstance(marker, ee.FeatureCollection):
geometry = marker.geometry()
self.addGeometry(marker, visParams, name, show, opacity, replace,
inspect)
示例2: testBounds
# 需要导入模块: import ee [as 别名]
# 或者: from ee import FeatureCollection [as 别名]
def testBounds(self):
"""Verifies that geometry intersection filters work."""
polygon = ee.Geometry.Polygon(1, 2, 3, 4, 5, 6)
self.assertEquals(
ee.ApiFunction.call_(
'Filter.intersects', '.all',
ee.ApiFunction.call_('Feature', polygon)),
ee.Filter.geometry(polygon))
# Collection-to-geometry promotion.
collection = ee.FeatureCollection('foo')
feature = ee.ApiFunction.call_(
'Feature', ee.ApiFunction.call_('Collection.geometry', collection))
self.assertEquals(
ee.ApiFunction.call_('Filter.intersects', '.all', feature),
ee.Filter.geometry(collection))
示例3: testNestedMapping
# 需要导入模块: import ee [as 别名]
# 或者: from ee import FeatureCollection [as 别名]
def testNestedMapping(self):
"""Verifies that nested map() calls produce distinct variables."""
collection = ee.FeatureCollection('foo')
result = collection.map(lambda x: collection.map(lambda y: [x, y]))
# Verify the signatures.
self.assertEquals(
'_MAPPING_VAR_1_0',
result.args['baseAlgorithm']._signature['args'][0]['name'])
inner_result = result.args['baseAlgorithm']._body
self.assertEquals(
'_MAPPING_VAR_0_0',
inner_result.args['baseAlgorithm']._signature['args'][0]['name'])
# Verify the references.
self.assertEquals(
'_MAPPING_VAR_1_0',
inner_result.args['baseAlgorithm']._body[0].varName)
self.assertEquals(
'_MAPPING_VAR_0_0',
inner_result.args['baseAlgorithm']._body[1].varName)
示例4: GetImageInfoTimeSeries
# 需要导入模块: import ee [as 别名]
# 或者: from ee import FeatureCollection [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']]
示例5: _updateMap
# 需要导入模块: import ee [as 别名]
# 或者: from ee import FeatureCollection [as 别名]
def _updateMap(self):
'''Updates the map with the current class'''
self._clearDrawings() # Remove all existing drawings
if not self.selectedClass:
return
# Convert from current class to an EE feature
coordList = self.classDict[self.selectedClass]
if len(coordList) == 0:
return # Don't try to draw an empty list
if len(coordList) < 3:
eeRing = ee.Geometry.LineString(coordList)
else:
eeRing = ee.Geometry.LinearRing(coordList)
# Add the feature to the map
fc = ee.FeatureCollection(ee.Feature(eeRing))
polyImage = ee.Image().byte().paint(fc, 0, 4)
self.polygonOnMap = polyImage
self.mapWidgetHandle.addToMap(polyImage, {}, self.selectedClass, True)
示例6: assetsize
# 需要导入模块: import ee [as 别名]
# 或者: from ee import FeatureCollection [as 别名]
def assetsize(asset):
ee.Initialize()
header = ee.data.getAsset(asset)["type"]
if header == "IMAGE_COLLECTION":
collc = ee.ImageCollection(asset)
size = collc.aggregate_array("system:asset_size")
return [str(humansize(sum(size.getInfo()))), collc.size().getInfo()]
elif header == "IMAGE":
collc = ee.Image(asset)
return [str(humansize(collc.get("system:asset_size").getInfo())), 1]
elif header == "TABLE":
collc = ee.FeatureCollection(asset)
return [str(humansize(collc.get("system:asset_size").getInfo())), 1]
elif header == "FOLDER":
num = subprocess.check_output(
"earthengine --no-use_cloud_api ls " + asset, shell=True
).decode("ascii")
return ["NA", len(num.split("\n")) - 1]
# folder parse
示例7: enumerateProperty
# 需要导入模块: import ee [as 别名]
# 或者: from ee import FeatureCollection [as 别名]
def enumerateProperty(col, name='enumeration'):
""" Create a list of lists in which each element of the list is:
[index, element]. For example, if you parse a FeatureCollection with 3
Features you'll get: [[0, feat0], [1, feat1], [2, feat2]]
:param collection: the collection
:return: ee.FeatureCollection
"""
enumerated = eecollection.enumerate(col)
def over_list(l):
l = ee.List(l)
index = ee.Number(l.get(0))
element = l.get(1)
return ee.Feature(element).set(name, index)
featlist = enumerated.map(over_list)
return ee.FeatureCollection(featlist)
示例8: getData
# 需要导入模块: import ee [as 别名]
# 或者: from ee import FeatureCollection [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 FeatureCollection [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: addArea
# 需要导入模块: import ee [as 别名]
# 或者: from ee import FeatureCollection [as 别名]
def addArea(feature):
return feature.set({'areaHa': feature.geometry().area().divide(100 * 100)})
# Map the area getting function over the FeatureCollection.
示例11: addField
# 需要导入模块: import ee [as 别名]
# 或者: from ee import FeatureCollection [as 别名]
def addField(feature):
sum = ee.Number(feature.get('property1')).add(feature.get('property2'))
return feature.set({'sum': sum})
# Create a FeatureCollection from a list of Features.
示例12: addStyle
# 需要导入模块: import ee [as 别名]
# 或者: from ee import FeatureCollection [as 别名]
def addStyle(pt):
size = ee.Number(pt.get('capacitymw')).sqrt().divide(10).add(2)
color = fuelColor.get(pt.get('fuel1'))
return pt.set('styleProperty', ee.Dictionary({'pointSize': size, 'color': color}))
# Make a FeatureCollection out of the power plant data table
示例13: nwi_add_color
# 需要导入模块: import ee [as 别名]
# 或者: from ee import FeatureCollection [as 别名]
def nwi_add_color(fc):
emergent = ee.FeatureCollection(
fc.filter(ee.Filter.eq('WETLAND_TY', 'Freshwater Emergent Wetland')))
emergent = emergent.map(lambda f: f.set(
'R', 127).set('G', 195).set('B', 28))
# print(emergent.first())
forested = fc.filter(ee.Filter.eq(
'WETLAND_TY', 'Freshwater Forested/Shrub Wetland'))
forested = forested.map(lambda f: f.set('R', 0).set('G', 136).set('B', 55))
pond = fc.filter(ee.Filter.eq('WETLAND_TY', 'Freshwater Pond'))
pond = pond.map(lambda f: f.set('R', 104).set('G', 140).set('B', 192))
lake = fc.filter(ee.Filter.eq('WETLAND_TY', 'Lake'))
lake = lake.map(lambda f: f.set('R', 19).set('G', 0).set('B', 124))
riverine = fc.filter(ee.Filter.eq('WETLAND_TY', 'Riverine'))
riverine = riverine.map(lambda f: f.set(
'R', 1).set('G', 144).set('B', 191))
fc = ee.FeatureCollection(emergent.merge(
forested).merge(pond).merge(lake).merge(riverine))
base = ee.Image(0).mask(0).toInt8()
img = base.paint(fc, 'R') \
.addBands(base.paint(fc, 'G')
.addBands(base.paint(fc, 'B')))
return img
示例14: testGetMap
# 需要导入模块: import ee [as 别名]
# 或者: from ee import FeatureCollection [as 别名]
def testGetMap(self):
"""Verifies that getMap() uses Collection.draw to rasterize Features."""
feature = ee.Feature(None)
mapid = feature.getMapId({'color': 'ABCDEF'})
manual = ee.ApiFunction.apply_('Collection.draw', {
'collection': ee.FeatureCollection([feature]),
'color': 'ABCDEF'})
self.assertEquals('fakeMapId', mapid['mapid'])
self.assertEquals(manual.serialize(), mapid['image'].serialize())
示例15: testTaskStatus
# 需要导入模块: import ee [as 别名]
# 或者: from ee import FeatureCollection [as 别名]
def testTaskStatus(self):
"""Verifies the return value of Task.status()."""
tasks = ee.batch.Task.list()
self.assertEquals(
{
'state': 'RUNNING',
'creation_timestamp_ms': 7,
'update_timestamp_ms': 42,
'description': 'FirstTestTask',
'id': 'TEST1',
'source_url': 'http://example.org/',
'start_timestamp_ms': 13,
'task_type': 'EXPORT_IMAGE',
}, tasks[0].status())
self.assertTrue(tasks[0].active())
self.assertEquals(
{
'state': 'FAILED',
'creation_timestamp_ms': 17,
'update_timestamp_ms': 142,
'error_message': 'Explosions.',
'description': 'SecondTestTask',
'id': 'TEST2',
'start_timestamp_ms': 113,
'task_type': 'EXPORT_FEATURES',
}, tasks[1].status())
self.assertFalse(tasks[1].active())
new_task = ee.batch.Export.table(ee.FeatureCollection('foo'))
self.assertEquals({
'state': 'UNSUBMITTED',
'creation_timestamp_ms': 0,
'id': 'TESTTASKID',
}, new_task.status())
self.assertFalse(new_task.active())