Commit d450d12f authored by Roelofsen, Hans's avatar Roelofsen, Hans
Browse files

fix bt function

parent d2313dc0
......@@ -27,66 +27,6 @@ def rand_web_color_hex():
return "#{}".format(rgb)
def fix_bt(code_in, as_mnp=False):
"""
Parser for Beheertype codes to repair abbreviated codes and/or MNP extension
eg. 02.01 --> N02.01 if as_mnp==False
02.01 --> N01.01.00 if as_mnp==True
N05.01 --> N05.01 if as_mnp==False
N05.01 --> N05.01.00 if as_mnp==True
N04.02.01 --> N04.02.01 if as_mnp==False
N04.02.01 --> N04.02.01 if as_mnp==True
BT Code is as follows <N><AA>.<BB>.<CC>
N = letter, may be missing
A = two digits indicating top level beheertype "TOP"
B = two digits indicating sub level beheertype "SUB"
C = two digits indicating neergeschaald beheertype if > 00. Else "00" as used in MNP param notation "NEER"
N04.02.00 is equivalent to N04.02
:param code_in: beheertypecode in any format
:param as_mnp: return MNP style beheertypecode, default=False
:return: beheertypecode
"""
if isinstance(code_in, numbers.Number):
code_in = str(code_in)
# Identify parts of code
parts = code_in.split(".")
if len(parts) == 1:
raise Exception("Unexpected BT code: {}".format(code_in))
elif len(parts) == 2:
top, sub = parts
neer = None
elif len(parts) == 3:
top, sub, neer = parts
# Verify TOP and add "N" is required
if top.isdigit():
top = "N{0}".format(top.zfill(2))
else:
assert top[0].isupper(), "Unexpected BT Code format: {}".format(code_in)
# Verify SUB
assert sub.isdigit and len(sub) == 2, "Unexpected BT Code format: {}".format(
code_in
)
# Verify NEER and check if it is neergeschaald or not
keep_neer = False
if neer:
assert neer.isdigit and len(neer) == 2, "Unexpected BT Code format: {}".format(
code_in
)
if int(neer) > 0:
keep_neer = True
# Construct output
head = "{}.{}".format(top, sub)
if keep_neer:
return "{}.{}".format(head, neer)
elif as_mnp:
return "{}.00".format(head)
else:
return head
def pnt2square_id(east_north, size, of="full"):
......
import numbers
def fix_bt(code_in, as_mnp=False):
"""
Parser for Beheertype codes to repair abbreviated codes and/or MNP extension
eg. 02.01 --> N02.01 if as_mnp==False
02.01 --> N01.01.00 if as_mnp==True
N05.01 --> N05.01 if as_mnp==False
N05.01 --> N05.01.00 if as_mnp==True
N04.02.01 --> N04.02.01 if as_mnp==False
N04.02.01 --> N04.02.01 if as_mnp==True
BT Code is as follows <N><AA>.<BB>.<CC>
N = letter, may be missing
A = two digits indicating top level beheertype "TOP"
B = two digits indicating sub level beheertype "SUB"
C = two digits indicating neergeschaald beheertype if > 00. Else "00" as used in MNP param notation "NEER"
N04.02.00 is equivalent to N04.02
:param code_in: beheertypecode in any format
:param as_mnp: return MNP style beheertypecode, default=False
:return: beheertypecode
"""
if isinstance(code_in, numbers.Number):
code_in = str(code_in)
# Identify parts of code
parts = code_in.split(".")
if len(parts) == 1:
raise Exception("Unexpected BT code: {}".format(code_in))
elif len(parts) == 2:
top, sub = parts
neer = None
elif len(parts) == 3:
top, sub, neer = parts
# Verify TOP and add "N" is required
if top.isdigit():
top = "N{0}".format(top.zfill(2))
else:
assert top[0].isupper(), "Unexpected BT Code format: {}".format(code_in)
# Verify SUB
assert sub.isdigit and len(sub) == 2, "Unexpected BT Code format: {}".format(
code_in
)
# Verify NEER and check if it is neergeschaald or not
keep_neer = False
if neer:
assert neer.isdigit and len(neer) == 2, "Unexpected BT Code format: {}".format(
code_in
)
if int(neer) > 0:
keep_neer = True
# Construct output
head = "{}.{}".format(top, sub)
if keep_neer:
return "{}.{}".format(head, neer)
elif as_mnp:
return "{}.00".format(head)
else:
return head
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment