0

I am attempting to print the average temperature for inputting coordinates in the format of a string. Currently, I have only managed to showcase the temperature on the map and extract it from manually clicking on a pixel on the map.

For the Hycom dataset:

// Import the time series of global images, filter 15 days in August, 2018.

var dataset = ee.ImageCollection('HYCOM/sea_temp_salinity') .filter(ee.Filter.date('2018-08-01', '2018-08-15'));

// Select water temperature at 0 meters and scale to degrees C.

var seaWaterTemperature = dataset.select('water_temp_0')
    .map(function scaleAndOffset(image) {
      return ee.Image(image).multiply(0.001).add(20);
    });

// Define visualization parameters.

var visParams = {
  min: -2.0,  // Degrees C
  max: 34.0,
  palette: ['000000', '005aff', '43c8c8', 'fff700', 'ff0000'],
};

// Display mean 15-day temperature on the map.

Map.setCenter(-88.6, 26.4, 1);
Map.addLayer(seaWaterTemperature.mean(), visParams, 'Sea Water Temperature');

1 Answer 1

0

This tutorial covers many of the functions required to extract the values of a raster located under a point. Though I suspect that the steps described may be overkill for what you need.

https://developers.google.com/earth-engine/tutorials/community/extract-raster-values-for-points

A simpler approach would be to generate the point feature, then use the reduce region function.

First you will want to create the point of interest

var poi = ee.Feature(ee.Geometry.Point([-118.6010, 37.0777]), {plot_id: 1})

The coordinates for the point can be entered manually, or substituted for a variable. Then run the reduce region function with the raster and point geometry to extract the value of the pixel which the point falls upon.

var ras_value = image.reduceRegion({
  reducer: ee.Reducer.mean(),
  geometry: poi.geometry(),
  scale: 30,
  maxPixels: 1e9
});

The result will be a dictionary of the pixel values for each band. The desired value can the be printed out.

Note: if reduce region is being run on a single point then the mean, min, or max reducers should all work as it will just sample a single pixel.

https://developers.google.com/earth-engine/guides/reducers_reduce_region

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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