From 3593827b6b04408d40fbb1d4e4ab4a73c7c0de16 Mon Sep 17 00:00:00 2001 From: xingjinshuang <xingjinshuang@smartearth.cn> Date: 星期二, 10 十二月 2024 15:45:43 +0800 Subject: [PATCH] @xingjs@20241210@添加验证GDAL是否成功加载方法 --- src/main/java/com/se/simu/config/InitConfig.java | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 50 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/se/simu/config/InitConfig.java b/src/main/java/com/se/simu/config/InitConfig.java index 44a9cf3..3d486c6 100644 --- a/src/main/java/com/se/simu/config/InitConfig.java +++ b/src/main/java/com/se/simu/config/InitConfig.java @@ -4,6 +4,11 @@ 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; @@ -41,8 +46,53 @@ 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(); + } + + + } -- Gitblit v1.9.3