13693261870
2024-07-16 fc7aae282af8b5ca9544fe3579e7b09aa0295f62
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.se.simu.helper;
 
import lombok.extern.slf4j.Slf4j;
import org.gdal.gdal.gdal;
import org.gdal.ogr.ogr;
 
import java.io.File;
 
/**
 * GDAL帮助类
 *
 * @author WWW
 * @date 2024-07-16
 */
@Slf4j
@SuppressWarnings("ALL")
public class GdalHelper {
    public static void init(String gdalPath) {
        // 支持中文路径
        gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
        // 属性表支持中文:CP936
        gdal.SetConfigOption("SHAPE_ENCODING", "");
        gdal.SetConfigOption("PGEO_DRIVER_TEMPLATE", "DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=%s");
        gdal.SetConfigOption("MDB_DRIVER_TEMPLATE", "DRIVER=Microsoft Access Driver (*.mdb, *.accdb);DBQ=%s");
 
        // 配置环境变量
        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");
 
            String path = System.getenv("PATH");
            if (!path.contains(gdalPath)) {
                System.setProperty("PATH", path + ";" + gdalPath);
            }
        }
 
        // 注册所有的驱动
        gdal.AllRegister();
        ogr.RegisterAll();
    }
}