气象折线图bug修改
This commit is contained in:
parent
b2a591e366
commit
059c52615e
|
|
@ -4,6 +4,8 @@ public class LatLonSizeConstants {
|
|||
// 网格参数
|
||||
public static final int LAT_SIZE = 721; // 纬度方向网格数
|
||||
public static final int LON_SIZE = 1440; // 经度方向网格数
|
||||
public static final int LAT_SIZE_181 = 181; // 纬度方向网格数
|
||||
public static final int LON_SIZE_360 = 360; // 经度方向网格数
|
||||
public static final double LAT_START = 90.0; // 纬度起始值(北纬)
|
||||
public static final double LAT_END = -90.0; // 纬度结束值(南纬)
|
||||
public static final double LON_START = 0.0; // 经度起始值
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import java.util.concurrent.TimeoutException;
|
|||
@Slf4j
|
||||
public class ExecutePyUtils {
|
||||
|
||||
private static final int PROCESS_TIMEOUT_SECONDS = 3600; // 30分钟超时
|
||||
private static final int PROCESS_TIMEOUT_SECONDS = 36000;
|
||||
/**
|
||||
* 执行Python进程
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
|
|||
List<String> windSpeedList = new ArrayList<>();
|
||||
|
||||
// 获取网格索引
|
||||
int[] gridIndex = getGridIndex(latitude, longitude);
|
||||
int[] gridIndex = null;
|
||||
int hourInterval = 6;
|
||||
|
||||
// 循环处理每个时间点的数据
|
||||
|
|
@ -175,6 +175,9 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
|
|||
String filePath = getWeatherFilePath(weatherDataList, currentTime);
|
||||
if (isFileValid(filePath)) {
|
||||
try {
|
||||
if(null == gridIndex){
|
||||
gridIndex = getGridIndex(latitude, longitude, filePath);
|
||||
}
|
||||
processCommonData(filePath, gridIndex, currentTime, timeList, temperatureList,
|
||||
pressureList, humidityList, windSpeedList, dataType);
|
||||
} catch (Exception e) {
|
||||
|
|
@ -250,7 +253,7 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
|
|||
throw new IllegalArgumentException("时间范围内没有气象数据");
|
||||
}
|
||||
|
||||
int[] gridIndex = getGridIndex(latitude, longitude);
|
||||
int[] gridIndex = null;
|
||||
Map<String, String> variables = getVariableNames(dataType);
|
||||
List<Double> uValues = new ArrayList<>();
|
||||
List<Double> vValues = new ArrayList<>();
|
||||
|
|
@ -263,6 +266,9 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
|
|||
String filePath = getWeatherFilePath(weatherDataList, currentTime);
|
||||
|
||||
if (isFileValid(filePath)) {
|
||||
if(null == gridIndex){
|
||||
gridIndex = getGridIndex(latitude, longitude, filePath);
|
||||
}
|
||||
try (NetcdfFile ncFile = NetcdfFile.open(filePath)) {
|
||||
uValues.add(getNcValueByIndex(ncFile, variables.get("windU"), gridIndex[0], gridIndex[1]));
|
||||
vValues.add(getNcValueByIndex(ncFile, variables.get("windV"), gridIndex[0], gridIndex[1]));
|
||||
|
|
@ -1106,18 +1112,29 @@ public class WeatherDataServiceImpl extends ServiceImpl<WeatherDataMapper, Weath
|
|||
* @param longitude 经度(-180到180)
|
||||
* @return 包含纬度和经度下标的数组 [latIndex, lonIndex]
|
||||
*/
|
||||
public static int[] getGridIndex(double latitude, double longitude) {
|
||||
// 计算纬度下标 (从北到南)
|
||||
double latStep = (LAT_START - LAT_END) / (LAT_SIZE - 1);
|
||||
int latIndex = (int) Math.round((LAT_START - latitude) / latStep);
|
||||
latIndex = Math.max(0, Math.min(latIndex, LAT_SIZE - 1));
|
||||
public static int[] getGridIndex(double latitude, double longitude, String filePath) {
|
||||
|
||||
// 计算经度下标 (从西到东)
|
||||
double lonStep = (LON_END - LON_START) / (LON_SIZE - 1);
|
||||
int lonIndex = (int) Math.round((longitude - LON_START) / lonStep);
|
||||
lonIndex = Math.max(0, Math.min(lonIndex, LON_SIZE - 1));
|
||||
try (NetcdfFile ncFile = NetcdfFile.open(filePath)) {
|
||||
Integer lat = ncFile.findDimension("lat").getLength();
|
||||
Integer lon = ncFile.findDimension("lon").getLength();
|
||||
|
||||
return new int[]{latIndex, lonIndex};
|
||||
Integer latSize = lat < LAT_SIZE ? LAT_SIZE_181 : LAT_SIZE;
|
||||
Integer lonSize = lon < LON_SIZE ? LON_SIZE_360 : LON_SIZE;
|
||||
|
||||
// 计算纬度下标 (从北到南)
|
||||
double latStep = (LAT_START - LAT_END) / (latSize - 1);
|
||||
int latIndex = (int) Math.round((LAT_START - latitude) / latStep);
|
||||
latIndex = Math.max(0, Math.min(latIndex, latSize - 1));
|
||||
|
||||
// 计算经度下标 (从西到东)
|
||||
double lonStep = (LON_END - LON_START) / (lonSize - 1);
|
||||
int lonIndex = (int) Math.round((longitude - LON_START) / lonStep);
|
||||
lonIndex = Math.max(0, Math.min(lonIndex, lonSize - 1));
|
||||
|
||||
return new int[]{latIndex, lonIndex};
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user