Image
या
FeatureCollection
के हर ज़ोन में आंकड़े पाने के लिए, reducer.group()
का इस्तेमाल करें. इससे, किसी तय इनपुट की वैल्यू के हिसाब से, रिड्यूसर के आउटपुट को ग्रुप किया जा सकता है. उदाहरण के लिए, हर राज्य की कुल आबादी और घरों की संख्या का हिसाब लगाने के लिए, यह उदाहरण सेंसस ब्लॉक FeatureCollection
में हुई कमी के आउटपुट को इस तरह ग्रुप करता है:
कोड एडिटर (JavaScript)
// Load a collection of US census blocks. var blocks = ee.FeatureCollection('TIGER/2010/Blocks'); // Compute sums of the specified properties, grouped by state code. var sums = blocks .filter(ee.Filter.and( ee.Filter.neq('pop10', null), ee.Filter.neq('housing10', null))) .reduceColumns({ selectors: ['pop10', 'housing10', 'statefp10'], reducer: ee.Reducer.sum().repeat(2).group({ groupField: 2, groupName: 'state-code', }) }); // Print the resultant Dictionary. print(sums);
import ee import geemap.core as geemap
Colab (Python)
# Load a collection of US census blocks. blocks = ee.FeatureCollection('TIGER/2010/Blocks') # Compute sums of the specified properties, grouped by state code. sums = blocks.filter( ee.Filter.And( ee.Filter.neq('pop10', None), ee.Filter.neq('housing10', None) ) ).reduceColumns( selectors=['pop10', 'housing10', 'statefp10'], reducer=ee.Reducer.sum() .repeat(2) .group(groupField=2, groupName='state-code'), ) # Print the resultant Dictionary. display(sums)
groupField
आर्ग्युमेंट, सिलेक्टर कलेक्शन में मौजूद इनपुट का इंडेक्स होता है. इसमें वे कोड होते हैं जिनके हिसाब से डेटा को ग्रुप में बांटा जाता है. groupName
आर्ग्युमेंट, ग्रुपिंग वैरिएबल की वैल्यू को सेव करने के लिए प्रॉपर्टी का नाम बताता है. हर इनपुट के लिए, रिड्यूसर अपने-आप दोहराया नहीं जाता. इसलिए, repeat(2)
कॉल की ज़रूरत होती है.
image.reduceRegions()
के आउटपुट को ग्रुप करने के लिए, ग्रुपिंग बैंड तय किया जा सकता है
जो पूर्णांक पिक्सल वैल्यू के हिसाब से ग्रुप तय करता है. इस तरह के हिसाब लगाने को कभी-कभी "ज़ोनल आंकड़ों" के तौर पर भी कहा जाता है. इसमें ज़ोन को ग्रुपिंग बैंड के तौर पर तय किया जाता है और आंकड़ों को रिड्यूसर तय करता है. नीचे दिए गए उदाहरण में, अमेरिका में रात में रोशनी में हुए बदलाव को लैंड कवर कैटगरी के हिसाब से ग्रुप किया गया है:
कोड एडिटर (JavaScript)
// Load a region representing the United States var region = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017') .filter(ee.Filter.eq('country_na', 'United States')); // Load MODIS land cover categories in 2001. var landcover = ee.Image('MODIS/051/MCD12Q1/2001_01_01') // Select the IGBP classification band. .select('Land_Cover_Type_1'); // Load nightlights image inputs. var nl2001 = ee.Image('NOAA/DMSP-OLS/NIGHTTIME_LIGHTS/F152001') .select('stable_lights'); var nl2012 = ee.Image('NOAA/DMSP-OLS/NIGHTTIME_LIGHTS/F182012') .select('stable_lights'); // Compute the nightlights decadal difference, add land cover codes. var nlDiff = nl2012.subtract(nl2001).addBands(landcover); // Grouped a mean reducer: change of nightlights by land cover category. var means = nlDiff.reduceRegion({ reducer: ee.Reducer.mean().group({ groupField: 1, groupName: 'code', }), geometry: region.geometry(), scale: 1000, maxPixels: 1e8 }); // Print the resultant Dictionary. print(means);
import ee import geemap.core as geemap
Colab (Python)
# Load a region representing the United States region = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017').filter( ee.Filter.eq('country_na', 'United States') ) # Load MODIS land cover categories in 2001. landcover = ee.Image('MODIS/051/MCD12Q1/2001_01_01').select( # Select the IGBP classification band. 'Land_Cover_Type_1' ) # Load nightlights image inputs. nl_2001 = ee.Image('NOAA/DMSP-OLS/NIGHTTIME_LIGHTS/F152001').select( 'stable_lights' ) nl_2012 = ee.Image('NOAA/DMSP-OLS/NIGHTTIME_LIGHTS/F182012').select( 'stable_lights' ) # Compute the nightlights decadal difference, add land cover codes. nl_diff = nl_2012.subtract(nl_2001).addBands(landcover) # Grouped a mean reducer: change of nightlights by land cover category. means = nl_diff.reduceRegion( reducer=ee.Reducer.mean().group(groupField=1, groupName='code'), geometry=region.geometry(), scale=1000, maxPixels=1e8, ) # Print the resultant Dictionary. display(means)
ध्यान दें कि इस उदाहरण में, groupField
उस बैंड का इंडेक्स है जिसमें ऐसे ज़ोन होते हैं जिनके हिसाब से आउटपुट को ग्रुप किया जाता है. पहले बैंड का इंडेक्स 0 है, दूसरे का
इंडेक्स 1 है, और इसी तरह यह क्रम चलता है.