fix(DataV_SuPER): 允许省略city参数以获取省级行政区划数据
修改resolve_adcode_by_name和fetch_and_save_geojson_by_name的city参数为可选参数,添加默认值None。更新函数文档字符串与示例代码,同时更新文件最后更新日期。
This commit is contained in:
parent
7a63d373a3
commit
cc0791f1ba
@ -10,7 +10,7 @@
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
Authors: CVEO Team
|
||||
Last Updated: 2026-04-13
|
||||
Last Updated: 2026-04-19
|
||||
===============================================================================
|
||||
"""
|
||||
|
||||
@ -114,7 +114,7 @@ def _name_matches_exact(target: str, candidate: str) -> bool:
|
||||
|
||||
def resolve_adcode_by_name(
|
||||
province: str,
|
||||
city: str,
|
||||
city: Optional[str] = None,
|
||||
county: Optional[str] = None,
|
||||
prefer_full: bool = False,
|
||||
) -> Optional[str]:
|
||||
@ -128,8 +128,8 @@ def resolve_adcode_by_name(
|
||||
----------
|
||||
province : str
|
||||
省份名称, 如 "湖北省". 不能为空.
|
||||
city : str
|
||||
城市名称, 如 "武汉市". 不能为空.
|
||||
city : str, optional
|
||||
城市名称, 如 "武汉市". 可为空 (表示只解析到省).
|
||||
county : str, optional
|
||||
区县名称, 如 "江岸区". 可为空 (表示只解析到市级).
|
||||
prefer_full : bool, optional
|
||||
@ -233,7 +233,7 @@ def resolve_adcode_by_name(
|
||||
|
||||
def fetch_and_save_geojson_by_name(
|
||||
province: str,
|
||||
city: str,
|
||||
city: Optional[str],
|
||||
county: Optional[str],
|
||||
out_dir: Path,
|
||||
prefer_full: bool = False,
|
||||
@ -245,8 +245,8 @@ def fetch_and_save_geojson_by_name(
|
||||
----------
|
||||
province : str
|
||||
省份名称, 如 "湖北省". 不能为空.
|
||||
city : str
|
||||
城市名称, 如 "武汉市". 不能为空.
|
||||
city : str, optional
|
||||
城市名称, 如 "武汉市". 可为空 (表示只解析到省).
|
||||
county : str, optional
|
||||
区县名称, 如 "江岸区". 可为空 (表示只解析到市级).
|
||||
out_dir : Path
|
||||
@ -281,7 +281,9 @@ def fetch_and_save_geojson_by_name(
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 示例 1: 只获取市级边界 (province + city)
|
||||
# out = fetch_and_save_geojson_by_name("湖北省", "武汉市", None, out_dir=Path("./data/vectors/"))
|
||||
out = fetch_and_save_geojson_by_name(
|
||||
"湖北省", None, None, out_dir=Path("./data/vectors/")
|
||||
)
|
||||
|
||||
# 示例 2: 获取十堰市县区级边界
|
||||
# out = fetch_and_save_geojson_by_name(
|
||||
@ -289,8 +291,8 @@ if __name__ == "__main__":
|
||||
# )
|
||||
|
||||
# 示例 3: 获取区县级边界 (province + city + county)
|
||||
out = fetch_and_save_geojson_by_name(
|
||||
"湖北省", "十堰市", "郧西县", out_dir=Path("./data/vectors/"), prefer_full=True
|
||||
)
|
||||
# out = fetch_and_save_geojson_by_name(
|
||||
# "湖北省", "十堰市", "郧西县", out_dir=Path("./data/vectors/"), prefer_full=True
|
||||
# )
|
||||
|
||||
print(f"Saved raw JSON and GeoJSON: {out}.")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user