AI-generated Key Takeaways
-
This function produces an image where each pixel represents the distance in meters to the nearest geometry within a collection.
-
Distances are computed on a sphere, introducing a small error proportional to the latitude difference.
-
Pixels outside of the specified searchRadius from a geometry will be masked out.
-
The function takes an input FeatureCollection, a searchRadius in meters, and an optional maxError for reprojection.
Distances are computed on a sphere, so there is a small error proportional to the latitude difference between each pixel and the nearest geometry.
| Usage | Returns |
|---|---|
FeatureCollection.distance(searchRadius, maxError) | Image |
| Argument | Type | Details |
|---|---|---|
this: features | FeatureCollection | Feature collection from which to get features used to compute pixel distances. |
searchRadius | Float, default: 100000 | Maximum distance in meters from each pixel to look for edges. Pixels will be masked unless there are edges within this distance. |
maxError | Float, default: 100 | Maximum reprojection error in meters, only used if the input polylines require reprojection. If '0' is provided, then this operation will fail if projection is required. |
Examples
Code Editor (JavaScript)
// FeatureCollection of power plants in Belgium. var fc = ee.FeatureCollection('WRI/GPPD/power_plants') .filter('country_lg == "Belgium"'); // Generate an image of distance to nearest power plant. var distance = fc.distance({searchRadius: 50000, maxError: 50}); // Display the image and FeatureCollection on the map. Map.setCenter(4.56, 50.78, 7); Map.addLayer(distance, {max: 50000}, 'Distance to power plants'); Map.addLayer(fc, {color: 'red'}, 'Power plants');
import ee import geemap.core as geemap
Colab (Python)
# FeatureCollection of power plants in Belgium. fc = ee.FeatureCollection('WRI/GPPD/power_plants').filter( 'country_lg == "Belgium"' ) # Generate an image of distance to nearest power plant. distance = fc.distance(searchRadius=50000, maxError=50) # Display the image and FeatureCollection on the map. m = geemap.Map() m.set_center(4.56, 50.78, 7) m.add_layer(distance, {'max': 50000}, 'Distance to power plants') m.add_layer(fc, {'color': 'red'}, 'Power plants') m