中国气象数据网API接口:http://data.cma.cn/Market/Detail/code/A.0012.0001/type/1.html
注意:需注册,注册后需一至两天审核通过。可免费试用7天。
China_SURF_Element.xls是可以采集的各种详细数据。适合研究和效果开发。
分类 | 要素编码 | 要素名称 | 单位 |
基本信息 | Station_Id_C | 区站号/观测平台标识 (字符) | |
Year | 年 | 年 | |
Mon | 月 | 月 | |
Day | 日 | 日 | |
Hour | 时次 | 时 | |
观测要素 | PRS | 气压 | 百帕 |
PRS_Sea | 海平面气压 | 百帕 | |
PRS_Max | 最高气压 | 百帕 | |
PRS_Min | 最低气压 | 百帕 | |
TEM | 温度/气温 | 摄氏度(℃) | |
TEM_Max | 最高气温 | 摄氏度(℃) | |
TEM_Min | 最低气温 | 摄氏度(℃) | |
RHU | 相对湿度 | 百分率 | |
RHU_Min | 最小相对湿度 | 百分率 | |
VAP | 水汽压 | 百帕 | |
PRE_1h | 降水量 | 毫米 | |
WIN_D_INST_Max | 极大风速的风向(角度) | 字符 | |
WIN_S_Max | 最大风速 | 米/秒 | |
WIN_D_S_Max | 最大风速的风向(角度) | 度 | |
WIN_S_Avg_2mi | 2分钟平均风速 | 米/秒 | |
WIN_D_Avg_2mi | 2分钟平均风向(角度) | 度 | |
WEP_Now | 现在天气 | ||
WIN_S_Inst_Max | 极大风速 | 米/秒 | |
tigan | 体感温度 | 摄氏度(℃) | |
windpower | 风力 | ||
VIS | 水平能见度(人工) | 米 | |
CLO_Cov | 总云量 | 百分率 | |
CLO_Cov_Low | 低云量 | 百分率 | |
CLO_COV_LM | 云量(低云或中云) | 百分率 |
China_SURF_Station.xls中是全国2000多个测象站的名称、经纬度等信息。
特征值说明.docx是511中天气阴晴情况(对应接口参数WEP_Now)的说明。
可以通过接口获取数据后打印成\t格式,可以将结果直接粘贴到Excel中,自动按照表格排列。
package com.weather.select.data;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.weather.select.util.HttpUtil;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* @Author: ZhangHao
* @Description: 地点天气
* @Date: 2020/6/16 15:22
* @Version: 1.0
*/
public class PoliceWeatherDataReader {
private static PoliceWeatherDataReader ourInstance = new PoliceWeatherDataReader();
private List<PoliceWeather> policeWeatherList;
public List<PoliceWeather> getPoliceWeatherList() {
return policeWeatherList;
}
public static PoliceWeatherDataReader getInstance() {
return ourInstance;
}
private PoliceWeatherDataReader() {
initPoliceWeatherDataReader();
}
private void initPoliceWeatherDataReader() {
policeWeatherList = new ArrayList<>();
Map<String, Police> policeMap = PoliceDataReader.getInstance().getPoliceMap();
Collection<Police> policeCollection = policeMap.values();
List<Police> policeList = new ArrayList<>(policeCollection);
int policeListSize = policeList.size();
System.out.println("省\t城市\t经度\t纬度\t气压/百帕\t海平面气压/百帕\t最高气压/百帕\t最低气压/百帕\t温度/气温/摄氏度(℃)\t最高气温/摄氏度(℃)\t最低气温/摄氏度(℃)\t相对湿度/百分率\t最小相对湿度/百分率\t水汽压/百帕\t降水量/毫米\t极大风速的风向(角度)/度\t最大风速/米/秒\t最大风速的风向(角度)/度\t2分钟平均风速/米/秒\t2分钟平均风向(角度)/度\t现在天气\t极大风速/米/秒\t体感温度/摄氏度(℃)\t风力\t水平能见度(人工)/米\t总云量/百分率\t低云量/百分率\t云量(低云或中云)/百分率");
for (int policeIndex = 0; policeIndex < policeListSize; ) {
StringBuilder policeGroupStringBuilder = new StringBuilder();
// 每次查询最多支持30个站点
int policeGroupSize = 30;
int remainPoliceNumber = policeListSize - policeIndex;
if (remainPoliceNumber < 30) {
policeGroupSize = remainPoliceNumber;
}
for (int policeInGroupIndex = 0; policeInGroupIndex < policeGroupSize; policeInGroupIndex++) {
policeGroupStringBuilder.append(policeList.get(policeIndex).getId()).append(policeIndex == policeList.size() - 1 ? "" : ",");
policeIndex++;
}
String userId = "中国地面气象站逐小时观测资料API接口选购后被分配的账号";
String pwd = "中国地面气象站逐小时观测资料API接口选购后被分配的账号";
// [20200615000000,20200616000000]为时间段,注意:[20200615000000,20200615240000]是错误的
// Station_Id_C,Year,Mon,Day,Hour是默认的,不能修改
// PRE_1h表示1h降水
String httpAPI = "http://api.data.cma.cn:8090/api?userId="+userId+"&pwd="+pwd+"&dataFormat=json&interfaceId=getSurfEleByTimeRangeAndStaID&dataCode=SURF_CHN_MUL_HOR&timeRange=[20200615000000,20200616000000]&staIDs=" + policeGroupStringBuilder.toString() + "&elements=Station_Id_C,Year,Mon,Day,Hour,PRS,PRE_1h,PRS_Sea,PRS_Max,PRS_Min,TEM,TEM_Max,TEM_Min,RHU,RHU_Min,VAP,PRE_1h,WIN_D_INST_Max,WIN_S_Max,WIN_D_S_Max,WIN_S_Avg_2mi,WIN_D_Avg_2mi,WEP_Now,WIN_S_Inst_Max,tigan,windpower,VIS,CLO_Cov,CLO_Cov_Low,CLO_COV_LM";
String resultJSONString = HttpUtil.sendGet(httpAPI);
JSONObject resultJSONObject = JSONObject.parseObject(resultJSONString);
JSONArray DSJSONArray = resultJSONObject.getJSONArray("DS");
for (JSONObject pliceWeatherJSONObject : DSJSONArray.toJavaList(JSONObject.class)) {
// 取全天中12点的天气
if ("12".equals(pliceWeatherJSONObject.getString("Hour"))) {
PoliceWeather policeWeather = new PoliceWeather();
Police police = policeMap.get(pliceWeatherJSONObject.getString("Station_Id_C"));
policeWeather.setPolice(police);
Weather weather = new Weather();
weather.setPRS(Double.parseDouble(pliceWeatherJSONObject.getString("PRS")));
weather.setPRS_Sea(Double.parseDouble(pliceWeatherJSONObject.getString("PRS_Sea")));
weather.setPRS_Max(Double.parseDouble(pliceWeatherJSONObject.getString("PRS_Max")));
weather.setPRS_Min(Double.parseDouble(pliceWeatherJSONObject.getString("PRS_Min")));
weather.setTEM(Double.parseDouble(pliceWeatherJSONObject.getString("TEM")));
weather.setTEM_Max(Double.parseDouble(pliceWeatherJSONObject.getString("TEM_Max")));
weather.setTEM_Min(Double.parseDouble(pliceWeatherJSONObject.getString("TEM_Min")));
weather.setRHU(Double.parseDouble(pliceWeatherJSONObject.getString("RHU")));
weather.setRHU_Min(Double.parseDouble(pliceWeatherJSONObject.getString("RHU_Min")));
weather.setVAP(Double.parseDouble(pliceWeatherJSONObject.getString("VAP")));
weather.setPRE_1h(Double.parseDouble(pliceWeatherJSONObject.getString("PRE_1h")));
weather.setWIN_D_INST_Max(Double.parseDouble(pliceWeatherJSONObject.getString("WIN_D_INST_Max")));
weather.setWIN_S_Max(Double.parseDouble(pliceWeatherJSONObject.getString("WIN_S_Max")));
weather.setWIN_D_S_Max(Double.parseDouble(pliceWeatherJSONObject.getString("WIN_D_S_Max")));
weather.setWIN_S_Avg_2mi(Double.parseDouble(pliceWeatherJSONObject.getString("WIN_S_Avg_2mi")));
weather.setWIN_D_Avg_2mi(Double.parseDouble(pliceWeatherJSONObject.getString("WIN_D_Avg_2mi")));
weather.setWEP_Now(pliceWeatherJSONObject.getString("WEP_Now"));
weather.setWIN_S_Inst_Max(Double.parseDouble(pliceWeatherJSONObject.getString("WIN_S_Inst_Max")));
weather.setTigan(Double.parseDouble(pliceWeatherJSONObject.getString("tigan")));
weather.setWindpower(Double.parseDouble(pliceWeatherJSONObject.getString("windpower")));
weather.setVIS(Double.parseDouble(pliceWeatherJSONObject.getString("VIS")));
weather.setCLO_Cov(Double.parseDouble(pliceWeatherJSONObject.getString("CLO_Cov")));
weather.setCLO_Cov_Low(Double.parseDouble(pliceWeatherJSONObject.getString("CLO_Cov_Low")));
weather.setCLO_COV_LM(Double.parseDouble(pliceWeatherJSONObject.getString("CLO_COV_LM")));
policeWeather.setWeather(weather);
System.out.println(police.getProvince() + "\t" + police.getStation() + "\t" + police.getLongitude() + "\t" + police.getLatitude() + "\t" + weather.getPRS() + "\t" + weather.getPRS_Sea() + "\t" + weather.getPRS_Max() + "\t" + weather.getPRS_Min() + "\t" + weather.getTEM() + "\t" + weather.getTEM_Max() + "\t" + weather.getTEM_Min() + "\t" + weather.getRHU() + "\t" + weather.getRHU_Min() + "\t" + weather.getVAP() + "\t" + weather.getPRE_1h() + "\t" + weather.getWIN_D_INST_Max() + "\t" + weather.getWIN_S_Max() + "\t" + weather.getWIN_D_S_Max() + "\t" + weather.getWIN_S_Avg_2mi() + "\t" + weather.getWIN_D_Avg_2mi() + "\t" + weather.getWEP_Now() + "\t" + weather.getWIN_S_Inst_Max() + "\t" + weather.getTigan() + "\t" + weather.getWindpower() + "\t" + weather.getVIS() + "\t" + weather.getCLO_Cov() + "\t" + weather.getCLO_Cov_Low() + "\t" + weather.getCLO_COV_LM());
policeWeatherList.add(policeWeather);
}
}
}
}
public static void main(String[] args) {
PoliceWeatherDataReader.getInstance().getPoliceWeatherList();
}
}
完整工程下载:https://download.csdn.net/download/haoranhaoshi/12548292