| | |
| | | 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; |
| | |
| | | @Slf4j |
| | | @SuppressWarnings("ALL") |
| | | public class GdalHelper { |
| | | /** |
| | | * 初始化 |
| | | */ |
| | | public static void init(String gdalPath) { |
| | | // 支持中文路径 |
| | | gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); |
| | |
| | | |
| | | // 配置环境变量 |
| | | 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)) { |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |