1

I want to create a data table which has only two column, parameters and value, i want to get feature properties from table1 and add properties and values to table, then print to console...

GEE Code

  var table1 =ee.Feature(
          ee.Geometry.Polygon(
              [[[27.198675268206312, 41.28337381424559],
                [27.198675268206312, 41.186296803350956],
                [27.379949682268812, 41.186296803350956],
                [27.379949682268812, 41.28337381424559]]], null, false),
          {
            "system:index": "0",
            "polID": 123,
            "area": 154,
            "perimeter": 200
          });
          
  print(table1)
  
  table1.evaluate(function(dataTableClient) {
        var per= ee.Number(table1.get('perimeter'))
        var area1 =ee.Number(table1.get('area'))
        
        var dataTable = [
          ['Parameter', 'Value'],
          ['polygon_ID', 123],
          ['perimeter', per],
          ['area', area1],
        ];
        
        var chart = ui.Chart(dataTable).setChartType('Table').setOptions({
          title: 'Parcel Characteristics)',
        });
        print(chart)
  });

When i try this code, it gives NAN values... How could be correct these values?

enter image description here

2 Answers 2

1

They way you set up your example the perimeter and area are GEE server-side objects and your plot is client side so you need to get the values from the server with getInfo():

        var per= ee.Number(table1.get('perimeter')).getInfo()
        var area1 =ee.Number(table1.get('area')).getInfo()

Be carefull with getInfo in your workflow as it is generally not recommended to use!

https://code.earthengine.google.com/1095f8a20034dec80d7c424f3091e054

0
1

I found a simpler code, it can be adapted for two columns tables(GEE Code):

  var table1 =ee.Feature(
          ee.Geometry.Polygon(
              [[[27.198675268206312, 41.28337381424559],
                [27.198675268206312, 41.186296803350956],
                [27.379949682268812, 41.186296803350956],
                [27.379949682268812, 41.28337381424559]]], null, false),
          {
            "system:index": "0",
            "polID": 123,
            "area": 154,
            "perimeter": 200
          });
          
  print(table1)
  
  var Dict = table1.toDictionary()
  var keys = ee.List(Dict.keys())
  var values=ee.List(Dict.values())
  
  var zipped = keys.zip(values)
  
  // Define column names and properties for the DataTable. The order should
  // correspond to the order in the construction of the 'row' property above.
  var columnHeader = ee.List([[
    {label: 'Parameter', role: 'data', type: 'string'},
    {label: 'Value', role: 'data', type: 'string'},
  ]]);
  
  // Concatenate the column header to the table.
  var dataTableServer = columnHeader.cat(zipped);

  // Use 'evaluate' to transfer the server-side table to the client, define the
  // chart and print it to the console.
  dataTableServer.evaluate(function(dataTableClient) {
                var chart = ui.Chart(dataTableClient)
                .setChartType('Table')
                .setOptions({ title: 'Polygon Characteristics)'});
                print(chart)
  });

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.