ee.Filter.hasType
Creates a unary or binary filter that passes if the left operand has the type, or is a subtype of the type named in the right operand.
Usage | Returns | ee.Filter.hasType(leftField, rightValue, rightField, leftValue) | Filter |
Argument | Type | Details | leftField | String, default: null | A selector for the left operand. Should not be specified if leftValue is specified. |
rightValue | Object, default: null | The value of the right operand. Should not be specified if rightField is specified. |
rightField | String, default: null | A selector for the right operand. Should not be specified if rightValue is specified. |
leftValue | Object, default: null | The value of the left operand. Should not be specified if leftField is specified. |
Examples
Code Editor (JavaScript)
var fc = ee.FeatureCollection([
ee.Feature(ee.Geometry.Rectangle([0, 0, 1, 1]), {'x': 0}),
ee.Feature(ee.Geometry.Rectangle(0, 0, 3, 3), {'x': 'foo'}),
ee.Feature(ee.Geometry.Point(0, 0))]);
// The third feature has a Point geometry.
print(fc.filter(ee.Filter.hasType({leftField: '.geo', rightValue: 'Point'})));
// The first two features have a Polygon geometry.
print(fc.filter(ee.Filter.hasType({leftField: '.geo', rightValue: 'Polygon'})));
// The first feature has property x with type Number.
print(fc.filter(ee.Filter.hasType({leftField: 'x', rightValue: 'Number'})));
// The second feature has property x with type String.
print(fc.filter(ee.Filter.hasType({leftField: 'x', rightValue: 'String'})));
Python setup
See the
Python Environment page for information on the Python API and using
geemap
for interactive development.
import ee
import geemap.core as geemap
Colab (Python)
fc = ee.FeatureCollection([
ee.Feature(ee.Geometry.Rectangle([0, 0, 1, 1]), {'x': 0}),
ee.Feature(ee.Geometry.Rectangle(0, 0, 3, 3), {'x': 'foo'}),
ee.Feature(ee.Geometry.Point(0, 0)),
])
# The third feature has a Point geometry.
display(
fc.filter(ee.Filter.hasType(leftField='.geo', rightValue='Point')).getInfo()
)
# The first two features have a Polygon geometry.
display(
fc.filter(
ee.Filter.hasType(leftField='.geo', rightValue='Polygon')
).getInfo()
)
# The first feature has property x with type Number.
display(
fc.filter(ee.Filter.hasType(leftField='x', rightValue='Number')).getInfo()
)
# The second feature has property x with type String.
display(
fc.filter(ee.Filter.hasType(leftField='x', rightValue='String')).getInfo()
)
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[[["`ee.Filter.hasType` creates a filter that checks if data has a specified type or is a subtype of it."],["This filter can be applied to properties or geometries within a FeatureCollection."],["The filter is constructed by defining the operand (property or geometry) and the expected type."],["`leftField` selects the property or geometry to check, while `rightValue` defines the expected type."]]],["`ee.Filter.hasType` creates a filter to check if a left operand's type matches or is a subtype of the type specified by the right operand. It accepts `leftField` or `leftValue` to select the left operand and `rightValue` or `rightField` for the right operand. The function returns a `Filter` object. Examples demonstrate filtering a feature collection based on the type of a geometry or the type of a property like Number or String.\n"]]