File size: 1,004 Bytes
f758beb
 
 
9e54623
f758beb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pandas as pd
import re

# Load the CRS lookup CSV
crs_lookup = pd.read_csv("docStore/crs5_codes.csv")  # columns: "code" and "new_crs_value"

def lookup_crs_value(crs_key):
    """
    Lookup the new CRS value given a CRS key, based on the loaded CSV file.

    Args:
        crs_key (str): The raw CRS code (possibly with trailing .0).

    Returns:
        str: The mapped CRS value or empty string if not found.
    """
    key_clean = re.sub(r'\.0$', '', str(crs_key).strip())
    row = crs_lookup[crs_lookup["code"].astype(str) == key_clean]
    if not row.empty:
        if "new_crs_value" in row.columns:
            try:
                return re.sub(r'\.0$', '', str(int(float(row.iloc[0]["new_crs_value"]))))
            except Exception:
                return re.sub(r'\.0$', '', str(row.iloc[0]["new_crs_value"]))
        else:
            # fallback to "name" column if no "new_crs_value" column
            return re.sub(r'\.0$', '', str(row.iloc[0]["name"]).strip())
    return ""