create-boundary-image
土壤污染状况调查边界图片生成工具:读取地块边界文件(.zip / .shp),生成带卫星底图、红色边界线、指北针、比例尺和地块标注的图片。
当前只做「出图」这一件事;生成/校验边界文件、批量处理不在范围内。
安装
uv tool install .
从源码运行 / 开发:
uv sync
uv run create-boundary-image --help
uv run create-boundary-image 初步调查13251351313.zip
命令行
# 出图到当前目录,文件名与输入相同
create-boundary-image 初步调查33042432609438.zip
# 输出到指定目录 / 指定文件名
create-boundary-image 初步调查33042432609438.zip -o 出图/
create-boundary-image 地块.shp -o 出图/边界.jpg
# 离线(不叠加卫星底图,只画边界线)
create-boundary-image 地块.zip --no-basemap
# 高分辨率 + 按属性字段标注
create-boundary-image 地块.zip -o 出图/ --dpi 300 --label-field DKMC
参数
| 参数 | 说明 | 缺省 |
|---|---|---|
input |
边界文件路径,.zip 或 .shp |
必填 |
-o, --output PATH |
输出图片路径;给目录则自动命名为 <输入名>.jpg |
当前目录 |
--dpi N |
输出分辨率 | 200 |
--figsize WxH |
图幅上限(英寸),如 10x8;高度按数据比例自动适配 |
8x8 |
--label TEXT |
覆盖标注文字 | 取文件名(调查阶段+DKBM) |
--label-field FIELD |
按属性字段逐图斑标注,优先于 --label |
— |
--no-label |
不添加标注 | — |
--basemap NAME |
底图源,如 Esri.WorldImagery、OpenStreetMap.Mapnik |
Esri 卫星影像 |
--no-basemap |
不叠加底图,可离线使用 | — |
--edge-color COLOR |
边界线颜色 | red |
--line-width N |
边界线宽 | 2 |
--inner NAME |
zip 内有多个 shp 时指定内层文件名 | 自动定位 |
-q, --quiet |
成功时不打印提示 | — |
退出码
| 码 | 含义 |
|---|---|
0 |
成功 |
1 |
运行错误(文件不存在、数据无效、底图下载失败等) |
2 |
参数错误 |
输出
- 默认输出
<输入名>.jpg,例如初步调查33042432609438.zip→初步调查33042432609438.jpg - 保存格式由输出文件扩展名决定:缺省
.jpg(JPEG 质量 95、白底),也可写.png等 - 图面为 Web 墨卡托下等比例绘制,边界线为红色,标注居中于最大图斑内部(凹多边形质心落在外部时自动改用内部代表点)
- 右上角带指北针,左下角带比例尺(长度取 1/2/5×10ⁿ 的整数距离,已按图幅中心纬度校正墨卡托的长度变形)
- 取景:四周按数据较长边的固定比例等距留白(缺省 45%,库接口
padding可调),图幅比例自动贴合数据,所以输出里没有多余白边
输入约定
-
支持
.zip与.shp。zip 内部的 shp 会自动定位,因此下面两种打包方式都可以:初步调查33042432609438.zip └── 初步调查33042432609438/ └── 初步调查33042432609438.shp # 含 .shx/.dbf/.prj/.cpg 地块.zip └── 地块.shp -
读入后统一按文件自带的坐标系(
.prj)重投影到 EPSG:3857 出图,不假设输入坐标系。 -
标注文字缺省取文件名(即
调查阶段+DKBM),与打包命名约定一致。
底图
默认使用 Esri World Imagery(全球卫星影像),无需密钥。
- 它属于 WGS84 / Web 墨卡托体系,与 CGCS2000 数据在厘米级一致,不需要纠偏。
- 高德 / 腾讯 / 百度等国内底图使用 GCJ-02(火星坐标),直接叠加会有 100–700 m 的系统性偏移,因此未作为默认;如确需使用,需自行处理纠偏。
- 底图瓦片需要联网。下载失败时命令会报错退出并提示,而不是静默生成一张没有底图的图;离线场景请显式加
--no-basemap。
作为库使用
from create_boundary_image import plot_boundary, read_boundary
gdf = read_boundary("初步调查33042432609438.zip") # 也接受 .shp 路径
print(gdf.crs, len(gdf))
plot_boundary(
"初步调查33042432609438.zip",
"出图/边界图.jpg",
dpi=300,
label_field="DKMC", # 或 label="自定义文字"
# padding=0.45, # 四周留白比例(相对数据较长边)
# basemap=None, # 不叠加底图
# scale_bar=False, # 不画比例尺
# north_arrow=False, # 不画指北针
)
主要导出:plot_boundary、read_boundary、boundary_name、shp_uri、add_scale_bar、add_north_arrow、DEFAULT_BASEMAP、PLOT_CRS、BasemapError。
add_scale_bar(ax, latitude) / add_north_arrow(ax) 也可单独调用,用于自建制图布局。
开发
uv sync
uv run pytest # 测试全部离线运行,不需要网络
依赖
geopandas、shapely、pyogrio、contextily、matplotlib、xyzservices(需要 Python ≥ 3.14)。
Metadata
Release files for create-boundary-image 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| create_boundary_image-0.1.0.tar.gz | 13.0 kB | Without provenance | Details for create_boundary_image-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| create_boundary_image-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for create_boundary_image-0.1.0-py3-none-any.whl |
Total release size: 29.3 kB
Release files / create_boundary_image-0.1.0.tar.gz
| Download URL | create_boundary_image-0.1.0.tar.gz |
|---|---|
| Size | 13.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9be46978643a8a0c652805ea42923c60a6fa8c74d4a935e2f6998e6230f75f5c
|
|
BLAKE2b-256 checksum How to use checksums |
c1e5ee1dea90dc80b01a8c2d8109f7d1237ee60bcc0e93eb91e6f03b51d58ee6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / create_boundary_image-0.1.0-py3-none-any.whl
| Download URL | create_boundary_image-0.1.0-py3-none-any.whl |
|---|---|
| Size | 16.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5b5692c7cd5e2fab0bd734fbdc5b5c38ec7c1f0befbb7e25cbb732fceaa0ae52
|
|
BLAKE2b-256 checksum How to use checksums |
b6a34bb861443405699bb9c960080e18990e5bed840762bfc9eb2107da97c320
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for create-boundary-image 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.