annikwag's picture
Update appStore/crs_utils.py
9e54623 verified
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 ""