package com.se.simu.config;
|
|
import com.se.simu.helper.CaffeineHelper;
|
import com.se.simu.helper.GdalHelper;
|
import com.se.simu.helper.WebHelper;
|
import lombok.extern.slf4j.Slf4j;
|
import org.gdal.gdal.Band;
|
import org.gdal.gdal.Dataset;
|
import org.gdal.gdal.Driver;
|
import org.gdal.gdal.gdal;
|
import org.gdal.gdalconst.gdalconstConstants;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationRunner;
|
import org.springframework.core.env.Environment;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
|
@Slf4j
|
@Component
|
@SuppressWarnings("ALL")
|
public class InitConfig implements ApplicationRunner {
|
@Resource
|
Environment env;
|
|
@Value("${server.port}")
|
String serverPort;
|
|
@Value("${config.cacheTime}")
|
Integer cacheTime;
|
|
@Value("${server.servlet.context-path}")
|
String contextPath;
|
|
@Override
|
public void run(ApplicationArguments args) {
|
// noinspection AlibabaRemoveCommentedCode
|
try {
|
log.info("***************** 初始化 GDAL *****************" + "\n");
|
GdalHelper.init(env.getProperty("config.gdalPath"));
|
CaffeineHelper.init(cacheTime);
|
|
String path = null != contextPath && contextPath.length() > 1 ? contextPath : "";
|
log.info("API文档:http://localhost:" + serverPort + path + "/doc.html");
|
log.info("API文档:http://{}:{}{}/doc.html", WebHelper.getHostIp(), serverPort, path);
|
|
log.info("***************** 系统启动完毕 *****************" + "\n");
|
|
//log.info("***************** 读取tif文件 *****************" + "\n");
|
// 读取tif文件
|
//readTif("D:\\soft\\env\\tif\\srtm_12_03.tif");
|
//log.info("***************** 读取tif文件完毕 *****************" + "\n");
|
|
|
} catch (Exception ex) {
|
log.error(ex.getMessage(), ex);
|
}
|
}
|
|
|
/**
|
* 读取tif文件
|
*
|
* @param fileName
|
*/
|
public static void readTif(String fileName) {
|
// 读取影像数据
|
Dataset dataset = gdal.Open(fileName, gdalconstConstants.GA_ReadOnly);
|
if (dataset == null) {
|
System.out.println("read fail!");
|
return;
|
}
|
|
// providing various methods for a format specific driver.
|
Driver driver = dataset.GetDriver();
|
System.out.println("driver name: " + driver.getLongName());
|
|
// 读取影像信息
|
int xSize = dataset.getRasterXSize();
|
int ySzie = dataset.getRasterYSize();
|
int rasterCount = dataset.getRasterCount();
|
System.out.println("dataset xSize: " + xSize + ", ySzie = " + ySzie + ", rasterCount = " + rasterCount);
|
|
Band band = dataset.GetRasterBand(1);
|
// the data type of the band.
|
int type = band.GetRasterDataType();
|
System.out.println("data type = " + type + ", " + (type == gdalconstConstants.GDT_Byte));
|
|
// Frees the native resource associated to a Dataset object and close the file.
|
dataset.delete();
|
|
gdal.GDALDestroyDriverManager();
|
}
|
|
|
|
}
|