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(); } } } }