Commit 17297993 authored by xiaosl's avatar xiaosl

Merge branch 'parseXML-xsl' into dev

parents 2a4df805 f9882d8e
package com.upyuns.platform.rs.datacenter.utils;
import java.io.File;
public class FileOperateUtil {
public static String getFileNameNotFormat(String filePath) {
......@@ -20,4 +22,19 @@ public class FileOperateUtil {
String fileName = filePath.substring(indexOf);
return fileName;
}
public static String getlocalFileParentPath(String filePath) {
File file = new File(filePath);
return file.getParent();
}
public static String getPathParentPath(String filePath) {
filePath = filePath.replaceAll("\\\\", "/");
Integer indexOf = filePath.lastIndexOf("/");
String parentPath = filePath;
if (indexOf > 0) {
parentPath = parentPath.substring(0, indexOf);
}
return parentPath;
}
}
......@@ -3,9 +3,12 @@ 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.utils.gdal.ImageOperateTools;
import com.upyuns.platform.rs.datacenter.vo.ImageStorageVo;
import com.upyuns.platform.rs.gtdata.GtDataRestClient;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang.time.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
......@@ -14,8 +17,8 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.text.SimpleDateFormat;
import java.util.*;
public class ImageStorageParseUtil {
......@@ -73,6 +76,7 @@ public class ImageStorageParseUtil {
if (xmlPathList == null || xmlPathList.size() == 0) {
throw new BaseException("xml文件提取失败", ResultCode.FAILED_CODE);
}
List<String> fileNameList = new ArrayList<>();
ImageStorageVo imageStorageVo = new ImageStorageVo();
//初始基础或固定信息
imageStorageVo.setName(FileOperateUtil.getFileNameNotFormat(inputLocalPath));
......@@ -88,22 +92,41 @@ public class ImageStorageParseUtil {
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"));
String takeTime = paramsMap.get("created_at");
if (StringUtils.isNotBlank(takeTime)) {
String takeTimeFormat = takeTime.replace("T", " ");
Integer indexOf = takeTimeFormat.lastIndexOf(".");
if (indexOf > 0) {
takeTimeFormat = takeTimeFormat.substring(0, indexOf);
}
if (takeTime.toLowerCase().endsWith("z")) {//UTC格林标准时区
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date date = sdf.parse(takeTimeFormat);
DateUtils.addHours(date, 8);//增加8小时,转为北京时区
takeTimeFormat = sdf.format(date);
}catch (Exception e) {
throw new BaseException("时间解析失败", ResultCode.FAILED_CODE);
}
}
imageStorageVo.setImageTakeTime(takeTimeFormat);
imageStorageVo.setImageProductTime(takeTimeFormat);
imageStorageVo.setImageEndTime(takeTimeFormat);
imageStorageVo.setImageStartTime(takeTimeFormat);
imageStorageVo.setImageCenterTime(takeTimeFormat);
}
//供应商
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.setImageCloudage(new BigDecimal(paramsMap.get("cloud_pctg")));
//传感器类型
imageStorageVo.setImageSensorType(paramsMap.get("camera"));
imageStorageVo.setImageSensorId(paramsMap.get("camera"));
//景id
imageStorageVo.setImageSceneId(paramsMap.get("scene_id"));
xmlFlag = true;
break;
......@@ -113,7 +136,27 @@ public class ImageStorageParseUtil {
throw new BaseException("xml 解析失败", ResultCode.FAILED_CODE);
}
//2、提取tiff,生成缩略图
List<String> tifPathList = TarFileOperateUtil.zipFileRead(inputLocalPath, localOutputDir,".tif");
if (tifPathList == null || tifPathList.size() == 0) {
tifPathList = TarFileOperateUtil.zipFileRead(inputLocalPath, localOutputDir,".tiff");
}
if (tifPathList == null || tifPathList.size() == 0) {
throw new BaseException("tif 文件提取失败", ResultCode.FAILED_CODE);
}
//生成缩略图
List<String> picPathList = new ArrayList<>();
for (String tifPath : tifPathList) {
if (tifPath.toLowerCase().contains("_quicklook")) {
String localPicPrefix = FileOperateUtil.getlocalFileParentPath(tifPath) + "/" +
FileOperateUtil.getFileNameNotFormat(tifPath);
String localPngPic = localPicPrefix + ".png";
ImageOperateTools.tif2Pic(tifPath, localPngPic);
picPathList.add(localPngPic);
String localTargetPngPic = localPicPrefix + "_800_800.png";
ImageOperateTools.zipImageFile(localPngPic, localTargetPngPic, 800, 1.0f);
break;
}
}
//3、转坐标系
return imageStorageVo;
}
......
......@@ -9,6 +9,7 @@ import org.gdal.gdal.gdal;
import org.gdal.gdalconst.gdalconstConstants;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
......@@ -44,6 +45,28 @@ public class ImageOperateTools {
return true;
}
//jpeg图片压缩处理
public static Boolean zipImageFile(String oldFile, String newFile, int width, float quality) {
if (oldFile == null) {
return false;
}
try {
/**对服务器上的临时文件进行处理 */
Image srcFile = ImageIO.read(new File(oldFile));
ImageIcon imageIcon = new ImageIcon(oldFile);
int iconWidth = imageIcon.getIconWidth();
int iconHeight = imageIcon.getIconHeight();
int height = iconHeight * width / iconWidth;
return zipImageFile(oldFile, newFile, width, height, quality);
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
//jpeg图片压缩处理
public static Boolean zipImageFile(String oldFile, String newFile, int width, int height, float quality) {
if (oldFile == null) {
......
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