# -*- coding: utf-8 -*-

'''
For ftp://download-opendata.lantmateriet.se/GSD-Terrangkartan_vektor/

Toponym names

'''

tr_t = {
    1: {"place": "isolated_dwelling"},# Bebyggelse, enstaka gård, hus
    2: {"place": "hamlet"},# Bebyggelse, by, större gård, mindre stadsdel
    3: {"place": "hamlet"},# Bebyggelse, by, stadsdel
    4: {"place": "hamlet"},# Bebyggelse, samhälle, samlad by
    5: {"place": "village"},# Tätort 200 - 499 inv., större stadsdel
    6: {"place": "town"},# Tätort 500 - 1 999 inv.
    7: {"place": "town"},# Tätort 2 000 - 9 999 inv.
    8: {"place": "city"},# Tätort 10 000 - 49 999 inv.
    9: {"place": "city"},# Tätort 50 000 och fler inv.
   14: {"place": "locality"},# Herrgård, storleksklass 1
#   15: {"historic": "castle", "castle_type"="manor"},# Slott
   16: {"place": "locality"},# Herrgård, storleksklass 2
#   17: {"building": "church"},# Kyrka, storleksklass 1
#   18: {"building": "church"},# Kyrka, storleksklass 2
}

for k in tr_t.keys():
    tr_t[k]["source"] = u"Lantmäteriet"
    tr_t[k]["lantmateriet:kkod"] = str(k)

def filterFeature(ogrfeature, fieldNames, reproject):
#    import pdb; pdb.set_trace()
    kkod_idx = ogrfeature.GetFieldIndex("KKOD")
    if kkod_idx >= 0:
        kkod = int(ogrfeature.GetField(kkod_idx))
        if not kkod in tr_t:
            return None

    return ogrfeature

def filterTags(attrs):
#    import pdb; pdb.set_trace()
    notags = {}
#    if not attrs:
#        return notags
#    if not "KKOD" in attrs:
#        return notags

    kkod = int(attrs["KKOD"])
    name = attrs.get("TEXT", "")
#    print(">>> name:", name)

    # Make a mutable copy of dict
    tags = dict(tr_t[kkod])

    tags["name"] = name
    return tags
