snl_beheertypen.py 1.12 KB
Newer Older
1
2
3
4
5
6
"""
pandas dataframe containing .\resources\snl_beheertypen.csv
Hans Roelofsen, 14/07/2021
"""

import os
7
import pathlib
8
import pandas as pd
9
import sys
10
from fix_bt import fix_bt  # this only works if the dir containing benb_utils has already been appended to
11
12
                                      # sys.path
filepath = pathlib.Path(__file__)
13

Roelofsen, Hans's avatar
Roelofsen, Hans committed
14

15
16
17
df = pd.read_csv(os.path.join(os.path.dirname(filepath), r'resources/snl_beheertypen.csv'), sep=',', comment='#', quotechar='"')

def get_snl_beheertypen_list(df=df, of='sparse'):
18
19
20
21
22
    """
    return snl beheertypen list as pandas df
    :param benb_dir: directory of benb_utils
    :return: pandas dataframe
    """
23
24
25
26
27
28
29
30
31
32
33
34
    mnp_codes = df.LAND_TYPE_CODE.apply(fix_bt, as_mnp=True)
    return {'full': df.assign(mnp_code=mnp_codes),
            'sparse': df}[of]

def btcode2description(code):
    # Note: dit hoeft niet perse in een functie te staan.
    try:
        return dict(zip(df.LAND_TYPE_CODE.apply(fix_bt, as_mnp=True),
                        df.LST_NAME))[fix_bt(code, as_mnp=True)]
    except KeyError as e:
        print('\n{} is not a valid beheertype\n'.format(code))
        sys.exit(0)