I want to retrieve the geometry of a country based on its ISO3 name (which is then used in another function). My code to get the geometry currently looks as follows (countryCodes
is a table with various aliases for countries in, and filtering it manually works fine):
var FAO_GAUL = ee.FeatureCollection("FAO/GAUL/2015/level0");
var countryCodes = ee.FeatureCollection("users/tsb42/country-codes_csv");
var getGaulCode = function (iso3) {
return countryCodes.filter(ee.Filter.eq("ISO3166-1-Alpha-3", iso3))
.select("GAUL").first().get("GAUL");
};
var getGaulGeom = function (iso3) {
var gaulCode = getGaulCode(iso3);
var countryDat = FAO_GAUL.filter(ee.Filter.eq("ADM0_CODE", gaulCode));
return countryDat.geometry();
};
Doing getGaulCode("GBR")
returns 256
, which is the expected value. However doing getGaulGeom("GBR")
returns an empty geometry because countryDat
is a feature collection with no elements.
Doing FAO_GAUL.filter(ee.Filter.eq("ADM0_CODE", 256))
returns a feature collection with one element and the expected geometry.
Why can I not pass the number generated by getGaulCode
into a filter? I'm very stuck, any method to get country boundaries from ISO3 strings would be much appreciated!!