geetools.FeatureCollection
#
Toolbox for the ee.FeatureCollection class.
Package Contents#
Classes#
Toolbox for the ee.FeatureCollection class. |
- class geetools.FeatureCollection.FeatureCollectionAccessor(obj)[source]#
Toolbox for the ee.FeatureCollection class.
Initialize the FeatureCollection class.
- Parameters:
obj (ee.FeatureCollection) –
- addId(name='id', start=1)[source]#
Add a unique numeric identifier, starting from parameter
start
.- Returns:
The parsed collection with a new id property
- Parameters:
name (geetools.types.ee_str) –
start (geetools.types.ee_int) –
- Return type:
ee.FeatureCollection
Example
import ee import geetools ee.Initialize() fc = ee.FeatureCollection('FAO/GAUL/2015/level0') fc = fc.geetools.addId() print(fc.first().get('id').getInfo())
- byFeatures(featureId='system:index', properties=[], labels=[])[source]#
Get a dictionary with all property values for each feature.
This method is returning a dictionary with all the feature ids as keys and their properties as a dictionary.
{ "feature1": {"property1": value1, "property2": value2, ...}, "feature2": {"property1": value1, "property2": value2, ...}, ... }
The output remain server side and can be used to create a client side plot.
- Parameters:
featureId (geetools.types.ee_str) – The property to use as the feature id. Defaults to “system:index”. This property needs to be a string property.
properties (geetools.types.ee_list) – A list of properties to get the values from.
labels (list) – A list of names to replace properties names. Default to the properties names.
- Returns:
A dictionary with all the feature ids as keys and their properties as a dictionary.
- Return type:
ee.Dictionary
Examples
import ee, geetools fc = ee.FeatureCollection("FAO/GAUL/2015/level2").limit(10) d = fc.geetools.byFeature(featureId="ADM2_CODE", properties=["ADM0_CODE"]) d.getInfo()
- byProperties(featureId='system:index', properties=[], labels=[])[source]#
Get a dictionary with all feature values for each properties.
This method is returning a dictionary with all the properties as keys and their values in each feaure as a list.
{ "property1": {"feature1": value1, "feature2": value2, ...}, "property2": {"feature1": value1, "feature2": value2, ...}, ... }
The output remain server side and can be used to create a client side plot.
- Parameters:
featureId (geetools.types.ee_str) – The property used to label features. Defaults to “system:index”.
properties (geetools.types.ee_list) – A list of properties to get the values from.
labels (list) – A list of names to replace properties names. Default to the properties names.
- Returns:
A dictionary with all the properties as keys and their values in each feaure as a list.
- Return type:
ee.Dictionary
Example
import ee, geetools fc = ee.FeatureCollection("FAO/GAUL/2015/level2").limit(10) d = fc.geetools.byProperties(["ADM1_CODE", "ADM2_CODE"]) d.getInfo()
- mergeGeometries()[source]#
Merge the geometries the included features.
- Returns:
the dissolved geometry
- Return type:
ee.Geometry
Example
import ee import geetools ee.Initialize() fc = ee.FeatureCollection("FAO/GAUL/2015/level0") fc =fc.filter(ee.Filter.inList("ADM0_CODE", [122, 237, 85])) geom = fc.geetools.mergeGeometries() print(geom.getInfo())
- plot_by_features(type='bar', featureId='system:index', properties=[], labels=[], colors=[], ax=None, **kwargs)[source]#
Plot the values of a
ee.FeatureCollection
by feature.Each feature property selected in properties will be plotted using the
featureId
as the x-axis. If noproperties
are provided, all properties will be plotted. If nofeatureId
is provided, the “system:index” property will be used.- Parameters:
type (str) – The type of plot to use. Defaults to “bar”. can be any type of plot from the python lib matplotlib.pyplot. If the one you need is missing open an issue!
featureId (str) – The property to use as the x-axis (name the features). Defaults to “system:index”.
properties (list) – A list of properties to plot. Defaults to all properties.
labels (list) – A list of labels to use for plotting the properties. If not provided, the default labels will be used. It needs to match the properties length.
colors (list) – A list of colors to use for plotting the properties. If not provided, the default colors from the matplotlib library will be used.
ax (Optional[matplotlib.axes.Axes]) – The matplotlib axes to use. If not provided, the plot will be send to a new figure.
kwargs – Additional arguments from the
pyplot
function.
- Return type:
matplotlib.axes.Axes
Examples
import ee, geetools fc = ee.FeatureCollection("FAO/GAUL/2015/level2").limit(10) fc.geetools.plot_by_features(properties=["ADM1_CODE", "ADM2_CODE"])
Note
This function is a client-side function.
- plot_by_properties(type='bar', featureId='system:index', properties=[], labels=[], colors=[], ax=None, **kwargs)[source]#
Plot the values of a FeatureCollection by property.
Each features will be represented by a color and each property will be a bar of the bar chart.
- Parameters:
type (str) – The type of plot to use. Defaults to “bar”. can be any type of plot from the python lib matplotlib.pyplot. If the one you need is missing open an issue!
featureId (str) – The property to use as the y-axis (name the features). Defaults to “system:index”.
properties (geetools.types.ee_list) – A list of properties to plot. Defaults to all properties.
labels (list) – A list of labels to use for plotting the properties. If not provided, the default labels will be used. It needs to match the properties length.
colors (list) – A list of colors to use for plotting the properties. If not provided, the default colors from the matplotlib library will be used.
ax (Optional[matplotlib.axes.Axes]) – The matplotlib axes to use. If not provided, the plot will be send to a new figure.
kwargs – Additional arguments from the
pyplot
function.
- Return type:
matplotlib.axes.Axes
Examples
import ee, geetools fc = ee.FeatureCollection("FAO/GAUL/2015/level2").limit(10) fc.geetools.plot_by_properties(xProperties=["ADM1_CODE", "ADM2_CODE"])
Note
This function is a client-side function.
- plot_hist(property, label='', ax=None, color=None, **kwargs)[source]#
Plot the histogram of a specific property.
- Parameters:
property (geetools.types.ee_str) – The property to display
label (str) – The label to use for the property. If not provided, the property name will be used.
ax (Optional[matplotlib.axes.Axes]) – The matplotlib axes to use. If not provided, the plot will be send to the current axes (
plt.gca()
)color – The color to use for the plot. If not provided, the default colors from the matplotlib library will be used.
kwargs – Additional arguments from the
pyplot.hist
function.
- Return type:
matplotlib.axes.Axes
Examples
import ee, geetools normClim = ee.ImageCollection('OREGONSTATE/PRISM/Norm81m').toBands() region = ee.Geometry.Rectangle(-123.41, 40.43, -116.38, 45.14) climSamp = normClim.sample(region, 5000) climSamp.geetools.plot_hist("07_ppt")
- toImage(color=0, width='')[source]#
Paint the current FeatureCollection to an Image.
It’s simply a wrapper on Image.paint() method
- Parameters:
color (Union[geetools.types.ee_str, geetools.types.ee_int]) – The pixel value to paint into every band of the input image, either as a number which will be used for all features, or the name of a numeric property to take from each feature in the collection.
width (Union[geetools.types.ee_str, geetools.types.ee_int]) – Line width, either as a number which will be the line width for all geometries, or the name of a numeric property to take from each feature in the collection. If unspecified, the geometries will be filled instead of outlined.
- Return type:
ee.Image
- toPolygons()[source]#
Drop any geometry that is not a Polygon or a multipolygon.
This method is made to avoid errors when performing zonal statistics and/or other surfaces operations. These operations won’t work on geometries that are Lines or points. The methods remove these geometry types from GEometryCollections and rremove features that don’t have any polygon geometry
- Returns:
The parsed collection with only polygon/MultiPolygon geometries
- Return type:
ee.FeatureCollection
Example
import ee import geetools ee.Initialize() point0 = ee.Geometry.Point([0,0], proj="EPSG:4326") point1 = ee.Geometry.Point([0,1], proj="EPSG:4326") poly0 = point0.buffer(1, proj="EPSG:4326") poly1 = point1.buffer(1, proj="EPSG:4326").bounds(proj="EPSG:4326") line = ee.Geometry.LineString([point1, point0], proj="EPSG:4326") multiPoly = ee.Geometry.MultiPolygon([poly0, poly1], proj="EPSG:4326") geometryCol = ee.Algorithms.GeometryConstructors.MultiGeometry([multiPoly, poly0, poly1, point0, line], crs="EPSG:4326", geodesic=True, maxError=1) fc = ee.FeatureCollection([geometryCol]) fc = fc.geetools.toPolygons() print(fc.getInfo())