So, this is my code.:

var dataset = ee.ImageCollection('USDA/NASS/CDL')
                  .filter(ee.Filter.date('2018-01-01', '2019-12-31'))

var cropLandcover = dataset.select('cropland');
var cultivated = dataset.select('cultivated');
Map.setCenter(-100.55, 40.71, 4);

Map.addLayer(cropLandcover, {}, 'Crop Landcover');
Map.addLayer(cultivated, {}, 'Cultivation');

I want to use one of the Image Properties, cropland_class_values, so it only shows the parts of the image that have a cropland_class_values value of 1, so it only shows crop cover for corn, which has a cropland_class_values value of 1.

Here is the Cropland Image Collection from the catalog: https://developers.google.com/earth-engine/datasets/catalog/USDA_NASS_CDL

New contributor
user177937 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Image properties do not tell you anything about parts of an image, only the whole image. In this case, it appears that the cropland_class_values property lists all the classes that occur in that image, though I'm not sure if that's exactly correct — I just checked that it isn't the same for all images.

(You can retrieve the value of the property with print(dataset.get('cropland_class_names'));)

If you just want to select pixels with a specific value, you don't need any properties to do that, just to know the value you're looking for: cropLandcover.eq(1) will give an image which is 1 for that value (which happens to itself be 1, but it could be whichever class number you wanted) and 0 elsewhere. That image can then be used as a mask:

var isCorn = cropLandcover.eq(1);
Map.addLayer(cultivated.updateMask(isCorn), {}, 'Cultivation');

I just guessed at what you wanted to do with the two bands you selected, but I notice that cultivated seems to always have a value of 2 in the corn pixels, so that may not be quite useful. But either way, there's the corn. (Assuming that all images in the collection consistently use the number 1 for corn, but most datasets should have consistent meanings of values in all images a collection.)

Your Answer

user177937 is a new contributor. Be nice, and check out our Code of Conduct.

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.