Commit 0743b1ed authored by xiaosl's avatar xiaosl

ruku

parent 59b4412e
......@@ -4,7 +4,6 @@
*/
package com.upyuns.platform.rs.gtdata;
import lombok.Data;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpStatus;
......@@ -470,8 +469,8 @@ public class GtDataRestClient {
* @return
*
*/
public Map<String, Object> mkdirs(String path) {
return mkdirs(path, defaultSign, defaultTime);
public Map<String, Object> mkdirOnly(String path) {
return mkdirOnly(path, defaultSign, defaultTime);
}
/**
......@@ -484,7 +483,7 @@ public class GtDataRestClient {
* @return
*
*/
public Map<String, Object> mkdirs(String path, String sign, String time) {
public Map<String, Object> mkdirOnly(String path, String sign, String time) {
String resourceUrl = MessageFormat.format(
"{0}{1}?op=MKDIRS&sign={2}&time={3}", gtDataUrl, path, sign,
time);
......@@ -496,17 +495,17 @@ public class GtDataRestClient {
*
* @param path
*/
public Map<String, Object> mkdir(String path) {
public Map<String, Object> mkdirs(String path) {
String parentPath = StringUtils.substringBeforeLast(path, "/");
if (logger.isInfoEnabled()) {
logger.info("path:{},parentPath:{},isExist(parentPath):{},", path,parentPath,isExist(parentPath).get("exist"));
}
if ( isExist(parentPath).get("exist").toString().equals("true")) {
return mkdirs(path);
return mkdirOnly(path);
} else {
mkdir(parentPath);
return mkdirs(path);
mkdirs(parentPath);
return mkdirOnly(path);
}
}
......
......@@ -16,13 +16,4 @@
<module>rs-datacenter-api</module>
<module>rs-datacenter-server</module>
</modules>
<dependencies>
<dependency>
<groupId>org.gdal</groupId>
<artifactId>gdal</artifactId>
<version>1.11.2</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package com.upyuns.platform.rs.datacenter.vo;
import lombok.Data;
import java.util.List;
@Data
public class ImageStorageVo {
//左上角经度
private Double leftTopLon;
//左上角维度
private Double leftTopLat;
//左下角经度
private Double leftBottomLon;
//左下角维度
private Double leftBottomLat;
//右下角经度
private Double rightBottomLon;
//右下角维度
private Double rightBottomLat;
//右上角经度
private Double rightTopLon;
//右上角维度
private Double rightTopLat;
//数据名称
private String name;
//缩略图存储路径
private String thumbnailPath;
//分辨率数组
private Double[] imageResolution;
//光谱
private String imageSpectrumType;
//光谱名称
private String imageSpectrumTypeDisplay;
//影像存储地址目录
private String imageFilePath;
//中心点经纬度
private Double imageCenterPointLat;
private Double imageCenterPointLon;
//投影
private String imageProjection;
//卫星类型
private String imageSatelliteType;
//卫星名称
private String imageSatelliteTypeDisplay;
//拍摄时间
private String imageTakeTime;
//云量
private Integer imageCloudage;
//传感器类型
private String imageSensorType;
//传感器id
private String imageSensorId;
//文件名称
private List<String> files;
//景id
private String imageSceneId;
//产品格式 GEOTIFF 、 TIFF
private String imageProductFormat;
//产品时间
private String imageProductTime;
//sat行号
private String imageSatPath;
//sat列号
private String imageSatRow;
//影像开始时间
private String imageStartTime;
//影像结束时间
private String imageEndTime;
//影像中间时间
private String imageCenterTime;
//影像宽度
private Integer imageWidthInPixels;
//影像高度
private String imageHeightInPixels;
//卫星平台平均俯仰角
private String imagePitchSatellitessAngle;
//太阳方位角
private String imageSolarAzimuth;
//太阳高度角
private String imageSolarZenith;
//卫星方向角
private String imageSatelliteAzimuth;
//卫星高度角
private String imageSatelliteZenith;
//卫星平台平均偏航角
private String imageYawSatelliteAngle;
//供应商
private String supplier;
}
......@@ -18,6 +18,17 @@
<version>2.0-rscp-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.gdal</groupId>
<artifactId>gdal</artifactId>
<version>3.0.0</version>
</dependency>
<!-- XML解析包 -->
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
<build>
......
package com.upyuns.platform.rs.datacenter.utils;
public class FileOperateUtil {
public static String getFileNameNotFormat(String filePath) {
filePath = filePath.replaceAll("\\\\", "/");
Integer indexOf = filePath.lastIndexOf("/");
String fileName = filePath.substring(indexOf);
String dirName = fileName;
indexOf = filePath.lastIndexOf(".");
if (indexOf > 0) {
dirName = dirName.substring(0, indexOf);
}
return dirName;
}
public static String getFileName(String filePath) {
filePath = filePath.replaceAll("\\\\", "/");
Integer indexOf = filePath.lastIndexOf("/");
String fileName = filePath.substring(indexOf);
return fileName;
}
}
package com.upyuns.platform.rs.datacenter.utils;
import com.github.wxiaoqi.security.common.constant.RestCode;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import com.upyuns.platform.rs.datacenter.vo.ImageStorageVo;
import com.upyuns.platform.rs.gtdata.GtDataRestClient;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
public class ImageStorageParseUtil {
@Value("${localDirTemp.tarFileTemp}")
private static String tarFileTempDir;
@Autowired
private static GtDataRestClient gtDataRestClient;
public static ImageStorageVo tarFileParseGtData(String inputGtPath, String ouputGtDir)throws BaseException {
//将GT上压缩包下载到本地
Integer indexOf = inputGtPath.lastIndexOf("/");
String fileName = inputGtPath.substring(indexOf);
String dirName = fileName;
indexOf = inputGtPath.lastIndexOf(".");
if (indexOf > 0) {
dirName = dirName.substring(0, indexOf);
}
File localDir = new File(tarFileTempDir + "/" + dirName);
localDir.mkdirs();
String localInputPath = localDir + "/" + fileName;
Map<String,Object > result = gtDataRestClient.open(inputGtPath);
if ((Integer)result.get("HttpStatusCode") != 200) {
throw new BaseException("文件下载失败", ResultCode.FAILED_CODE);
}
try {
OutputStream outputStream = new FileOutputStream(new File(localInputPath));
outputStream.write((byte[])result.get("file"));
outputStream.flush();
outputStream.close();
}catch (Exception e) {
throw new BaseException("文件保存失败", ResultCode.FAILED_CODE);
}
return tarFileParse(localInputPath, localDir.getPath(), ouputGtDir);
}
public static ImageStorageVo tarFileParse(String inputLocalPath, String localOutputDir, String outputGtPath) throws BaseException {
if (inputLocalPath.endsWith("zip")) {
//Satellogic 压缩包解析
return satellogicParse(inputLocalPath, localOutputDir, outputGtPath);
}else if (inputLocalPath.endsWith("tar.gz")) {
throw new BaseException("tar.gz 压缩包未实现", ResultCode.FAILED_CODE);
}else {
throw new BaseException("压缩包格式不支持", ResultCode.FAILED_CODE);
}
}
//Satellogic 压缩包解析
public static ImageStorageVo satellogicParse(String inputLocalPath, String localOutputDir, String outputGtPath) throws BaseException {
//1、提取解析xml文件
List<String> xmlPathList = TarFileOperateUtil.zipFileRead(inputLocalPath, localOutputDir,".xml");
if (xmlPathList == null || xmlPathList.size() == 0) {
throw new BaseException("xml文件提取失败", ResultCode.FAILED_CODE);
}
ImageStorageVo imageStorageVo = new ImageStorageVo();
//初始基础或固定信息
imageStorageVo.setName(FileOperateUtil.getFileNameNotFormat(inputLocalPath));
imageStorageVo.setImageProductFormat("TIFF");
imageStorageVo.setImageSpectrumType("{QS,DGP}");
imageStorageVo.setImageSpectrumTypeDisplay("{全色,多光谱}");
imageStorageVo.setImageProjection("WGS-84");
Map<String, String> paramsMap = new HashedMap();
boolean xmlFlag = false;
for (String xmlPath : xmlPathList) {
paramsMap.clear();
XmlFileOperateUtil.xmlParse(xmlPath, paramsMap);
if (paramsMap.get("camera") != null && paramsMap.get("bounds") != null) {
//拍摄时间
imageStorageVo.setImageTakeTime(paramsMap.get("created_at"));
imageStorageVo.setImageProductTime(paramsMap.get("created_at"));
imageStorageVo.setImageEndTime(paramsMap.get("created_at"));
imageStorageVo.setImageStartTime(paramsMap.get("created_at"));
imageStorageVo.setImageCenterTime(paramsMap.get("created_at"));
//供应商
imageStorageVo.setSupplier(paramsMap.get("supplier"));
//卫星名称、类型
imageStorageVo.setImageSatelliteType(paramsMap.get("satellite_name"));
imageStorageVo.setImageSatelliteTypeDisplay(paramsMap.get("satellite_name"));
//云量
imageStorageVo.setImageCloudage(new BigDecimal(paramsMap.get("cloud_pctg")).intValue());
//传感器类型
imageStorageVo.setImageSensorType(paramsMap.get("camera"));
imageStorageVo.setImageSensorId(paramsMap.get("camera"));
xmlFlag = true;
break;
}
}
if (!xmlFlag) {
throw new BaseException("xml 解析失败", ResultCode.FAILED_CODE);
}
//2、提取tiff,生成缩略图
//3、转坐标系
return imageStorageVo;
}
}
package com.upyuns.platform.rs.datacenter.utils;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import org.apache.commons.lang3.StringUtils;
import java.io.*;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class TarFileOperateUtil {
/**
* 解压zip压缩包中,指定文件类型的文件
* @param file
* @param saveRootDirectory
* @param suffix
* @return 返回解压后的文件路径列表
* @throws Exception
*/
public static List<String> zipFileRead(String file, String saveRootDirectory, String suffix)throws BaseException {
try {
List<String> filePathList = new ArrayList<>();
String lowerCaseSuffix = suffix;
if (StringUtils.isBlank(lowerCaseSuffix)) {
lowerCaseSuffix = lowerCaseSuffix.toLowerCase();
}
ZipFile zipFile = new ZipFile(file);
@SuppressWarnings("unchecked")
Enumeration<ZipEntry> enu = (Enumeration<ZipEntry>) zipFile.entries();
while (enu.hasMoreElements()) {
ZipEntry zipElement = enu.nextElement();
InputStream read = zipFile.getInputStream(zipElement);
String fileName = zipElement.getName();
if (!zipElement.isDirectory() && fileName != null) {//是否为文件
if (StringUtils.isBlank(lowerCaseSuffix)) {
if (zipExecute(zipElement, read, saveRootDirectory)) {
filePathList.add(saveRootDirectory + "/" + fileName);
}
} else if (fileName.toLowerCase().endsWith(lowerCaseSuffix)) {//指定文件类型
if (zipExecute(zipElement, read, saveRootDirectory)) {
filePathList.add(saveRootDirectory + "/" + fileName);
}
}
}
}
return filePathList;
}catch (Exception e) {
throw new BaseException("xml解析失败", ResultCode.FAILED_CODE);
}
}
private static boolean zipExecute(ZipEntry ze, InputStream read, String saveRootDirectory) throws IOException {
String fileName = ze.getName();
File file = new File(saveRootDirectory + "/" + fileName);
if (!file.exists()) {
File rootDirectoryFile = new File(file.getParent());
//创建目录
if (!rootDirectoryFile.exists()) {
boolean ifSuccess = rootDirectoryFile.mkdirs();
if (ifSuccess) {
System.out.println("文件夹创建成功!");
} else {
return false;
}
}
//创建文件
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
//写入文件
BufferedOutputStream write = new BufferedOutputStream(new FileOutputStream(file));
int cha = 0;
while ((cha = read.read()) != -1) {
write.write(cha);
}
//要注意IO流关闭的先后顺序
write.flush();
write.close();
read.close();
return true;
}
}
package com.upyuns.platform.rs.datacenter.utils;
import com.github.wxiaoqi.security.common.exception.BaseException;
import com.github.wxiaoqi.security.common.util.process.ResultCode;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class XmlFileOperateUtil {
public static void xmlParse(String xmlPath, Map<String, String> paramsMap) throws BaseException{
try {
//1.创建Reader对象
SAXReader reader = new SAXReader();
//2.加载xml
Document document = reader.read(new File(xmlPath));
//3.获取根节点
Element rootElement = document.getRootElement();
Iterator iterator = rootElement.elementIterator();
while (iterator.hasNext()) {
Element stu = (Element) iterator.next();
List<Attribute> attributes = stu.attributes();
System.out.println("======获取属性值======");
for (Attribute attribute : attributes) {
System.out.println(attribute.getValue());
}
System.out.println("======遍历子节点======");
Iterator iterator1 = stu.elementIterator();
while (iterator1.hasNext()) {
Element stuChild = (Element) iterator1.next();
paramsMap.put(stuChild.getName(), stuChild.getStringValue());
}
}
}catch (Exception e) {
throw new BaseException("xml解析失败", ResultCode.FAILED_CODE);
}
}
}
package com.upyuns.platform.rs.datacenter.utils.gdal;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGEncodeParam;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import org.gdal.gdal.Dataset;
import org.gdal.gdal.Driver;
import org.gdal.gdal.gdal;
import org.gdal.gdalconst.gdalconstConstants;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class ImageOperateTools {
/**
* tif 文件转 为png文件
* tif 文件转 为图片
* @param inputPath
* @param outputPath
* @return
*/
public static Boolean tif2Png(String inputPath, String outputPath) {
public static Boolean tif2Pic(String inputPath, String outputPath) {
//注册GDAL
gdal.AllRegister();
//设置中文
gdal.SetConfigOption("gdal_FILENAME_IS_UTF8", "YES");
//只读方式读取数据
Dataset sourceData = gdal.Open(inputPath, gdalconstConstants.GA_ReadOnly);
if (sourceData == null) {
return false;
}
Driver hDriver = sourceData.GetDriver();
hDriver.CreateCopy(outputPath, sourceData);
hDriver.delete();
sourceData.delete();
return true;
}
//jpeg图片压缩处理
public static Boolean zipImageFile(String oldFile, String newFile, int width, int height, float quality) {
if (oldFile == null) {
return null;
}
try {
/**对服务器上的临时文件进行处理 */
Image srcFile = ImageIO.read(new File(oldFile));
/** 宽,高设定 */
BufferedImage tag = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
tag.getGraphics().drawImage(srcFile, 0, 0, width, height, null);
/**
*
* @param inputPath
* @param outputPath
* @return
*/
public static Boolean tif2Jpeg(String inputPath, String outputPath) {
/** 压缩之后临时存放位置 */
FileOutputStream out = new FileOutputStream(newFile);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam jep = JPEGCodec.getDefaultJPEGEncodeParam(tag);
/** 压缩质量 */
jep.setQuality(quality, true);
encoder.encode(tag, jep);
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
return true;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment