package com.se.nsl.utils;
|
|
import com.alibaba.fastjson.JSONArray;
|
import org.gdal.gdal.Dataset;
|
import org.gdal.gdal.gdal;
|
|
public class TiffCoordinateExtractorUtil {
|
public static void main(String[] args) {
|
getCoordinate("D:\\城市内涝\\sem\\DEM.tif");
|
}
|
public static JSONArray getCoordinate(String tifPath){
|
gdal.AllRegister();
|
JSONArray array=new JSONArray();
|
Dataset dataset = gdal.Open(tifPath);
|
if (dataset!= null) {
|
double[] geotransform = dataset.GetGeoTransform();
|
if (geotransform!= null) {
|
double xmin = geotransform[0];
|
double ymax = geotransform[3];
|
double xmax = geotransform[0] + geotransform[1] * dataset.getRasterXSize();
|
double ymin = geotransform[3] + geotransform[5] * dataset.getRasterYSize();
|
System.out.println("左上角经纬度: (" + xmin + ", " + ymax + ")");
|
array.add(ProjectionToGeographicUtil.getPoint(xmin,ymax));
|
System.out.println("右上角经纬度: (" + xmax + ", " + ymax + ")");
|
array.add(ProjectionToGeographicUtil.getPoint(xmax,ymax));
|
System.out.println("左下角经纬度: (" + xmin + ", " + ymin + ")");
|
array.add(ProjectionToGeographicUtil.getPoint(xmin,ymin));
|
System.out.println("右下角经纬度: (" + xmax + ", " + ymin + ")");
|
array.add(ProjectionToGeographicUtil.getPoint(xmax,ymin));
|
}
|
}
|
System.out.println(array.toJSONString());
|
return array;
|
}
|
}
|