From b5e2f02b3a6cff003def0776837e7c4ef7cb0527 Mon Sep 17 00:00:00 2001 From: wanggeng <450292408@qq.com> Date: Sun, 9 Jan 2022 15:42:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BD=91=E6=A0=BC=E5=9D=90?= =?UTF-8?q?=E6=A0=87=E8=BD=AC=E6=8D=A2test=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SmartCityUsercenterApplicationTests.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/test/java/cn/com/tenlion/usercenter/SmartCityUsercenterApplicationTests.java b/src/test/java/cn/com/tenlion/usercenter/SmartCityUsercenterApplicationTests.java index 909c8b0..d20a70a 100644 --- a/src/test/java/cn/com/tenlion/usercenter/SmartCityUsercenterApplicationTests.java +++ b/src/test/java/cn/com/tenlion/usercenter/SmartCityUsercenterApplicationTests.java @@ -2,6 +2,9 @@ package cn.com.tenlion.usercenter; import cn.com.tenlion.usercenter.pojo.dtos.userexpand.UserExpandDTO; import cn.com.tenlion.usercenter.service.userexpand.IUserExpandService; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import ink.wgink.util.LatLngTransformUtil; import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -9,6 +12,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import java.io.*; import java.util.ArrayList; import java.util.List; @@ -30,4 +34,46 @@ class SmartCityUsercenterApplicationTests { } } + public static void main(String[] args) throws IOException { + String baseDir = "/Users/wanggeng/Desktop/"; + BufferedReader bufferedReader = new BufferedReader(new FileReader(new File(baseDir + "/gridPoint.json"))); + StringBuilder sourceJsonArraySB = new StringBuilder(); + for (String line; (line = bufferedReader.readLine()) != null; ) { + sourceJsonArraySB.append(line); + } + JSONArray sourceJsonArray = JSONArray.parseArray(sourceJsonArraySB.toString()); + JSONArray map84GridJsonArray = new JSONArray(); + // 遍历 + for (int i = 0; i < sourceJsonArray.size(); i++) { + JSONObject gridJSONObject = sourceJsonArray.getJSONObject(i); + JSONObject map84GridJSONObject = new JSONObject(); + map84GridJSONObject.put("areaCode", gridJSONObject.getString("areaCode")); + map84GridJSONObject.put("areaName", gridJSONObject.getString("areaName")); + map84GridJSONObject.put("fillColor", gridJSONObject.getString("fillColor")); + map84GridJSONObject.put("gridCode", gridJSONObject.getString("gridCode")); + map84GridJSONObject.put("gridName", gridJSONObject.getString("gridName")); + map84GridJSONObject.put("gridId", gridJSONObject.getString("gridId")); + + JSONArray pointArray = gridJSONObject.getJSONArray("pointArray"); + JSONArray map84PointArray = new JSONArray(); + for (int j = 0; j < pointArray.size(); j++) { + JSONObject point = pointArray.getJSONObject(j); + double lat = point.getDoubleValue("lat"); + double lng = point.getDoubleValue("lng"); + double[] latLng = LatLngTransformUtil.bd09_To_gps84(lat, lng); + + JSONObject map84Point = new JSONObject(); + map84Point.put("lat", String.valueOf(latLng[0])); + map84Point.put("lng", String.valueOf(latLng[1])); + map84PointArray.add(map84Point); + } + + map84GridJSONObject.put("pointArray", map84PointArray); + + map84GridJsonArray.add(map84GridJSONObject); + } + StringBuilder sb = new StringBuilder(map84GridJsonArray.toJSONString()); + System.out.println(sb); + } + }