FeatureCollection
में सुविधाओं की प्रॉपर्टी कम करने के लिए, featureCollection.reduceColumns()
का इस्तेमाल करें. खिलौने के इस उदाहरण पर ध्यान दें:
कोड एडिटर (JavaScript)
// Make a toy FeatureCollection. var aFeatureCollection = ee.FeatureCollection([ ee.Feature(null, {foo: 1, weight: 1}), ee.Feature(null, {foo: 2, weight: 2}), ee.Feature(null, {foo: 3, weight: 3}), ]); // Compute a weighted mean and display it. print(aFeatureCollection.reduceColumns({ reducer: ee.Reducer.mean(), selectors: ['foo'], weightSelectors: ['weight'] }));
import ee import geemap.core as geemap
Colab (Python)
# Make a toy FeatureCollection. a_feature_collection = ee.FeatureCollection([ ee.Feature(None, {'foo': 1, 'weight': 1}), ee.Feature(None, {'foo': 2, 'weight': 2}), ee.Feature(None, {'foo': 3, 'weight': 3}), ]) # Compute a weighted mean and display it. display( a_feature_collection.reduceColumns( reducer=ee.Reducer.mean(), selectors=['foo'], weightSelectors=['weight'] ) )
ध्यान दें कि इनपुट को तय की गई weight
प्रॉपर्टी के हिसाब से तय किया जाता है. इसलिए, नतीजा यह है:
mean: 2.333333333333333
ज़्यादा मुश्किल उदाहरण के तौर पर, अमेरिका के सेंसस ब्लॉक का FeatureCollection
लें. इसमें सेंसस डेटा को एट्रिब्यूट के तौर पर शामिल करें. दिलचस्पी के वैरिएबल, कुल जनसंख्या और
कुल हाउसिंग यूनिट हैं. reduceColumns()
में जोड़ने वाले रिड्यूसर आर्ग्युमेंट को सबमिट करके और नतीजे को प्रिंट करके, उनका योग पाया जा सकता है:
कोड एडिटर (JavaScript)
// Load US census data as a FeatureCollection. var census = ee.FeatureCollection('TIGER/2010/Blocks'); // Filter the collection to include only Benton County, OR. var benton = census.filter( ee.Filter.and( ee.Filter.eq('statefp10', '41'), ee.Filter.eq('countyfp10', '003') ) ); // Display Benton County census blocks. Map.setCenter(-123.27, 44.57, 13); Map.addLayer(benton); // Compute sums of the specified properties. var properties = ['pop10', 'housing10']; var sums = benton .filter(ee.Filter.notNull(properties)) .reduceColumns({ reducer: ee.Reducer.sum().repeat(2), selectors: properties }); // Print the resultant Dictionary. print(sums);
import ee import geemap.core as geemap
Colab (Python)
# Load US census data as a FeatureCollection. census = ee.FeatureCollection('TIGER/2010/Blocks') # Filter the collection to include only Benton County, OR. benton = census.filter( ee.Filter.And( ee.Filter.eq('statefp10', '41'), ee.Filter.eq('countyfp10', '003') ) ) # Display Benton County census blocks. m = geemap.Map() m.set_center(-123.27, 44.57, 13) m.add_layer(benton) display(m) # Compute sums of the specified properties. properties = ['pop10', 'housing10'] sums = benton.filter(ee.Filter.notNull(properties)).reduceColumns( reducer=ee.Reducer.sum().repeat(2), selectors=properties ) # Print the resultant Dictionary. display(sums)
आउटपुट एक Dictionary
होता है, जो तय किए गए रिड्यूसर के हिसाब से इकट्ठा की गई प्रॉपर्टी को दिखाता है:
sum: [85579,36245]
ध्यान दें कि ऊपर दिए गए उदाहरण में notNull()
फ़िल्टर का इस्तेमाल करके, सिर्फ़ उन सुविधाओं को शामिल किया गया है जिनकी वैल्यू शून्य नहीं है.
अचानक से डेटा न मिलने की समस्या का पता लगाने और गणना के दौरान, शून्य वैल्यू की वजह से होने वाली गड़बड़ियों से बचने के लिए, शून्य वैल्यू वाली एंट्री की जांच करना एक अच्छा तरीका है.
यह भी ध्यान रखें कि imageCollection.reduce()
के उलट, FeatureCollection
में रिड्यूसर,
हर बैंड के लिए अपने-आप दोहराए जाते हैं. हालांकि, FeatureCollection
में रिड्यूसर को repeat()
का इस्तेमाल करके,
साफ़ तौर पर दोहराया जाना चाहिए. खास तौर पर, m इनपुट के लिए, रिड्यूसर को m बार दोहराएं. रिड्यूसर को दोहराए बिना, यह गड़बड़ी दिख सकती है: