From a7766f8c1619fde0ea8233fd078205031bab54ef Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期二, 16 七月 2024 17:13:25 +0800 Subject: [PATCH] 创建金字塔 --- src/main/java/com/se/simu/helper/GdalHelper.java | 42 ++++++++++++++++++++++++++++++++++++++---- 1 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/se/simu/helper/GdalHelper.java b/src/main/java/com/se/simu/helper/GdalHelper.java index 5de0452..5c03481 100644 --- a/src/main/java/com/se/simu/helper/GdalHelper.java +++ b/src/main/java/com/se/simu/helper/GdalHelper.java @@ -1,7 +1,11 @@ package com.se.simu.helper; import lombok.extern.slf4j.Slf4j; +import org.gdal.gdal.Band; +import org.gdal.gdal.Dataset; import org.gdal.gdal.gdal; +import org.gdal.gdalconst.gdalconst; +import org.gdal.gdalconst.gdalconstConstants; import org.gdal.ogr.ogr; import java.io.File; @@ -15,6 +19,9 @@ @Slf4j @SuppressWarnings("ALL") public class GdalHelper { + /** + * 鍒濆鍖� + */ public static void init(String gdalPath) { // 鏀寔涓枃璺緞 gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); @@ -25,10 +32,10 @@ // 閰嶇疆鐜鍙橀噺 if (!StringHelper.isEmpty(gdalPath)) { - gdal.SetConfigOption("GDAL_DATA", gdalPath + File.separator + "gdal-data"); - gdal.SetConfigOption("PROJ_LIB", gdalPath + File.separator + "proj7" + File.separator + "share"); - //System.setProperty("PROJ_LIB", gdalPath + File.separator + "proj7" + File.separator + "share") - gdal.SetConfigOption("GDAL_DRIVER_PATH", gdalPath + File.separator + "gdalplugins"); + gdal.SetConfigOption("GDAL_DATA", gdalPath + "/gdal-data"); + gdal.SetConfigOption("PROJ_LIB", gdalPath + "/proj7/share"); + //System.setProperty("PROJ_LIB", gdalPath + "/proj7/share") + gdal.SetConfigOption("GDAL_DRIVER_PATH", gdalPath + "/gdalplugins"); String path = System.getenv("PATH"); if (!path.contains(gdalPath)) { @@ -40,4 +47,31 @@ gdal.AllRegister(); ogr.RegisterAll(); } + + /** + * 鍒涘缓閲戝瓧濉� + */ + public static void createPyramid(String file) { + try { + File f = new File(file); + if (!f.exists() || f.isDirectory()) { + return; + } + + Dataset ds = gdal.Open(file, gdalconst.GA_ReadOnly); + if (null == ds) { + return; + } + + // 鍒涘缓閲戝瓧濉� + Band band = ds.GetRasterBand(1); + if (0 == band.GetOverviewCount()) { + ds.BuildOverviews("nearest", new int[]{2, 4, 6, 8, 16}, null); + } + + ds.delete(); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + } + } } -- Gitblit v1.9.3