地图数据包解析
Controller层代码
@PostMapping(value = "mapJson")
@ApiOperation(value = "地图数据解析",notes = "地图数据解析",httpMethod = "POST")
public Response mapJson(int num){
return new Response.Builder()
.withSuccess(mapService.mapJson(num) >0)
.build();
}
Service层代码
public int mapJson(int num){
try {
FileReader fileReader = new FileReader("C:\\Users\\Administrator\\Desktop\\new\\echarts-mapJson-master\\geometryProvince\\" + num + ".json");
BufferedReader reader = new BufferedReader(fileReader);
String line;
String data="";
while ((line = reader.readLine()) != null){
data = data + line + "\n";
}
int i1 = data.indexOf("{");
String substring = data.substring(i1);
JSONObject jsonObject = new JSONObject(substring.trim());
MapJsonPO mapJsonPO = new MapJsonPO(true);
String type = jsonObject.optString("type");
mapJsonPO.setType(type);
JSONArray features = jsonObject.optJSONArray("features");
String province ="";
int number = 0;
for (int i = 0; i < features.length(); i++) {
JSONObject jsonObject1 = features.getJSONObject(i);
String city = jsonObject1.optJSONObject("properties").optString("name");
/* String url = "https://restapi.amap.com/v3/geocode/geo?output=json&address="+ city + "&city=" + city + "&key=2f91323cf8ac462c4f3ba53d8237f0eb&radius=1000";
String str = HttpClient.doGet(url);
JSONObject jsonObject2 = new JSONObject(str);
JSONArray geocodes = jsonObject2.optJSONArray("geocodes");
province = geocodes.getJSONObject(0).optString("province");*/
MapDataPO mapDataPO = new MapDataPO();
mapDataPO.setCity(city);
mapDataPO.setProvince(province);
mapDataPO.setFeatures(jsonObject1.toString());
int result = mapDao.saveMap(mapDataPO);
number = number + result;
}
return number;
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}
dao层代码
/**
* 存储市级地图数据
* @param mapDataPO
* @return
*/
int saveMap(@Param("mapDataPO")MapDataPO mapDataPO)
mapper
<insert id="saveMap" parameterType="com.hrzn.dao.hradminpo.MapDataPO">
insert into map(province,city,features) VALUES (#{mapDataPO.province},#{mapDataPO.city},#{mapDataPO.features});
</insert>
实体类 MapDataPO
@Data
public class MapDataPO {
private String features;
private String city;
private String province;
}
[数据包链接]
https://pan.baidu.com/s/1ByaZFcy6djcqLd503Vsw9Q
提取码:4wgd