pyguymer3.geo.getRecordAttribute

pyguymer3.geo.getRecordAttribute(record, attribute, /, *, strict=False)[source]

Get an attribute of a Shapefile record

This function gets an attribute of a Shapefile record, falling back on different attributes to work around inconsistencies in records in Shapefiles obtained from Natural Earth.

For example, if the user wants the “ISO_A2” attribute then this function (with strict = False) will return the first value it finds (which does not equal “-99”) from:

  • record.attributes["ISO_A2"]

  • record.attributes["iso_a2"]

  • record.attributes["ISO_A2_EH"]

  • record.attributes["iso_a2_eh"]

Parameters:
  • record (cartopy.io.shapereader.Record) – the record

  • attribute (str) – the attribute

  • debug (bool, optional) – if True then return “-99” if that is what the value is; if False then continue looping through the possibilities

Returns:

value – the value

Return type:

str

Notes

According to the developer of Natural Earth [1] :

“Because Natural Earth has a more fidelity than ISO, and tracks countries that ISO doesn’t, Natural Earth maintains it’s own set of 3-character codes for each admin-0 related feature.”

Therefore, when “ISO_A2” or “ISO_A3” are not populated I must fall back on “ISO_A2_EH” and “ISO_A3_EH” instead.

Copyright 2017 Thomas Guymer [2]

References