ee.FeatureCollection.distance

สร้างรูปภาพ DOUBLE โดยที่แต่ละพิกเซลคือระยะทางเป็นเมตรจากกึ่งกลางพิกเซลไปยัง Point, LineString หรือขอบเขตแบบหลายเหลี่ยมที่ใกล้ที่สุดในคอลเล็กชัน โปรดทราบว่าระบบจะวัดระยะทางภายในรูปหลายเหลี่ยมด้วย ระบบจะมาสก์พิกเซลที่อยู่นอกรัศมี "searchRadius" เมตรของรูปทรงเรขาคณิต

ระยะทางจะคำนวณบนทรงกลม จึงอาจมีข้อผิดพลาดเล็กน้อยตามสัดส่วนของความแตกต่างของละติจูดระหว่างแต่ละพิกเซลกับรูปเรขาคณิตที่ใกล้ที่สุด

การใช้งานการคืนสินค้า
FeatureCollection.distance(searchRadius, maxError)รูปภาพ
อาร์กิวเมนต์ประเภทรายละเอียด
ดังนี้ featuresFeatureCollectionชุดฟีเจอร์ที่จะใช้ในการคำนวณระยะทางของพิกเซล
searchRadiusFloat, ค่าเริ่มต้น: 100000ระยะทางสูงสุดเป็นเมตรจากแต่ละพิกเซลเพื่อค้นหาขอบ ระบบจะมาสก์พิกเซล เว้นแต่จะมีขอบภายในระยะนี้
maxErrorFloat, ค่าเริ่มต้น: 100ข้อผิดพลาดในการฉายซ้ำสูงสุดเป็นเมตร ใช้เฉพาะในกรณีที่เส้นหลายเส้นอินพุตต้องมีการฉายซ้ำ หากระบุ "0" การดำเนินการนี้จะล้มเหลวหากต้องมีการฉายภาพ

ตัวอย่าง

โปรแกรมแก้ไขโค้ด (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');

การตั้งค่า Python

ดูข้อมูลเกี่ยวกับ Python API และการใช้ geemap เพื่อการพัฒนาแบบอินเทอร์แอกทีฟได้ที่หน้า สภาพแวดล้อม Python

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