You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何利用JSON坐标对TIFF影像进行地理配准用于深度学习作物分类

基于JSON坐标的TIFF影像地理配准Python实现方案

前置说明

你提供的JSON文件中geometry字段存储了对应TIFF影像的地理范围多边形,需要先注意JSON中的匿名提示:

WARNING: The item geometries in this collection have been anonymized such that they exist somewhere within the bounding box listed within that item's geometry.
该提示说明JSON中的坐标是匿名化后的近似边界框,影像真实地理范围仅落在该框内,以下方案基于该边界框作为影像实际地理范围实现配准,若需要更高精度配准需要数据集提供真实控制点或更精准的坐标信息。

配准核心逻辑

  • 从JSON中提取多边形的外接矩形,得到地理范围的极值:最小经度min_lon、最大经度max_lon、最小纬度min_lat、最大纬度max_lat
  • 读取未配准TIFF的宽(列数)、高(行数),计算像素的地理分辨率
  • 为TIFF写入地理变换参数和对应空间参考,完成配准

Python实现代码

依赖第三方库:rasterio、json,可通过pip install rasterio安装依赖。

import json
import rasterio
from rasterio.transform import from_bounds
from rasterio.crs import CRS

# 1. 读取JSON坐标文件
with open("替换为你的JSON文件路径.json", "r", encoding="utf-8") as f:
    feature = json.load(f)

# 2. 提取地理范围极值
coords = feature["geometry"]["coordinates"][0]
lons = [point[0] for point in coords]
lats = [point[1] for point in coords]
min_lon, max_lon = min(lons), max(lons)
min_lat, max_lat = min(lats), max(lats)

# 3. 读取原始未配准TIFF
with rasterio.open("替换为未配准TIFF路径.tif") as src:
    img_data = src.read()
    img_profile = src.profile.copy()

# 4. 生成地理变换参数,默认JSON坐标为WGS84坐标系(EPSG:4326)
geo_transform = from_bounds(min_lon, min_lat, max_lon, max_lat, src.width, src.height)
img_profile.update(
    crs=CRS.from_epsg(4326),
    transform=geo_transform,
    driver="GTiff"
)

# 5. 保存配准后的TIFF
with rasterio.open("替换为配准后输出TIFF路径.tif", "w", **img_profile) as dst:
    dst.write(img_data)

注意事项

  • 若JSON坐标对应的坐标系不是WGS84,需要将代码中CRS.from_epsg(4326)的4326替换为对应坐标系的EPSG编码
  • 若你的JSON文件是包含多个影像对应要素的FeatureCollection,需要先根据JSON的id字段匹配对应TIFF影像,再提取对应范围做配准
  • 配准完成后可通过GIS工具打开配准后TIFF和JSON矢量,核验范围匹配度,确认无误后再开展后续像素级分类的样本标注、模型训练工作

内容的提问来源于stack exchange,提问作者Rameen Rahman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 08:15:03