AI-generated Key Takeaways
-
Computes the distance (in meters) from each pixel to the nearest point, line, or polygon within a given FeatureCollection.
-
Generates a double-precision image where pixel values represent the distance to the nearest feature.
-
Offers adjustable search radius and maximum error parameters for controlling computation.
-
Pixels beyond the search radius or exceeding the error threshold are masked out.
-
Calculations consider the Earth's curvature for accurate distance measurements.
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