GID_HuggingFace / modules /getCountrycode.py
giho905e's picture
Upload 30 files
84e78bb
raw
history blame
1.07 kB
import geopandas as gpd
# Sample DataFrame acording to actual structure (use your own data)
data = {'GID_1': ['DEU.1_1','DEU.2_1'],
'GID_0': ['DEU', 'DEU'],
'COUNTRY': ['Germany', 'Germany'],
'NAME_1': ['Baden-Würtenberg', 'Bayern'],
'VARNAME_1': ['NA','Bavaria'],
'NL_NAME_1': ['NA', 'NA'],
'TYPE_1': ['Land', 'Freistaat'],
'ENGTYPE_1': ['State', 'Freestate'],
'CC_1': ['08','09'],
'HASC_1': ['DE.BW', 'DE.BY'], # Extra for subnational countys (https://de.wikipedia.org/wiki/Hierarchical_administrative_subdivision_codes)
'ISO_1': ['NA', 'DE-BY'], # International Order --> Check First (https://de.wikipedia.org/wiki/ISO_3166)
'geometry': [0,1]
}
gdf = gpd.GeoDataFrame(data)
# function to generate output
# Land should be a line from the geojson-table
# Currently only works for NUTS-1 areas!!!
def getCountrycode(land):
if land['ISO_1'] != 'NA':
return land['ISO_1']
elif land['HASC_1']:
return land['HASC_1']
else:
return False