0

I would like to select this row (it is a polygon) from this fusion table (called CDM_areas). I am struggling with the code to select such a field...

I have so far (uncertain in bold):

var ndviclip = ndvichange.clip(CDM_areas.select('name' **= '40'**));

Fusion Table

1 Answer 1

0

A FeatureCollection has Features with one or many properties. When you call select on a FeatureCollection you'll get the same but each Feature will keep only the properties you have indicated in the select method. See this example:

var geometry = ee.FeatureCollection(
        [ee.Feature(
            ee.Geometry.Point([-115.59062499999999, 39.72805832737948]),
            {
              "system:index": "0",
              "id": "0",
              "name": "zero"
            }),
        ee.Feature(
            ee.Geometry.Point([-104.25273437499999, 45.78644775647758]),
            {
              "system:index": "1",
              "id": "1",
              "name": "one"
            }),
        ee.Feature(
            ee.Geometry.Point([-91.50859374999999, 37.74005100886954]),
            {
              "system:index": "2",
              "id": "2",
              "name": "two"
            })]);

print(geometry.first())
print(geometry.select('name').first())

enter image description here

What you are looking for is to filter the FeatureCollection by name, and as you know name are unique, you get only the Feature you need.

var myfeature = ee.Feature(CDM_areas.filterMetadata('name', 'equals', 40).first()); // If it is a string column you have to quote it: '40'
var ndviclip = ndvichange.clip(myfeature);
4
  • Thanks for the tip Rodrigo, sadly it didn't work. I now imported the shapefile directly (no fusion table). The NEW_ID field is now the one I need to select a value from. I tried different values and different columns but no luck. It keeps returning 'null' in the Console. Code: var project1 = ee.Feature(CDM_areas.filterMetadata('NEW_ID', 'equals', '30').first());
    – Olivier
    Commented Nov 16, 2018 at 16:12
  • Is "NEW_ID" a number column? If so, I guess it should be project1 = ee.Feature(CDM_areas.filterMetadata('NEW_ID', 'equals', 30).first()); Commented Nov 16, 2018 at 16:18
  • Yes, that works. Thanks so much! Of course, it is not a string. This is my first thread here... do I copy/ quote your answer in the "Answer Your Question" button?
    – Olivier
    Commented Nov 16, 2018 at 16:25
  • I don't think your answer will be different of mine, because this is how you do it. I just didn't know if your column was a number or string, I supposed a string due to your first approach. I'll edit my answer Commented Nov 16, 2018 at 17:46

Your Answer

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

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