File size: 2,248 Bytes
84e78bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Import
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)


def getLand(landnr):
    landnr = int(landnr)
    #Test
    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)
    landR = gdf.iloc[landnr]
    return landR

# function to generate output
# Land should be a line from the geojson-table
# Currently only works for NUTS-1 areas!!!

def getCountrycode(land, level = 1):

    iso = 'ISO_'+ str(level)
    hasc = 'HASC_' + str(level)
    if land[iso] != 'NA':
        return str(land[iso])
    elif land[hasc]:
        return str(land[hasc])
    else:
        return False
    

def grad_Country(landnr):
    land = getLand(landnr)
    kuerzel = getCountrycode(land)
    return str(kuerzel)


#'''
import gradio as gr

def greet(name):
    return "Hello " + name + "!!"

iface = gr.Interface(fn=grad_Country, inputs="number", outputs="text")

if __name__ == '__main__':

    iface.launch()
#'''