Page Summary
-
ee.Filter.hasTypecreates a filter that checks if the left operand's type is, or is a subtype of, the type specified in the right operand. -
This filter can be used with
leftFieldandrightValueto check the type of a specific field against a given type string. -
Examples demonstrate filtering features based on the type of their geometry or property values.
| 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'})));
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')) ) # The first two features have a Polygon geometry. display( fc.filter( ee.Filter.hasType(leftField='.geo', rightValue='Polygon') ) ) # The first feature has property x with type Number. display( fc.filter(ee.Filter.hasType(leftField='x', rightValue='Number')) ) # The second feature has property x with type String. display( fc.filter(ee.Filter.hasType(leftField='x', rightValue='String')) )