管道基础大数据平台系统开发-【后端】-Server
13693261870
2023-08-27 126a156beabb3e61bc5ba888f8915adc8e974c2a
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.lf.server.service.data;
 
import com.lf.server.helper.StringHelper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.gdal.gdal.Dataset;
import org.gdal.gdal.gdal;
import org.gdal.gdalconst.gdalconst;
import org.springframework.stereotype.Service;
 
import java.io.File;
 
/**
 * 栅格服务
 * @author WWW
 * @date 2023-08-27
 */
@Service
public class RasterService {
    private final static Log log = LogFactory.getLog(RasterService.class);
 
    /**
     * 获取栅格数据的EPSG编码
     */
    public Integer getRaterEpsg(String file) {
        Dataset ds = null;
        try {
            File f = new File(file);
            if (!f.exists() || f.isDirectory()) {
                return null;
            }
 
            ds = gdal.Open(file, gdalconst.GA_ReadOnly);
            if (null == ds || 0 == ds.getRasterCount()) {
                return null;
            }
 
            if (null == ds.GetSpatialRef()) {
                return null;
            }
 
            // PROJCS、 GEOGCS、GEOGCS 或 NULL
            String code = ds.GetSpatialRef().GetAuthorityCode(null);
            if (StringHelper.isEmpty(code)) {
                return null;
            }
 
            return Integer.parseInt(code);
        } catch (Exception ex) {
            log.error(ex.getMessage(), ex);
            return null;
        } finally {
            if (null != ds) {
                ds.delete();
            }
        }
    }
}