ai_project_v1/uv_module/test_epsg.py

21 lines
726 B
Python
Raw Normal View History

import rasterio
from pyproj import CRS
def get_crs_info(tif_path):
with rasterio.open(tif_path) as src:
crs = src.crs
if not crs:
return "未知坐标系"
# 硬编码检查 CGCS2000 3度带第35带
if "CGCS2000" in crs.to_string() and "Gauss-Kruger zone 35" in crs.to_string():
return "EPSG:4523"
# 尝试用 pyproj 解析
try:
pyproj_crs = CRS.from_user_input(crs.to_wkt())
epsg_code = pyproj_crs.to_epsg()
return f"EPSG:{epsg_code}" if epsg_code else crs.to_wkt()
except Exception as e:
return f"解析失败: {e}"
tif_path = "tile_0_0.tif"
print(f"TIFF坐标系: {get_crs_info(tif_path)}")