tables module
restee.tables
features_to_df(session, features)
Fuction to request ee.Feature or ee.FeatureCollection without coordinates as a pandas DataFrame
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
EESession |
restee session autheticated to make requests |
required |
features |
FeatureCollection |
ee.Feature or ee.FeatureCollections to request as a DataFrame |
required |
Returns:
Type | Description |
---|---|
pandas.DataFrame |
ee.FeatureCollection as DataFrame |
Examples:
>>> ndvi = (
ee.ImageCollection('MODIS/006/MOD13Q1')
.select("NDVI")
.first()
)
>>> temp = ee.ImageCollection('OREGONSTATE/PRISM/AN81m')
.filter(ee.Filter.date('2018-07-01', '2018-07-31'));
>>> states = ee.FeatureCollection('TIGER/2018/States')
>>> features = image.reduceRegions(
collection=maine,
reducer=ee.Reducer.mean().setOutputs(["NDVI"]),
scale=image.projection().nominalScale()
)
>>> gdf = restee.features_to_geopandas(session,features)
Source code in restee/tables.py
def features_to_df(session: EESession, features: ee.FeatureCollection):
"""Fuction to request ee.Feature or ee.FeatureCollection without coordinates as a pandas DataFrame
args:
session (EESession): restee session autheticated to make requests
features (ee.Feature | ee.FeatureCollection): ee.Feature or ee.FeatureCollections to
request as a DataFrame
returns:
pandas.DataFrame: ee.FeatureCollection as DataFrame
example:
>>> ndvi = (
ee.ImageCollection('MODIS/006/MOD13Q1')
.select("NDVI")
.first()
)
>>> temp = ee.ImageCollection('OREGONSTATE/PRISM/AN81m')
.filter(ee.Filter.date('2018-07-01', '2018-07-31'));
>>> states = ee.FeatureCollection('TIGER/2018/States')
>>> features = image.reduceRegions(
collection=maine,
reducer=ee.Reducer.mean().setOutputs(["NDVI"]),
scale=image.projection().nominalScale()
)
>>> gdf = restee.features_to_geopandas(session,features)
"""
if isinstance(features, ee.Feature):
features = ee.FeatureCollection([features])
table = _get_table(session, features)
return pd.read_file(StringIO(table.decode()))
features_to_file(session, features, outfile, driver='GeoJSON')
Wrapper fuction to save requested ee.Feature or ee.FeatureCollection in a vector format
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
EESession |
restee session autheticated to make requests |
required |
features |
FeatureCollection |
ee.Feature or ee.FeatureCollections save as file |
required |
outfile |
str |
path to save features |
required |
driver |
str |
valid vector driver name to save file, see |
'GeoJSON' |
Examples:
>>> img = (
ee.ImageCollection('MODIS/006/MOD13Q1')
.select("NDVI")
.first()
)
>>> states = ee.FeatureCollection('TIGER/2018/States')
>>> features = image.reduceRegions(
collection=maine,
reducer=ee.Reducer.mean().setOutputs(["NDVI"]),
scale=image.projection().nominalScale()
)
>>> restee.features_to_file(session,features,"state_ndvi.geojson")
Source code in restee/tables.py
def features_to_file(
session: EESession, features: ee.FeatureCollection, outfile: str, driver: str = "GeoJSON"
):
"""Wrapper fuction to save requested ee.Feature or ee.FeatureCollection in a vector format
args:
session (EESession): restee session autheticated to make requests
features (ee.Feature | ee.FeatureCollection): ee.Feature or ee.FeatureCollections save as file
outfile (str): path to save features
driver (str): valid vector driver name to save file, see `import fiona; fiona.supported_drivers`
for full list of supported drivers . default = "GeoJSON"
example:
>>> img = (
ee.ImageCollection('MODIS/006/MOD13Q1')
.select("NDVI")
.first()
)
>>> states = ee.FeatureCollection('TIGER/2018/States')
>>> features = image.reduceRegions(
collection=maine,
reducer=ee.Reducer.mean().setOutputs(["NDVI"]),
scale=image.projection().nominalScale()
)
>>> restee.features_to_file(session,features,"state_ndvi.geojson")
"""
gdf = features_to_geopandas(session, features)
gdf.to_file(outfile,driver=driver)
return
features_to_geodf(session, features)
Fuction to request ee.Feature or ee.FeatureCollection as a geopandas GeoDataFrame
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session |
EESession |
restee session autheticated to make requests |
required |
features |
FeatureCollection |
ee.Feature or ee.FeatureCollections to request as a GeoDataFrame |
required |
Returns:
Type | Description |
---|---|
geopandas.GeoDataFrame |
ee.FeatureCollection as GeoDataFrame |
Examples:
>>> img = (
ee.ImageCollection('MODIS/006/MOD13Q1')
.select("NDVI")
.first()
)
>>> states = ee.FeatureCollection('TIGER/2018/States')
>>> features = image.reduceRegions(
collection=maine,
reducer=ee.Reducer.mean().setOutputs(["NDVI"]),
scale=image.projection().nominalScale()
)
>>> gdf = restee.features_to_geopandas(session,features)
Source code in restee/tables.py
def features_to_geodf(session: EESession, features: ee.FeatureCollection):
"""Fuction to request ee.Feature or ee.FeatureCollection as a geopandas GeoDataFrame
args:
session (EESession): restee session autheticated to make requests
features (ee.Feature | ee.FeatureCollection): ee.Feature or ee.FeatureCollections to
request as a GeoDataFrame
returns:
geopandas.GeoDataFrame: ee.FeatureCollection as GeoDataFrame
example:
>>> img = (
ee.ImageCollection('MODIS/006/MOD13Q1')
.select("NDVI")
.first()
)
>>> states = ee.FeatureCollection('TIGER/2018/States')
>>> features = image.reduceRegions(
collection=maine,
reducer=ee.Reducer.mean().setOutputs(["NDVI"]),
scale=image.projection().nominalScale()
)
>>> gdf = restee.features_to_geopandas(session,features)
"""
if isinstance(features, ee.Feature):
features = ee.FeatureCollection([features])
table = _get_table(session, features)
return gpd.read_file(StringIO(table.decode()))