1

I'm having trouble with turning a client-side object into a server-side object. Below I have adapted an excerpt of my script to illustrate my problem. I want to make the end of my filter selection depend on the values of DOYend and DOYstart. Printing yearAdd and yearStr returns what I expect, but filterSelectEnd returns something I don't understand.

var DOYend = 10
var DOYstart = 13
var yearSelected = ee.String('2014')

    if(DOYend <= DOYstart) {
      var yearNum = ee.Number.parse(yearSelected)
      var yearAdd = yearNum.add(1)
      var yearStr = ee.String((yearAdd))
      var filterSelectEnd = ee.Algorithms.String(yearAdd + '-12-31')
    }

print('yearAdd',yearAdd)
print('yearStr',yearStr)
print('conditionResult',filterSelectEnd)

Output:

conditionResult
ee.Number({
  "type": "Invocation",
  "arguments": {
    "left": {
      "type": "Invocation",
      "arguments": {
        "input": "2015"
      },
      "functionName": "Number.parse"
    },
    "right": 1
  },
  "functionName": "Number.add"
})-12-31
  • Could you update the question with an example of the output? A total random guess is the ( ) around '-12-13' make that a tuple which is probably NOT what you want. Try removing the ( ). – Richard Morgan Mar 18 at 16:33
  • Done, but it still hasn't solved the problem. From what I understand, filterSelectEnd has to be stated to be a server-side object, rather than a client-side. Let me add the output of 'conditionResult' as well. – IskJon Mar 18 at 16:36
  • 1
    See if this SO answer will help: stackoverflow.com/a/48411561/2258 – Richard Morgan Mar 18 at 16:47
  • Yep, that did it. if(DOYend <= DOYstart) { var yearNum = ee.Number.parse(yearSelected) var yearAdd = yearNum.add(1) var yearStr = ee.String(yearAdd) filterSelectEnd = ee.String(yearStr).cat('-12-31') } – IskJon Mar 18 at 17:15
1

If those inputs are coming from, say a UI element, then I highly suggest keeping everything client-side:

var DOYend = 10
var DOYstart = 13
var yearSelected = '2014'

if(DOYend <= DOYstart) {
  var yearNum = Number(yearSelected)
  var yearAdd = yearNum + 1
  var yearStr = yearAdd + '-12-31'
}

print('yearAdd', yearAdd)
print('yearStr', yearStr)

(As an aside, I don't quite follow the logic here. Shouldn't you advance the year and then advance the DOY and not set it to 12-31? If so, that will complicate things, because now you're going to have to fiddle with either a Date or an ee.Date, but again, keep everything client-side if possible.)

  • Thanks for the insight! The objective of my script is to make a comparison for a specific date-range in a selected year with data for the same date-range for the last 36 years. I'm using sliders to determine the starts and ends of the ranges I want to look at. However, DOY is set using integers (which I am using the sliders to set), so the date range is effectively set as a count of days from the start of the year. – IskJon Mar 20 at 11:00
0

See comment feed.

    if(DOYend <= DOYstart) { 
var yearNum = ee.Number.parse(yearSelected) 
var yearAdd = yearNum.add(1) 
var yearStr = ee.String(yearAdd) 
filterSelectEnd = ee.String(yearStr).cat('-12-31') }
  • Could maybe add some expalnations? Thanks! – Matifou Mar 19 at 15:52

Your Answer

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.