93 lines
2.8 KiB
Go
93 lines
2.8 KiB
Go
package imageproc
|
||
|
||
import (
|
||
"fmt"
|
||
"time"
|
||
|
||
"github.com/airbusgeo/godal"
|
||
log "github.com/sirupsen/logrus"
|
||
)
|
||
|
||
func calculateProj(topLeftX, topLeftY, width, height, resolution float64) string {
|
||
// 计算图像的地理范围
|
||
bottomRightX := topLeftX + float64(width)*resolution
|
||
bottomRightY := topLeftY + float64(height)*resolution
|
||
|
||
// 根据地理范围和分辨率选择适当的投影信息
|
||
// 这里只是一个示例,你需要根据实际情况选择合适的投影系统和参数
|
||
projection := fmt.Sprintf(`PROJCS["Custom Projection",
|
||
GEOGCS["WGS 84",
|
||
DATUM["WGS_1984",
|
||
SPHEROID["WGS 84",6378137,298.257223563,
|
||
AUTHORITY["EPSG","7030"]],
|
||
AUTHORITY["EPSG","6326"]],
|
||
PRIMEM["Greenwich",0,
|
||
AUTHORITY["EPSG","8901"]],
|
||
UNIT["degree",0.0174532925199433,
|
||
AUTHORITY["EPSG","9122"]],
|
||
AUTHORITY["EPSG","4326"]],
|
||
PROJECTION["Transverse_Mercator"],
|
||
PARAMETER["latitude_of_origin",0],
|
||
PARAMETER["central_meridian",%f],
|
||
PARAMETER["scale_factor",0.9996],
|
||
PARAMETER["false_easting",%f],
|
||
PARAMETER["false_northing",0],
|
||
UNIT["metre",1,
|
||
AUTHORITY["EPSG","9001"]],
|
||
AXIS["Easting",EAST],
|
||
AXIS["Northing",NORTH]]`,
|
||
(topLeftX+bottomRightX)/2, (topLeftY+bottomRightY)/2)
|
||
|
||
projection = `PROJCS["WGS 84 / UTM zone 51N",
|
||
GEOGCS["WGS 84",
|
||
DATUM["WGS_1984",
|
||
SPHEROID["WGS 84",6378137,298.257223563,
|
||
AUTHORITY["EPSG","7030"]],
|
||
AUTHORITY["EPSG","6326"]],
|
||
PRIMEM["Greenwich",0,
|
||
AUTHORITY["EPSG","8901"]],
|
||
UNIT["degree",0.0174532925199433,
|
||
AUTHORITY["EPSG","9122"]],
|
||
AUTHORITY["EPSG","4326"]],
|
||
PROJECTION["Transverse_Mercator"],
|
||
PARAMETER["latitude_of_origin",0],
|
||
PARAMETER["central_meridian",123],
|
||
PARAMETER["scale_factor",0.9996],
|
||
PARAMETER["false_easting",500000],
|
||
PARAMETER["false_northing",0],
|
||
UNIT["metre",1,
|
||
AUTHORITY["EPSG","9001"]],
|
||
AXIS["Easting",EAST],
|
||
AXIS["Northing",NORTH],
|
||
AUTHORITY["EPSG","32651"]]`
|
||
|
||
// 输出投影信息
|
||
return projection
|
||
}
|
||
|
||
func setGeoTransform(ds *godal.Dataset, topLeftX, topLeftY, width, height, resolution float64) {
|
||
// 设置地理变换(假设左上角坐标为(0,0),PAN每个像素分辨率为1.2米)
|
||
geotransform := [6]float64{
|
||
0, // top left x
|
||
resolution, // w-e pixel resolution
|
||
0, // rotation, 0 if image is "north up"
|
||
0, // top left y
|
||
0, // rotation, 0 if image is "north up"
|
||
-resolution, // n-s pixel resolution (negative value)
|
||
}
|
||
err := ds.SetGeoTransform(geotransform)
|
||
if err != nil {
|
||
log.Errorf("Failed to set GeoTransform: %v", err)
|
||
}
|
||
|
||
// 设置投影信息(WGS84)
|
||
err = ds.SetProjection(calculateProj(topLeftX, topLeftY, width, height, resolution))
|
||
if err != nil {
|
||
log.Errorf("Failed to set projection: %v", err)
|
||
}
|
||
|
||
// 设置一些常见的元数据(可选)
|
||
ds.SetMetadata("TIFFTAG_DATETIME", time.Now().String())
|
||
ds.SetMetadata("TIFFTAG_SOFTWARE", "StarWiz-SJY01-IMAGE-PROC")
|
||
}
|