中国省市地图json数据包及解析

地图数据包解析

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

效果图

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值