Spaces:
Sleeping
Sleeping
Create crs_utils.py
Browse files- appStore/crs_utils.py +28 -0
appStore/crs_utils.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import re
|
3 |
+
|
4 |
+
# Load the CRS lookup CSV once at import time
|
5 |
+
crs_lookup = pd.read_csv("docStore/crs5_codes.csv") # columns: "code" and "new_crs_value"
|
6 |
+
|
7 |
+
def lookup_crs_value(crs_key):
|
8 |
+
"""
|
9 |
+
Lookup the new CRS value given a CRS key, based on the loaded CSV file.
|
10 |
+
|
11 |
+
Args:
|
12 |
+
crs_key (str): The raw CRS code (possibly with trailing .0).
|
13 |
+
|
14 |
+
Returns:
|
15 |
+
str: The mapped CRS value or empty string if not found.
|
16 |
+
"""
|
17 |
+
key_clean = re.sub(r'\.0$', '', str(crs_key).strip())
|
18 |
+
row = crs_lookup[crs_lookup["code"].astype(str) == key_clean]
|
19 |
+
if not row.empty:
|
20 |
+
if "new_crs_value" in row.columns:
|
21 |
+
try:
|
22 |
+
return re.sub(r'\.0$', '', str(int(float(row.iloc[0]["new_crs_value"]))))
|
23 |
+
except Exception:
|
24 |
+
return re.sub(r'\.0$', '', str(row.iloc[0]["new_crs_value"]))
|
25 |
+
else:
|
26 |
+
# fallback to "name" column if no "new_crs_value" column
|
27 |
+
return re.sub(r'\.0$', '', str(row.iloc[0]["name"]).strip())
|
28 |
+
return ""
|