Feature Overview

A Feature in Earth Engine is defined as a GeoJSON Feature. Specifically, a Feature is an object with a geometry property storing a Geometry object (or null) and a properties property storing a dictionary of other properties.

Creating Feature objects

To create a Feature, provide the constructor with a Geometry and (optionally) a dictionary of other properties. For example:

// Create an ee.Geometry.
var polygon = ee.Geometry.Polygon([
  [[-35, -10], [35, -10], [35, 10], [-35, 10], [-35, -10]]
]);

// Create a Feature from the Geometry.
var polyFeature = ee.Feature(polygon, {foo: 42, bar: 'tart'});
      

As with a Geometry, a Feature may be printed or added to the map for inspection and visualization:

print(polyFeature);
Map.addLayer(polyFeature, {}, 'feature');
      

A Feature need not have a Geometry and may simply wrap a dictionary of properties. For example:

// Create a dictionary of properties, some of which may be computed values.
var dict = {foo: ee.Number(8).add(88), bar: 'nihao'};

// Create a null geometry feature with the dictionary of properties.
var nowhereFeature = ee.Feature(null, dict);
      

In this example, note that the dictionary supplied to the Feature contains a computed value. Creating features in this manner is useful for exporting long-running computations with a Dictionary result (e.g. image.reduceRegion()). See the FeatureCollections and Importing or Exporting sections for details.

Each Feature has one primary Geometry stored in the geometry property. Additional geometries may be stored in other properties. Geometry methods such as intersection and buffer also exist on Feature as a convenience for getting the primary Geometry, applying the operation, and setting the result as the new primary Geometry. The result will retain all the other properties of the Feature on which the method is called. There are also methods for getting and setting the non-geometry properties of the Feature. For example:

// Make a feature and set some properties.
var feature = ee.Feature(ee.Geometry.Point([-122.22599, 37.17605]))
  .set('genus', 'Sequoia').set('species', 'sempervirens');

// Get a property from the feature.
var species = feature.get('species');
print(species);

// Set a new property.
feature = feature.set('presence', 1);

// Overwrite the old properties with a new dictionary.
var newDict = {genus: 'Brachyramphus', species: 'marmoratus'};
var feature = feature.set(newDict);

// Check the result.
print(feature);
      

In the previous example, note that properties can be set with either a key: value pair, or with a dictionary as a JavaScript literal. Also note that feature.set() overwrites existing properties.

发送以下问题的反馈:

此网页
Google Earth Engine API