| | |
| | | @ApiOperation(value = "管点转cityjson") |
| | | @GetMapping(value = "/pointToCityJson", produces = "application/json; charset=UTF-8") |
| | | public R<String> pointToCityJson(@RequestParam("shpPath") String shpPath) throws Exception { |
| | | String path = outPath + "\\"; |
| | | String path = outPath + "\\point\\"; |
| | | List<Map<String, Object>> list = ShpReadUtils.readPointShp(shpPath); |
| | | JSONObject jsonObject = getModule("pointmodule.json"); |
| | | for (Map<String, Object> map : list |
| | |
| | | metry.put("boundaries", boundarie); |
| | | geometry.add(metry); |
| | | cityObject.put("geometry", geometry); |
| | | jsonObject.getJSONObject("CityObjects").put("UUID_"+UUID.randomUUID().toString(), cityObject); |
| | | jsonObject.getJSONObject("CityObjects").put("UUID_" + UUID.randomUUID().toString(), cityObject); |
| | | } |
| | | long times=System.currentTimeMillis(); |
| | | String pointPath=path + times + "\\管点.json"; |
| | | File dirFile=new File(path + times); |
| | | if (!dirFile.exists()){ |
| | | long times = System.currentTimeMillis(); |
| | | String pointPath = path + times + "\\管点.json"; |
| | | File dirFile = new File(path + times); |
| | | if (!dirFile.exists()) { |
| | | dirFile.mkdirs(); |
| | | } |
| | | FileWriter fileWriter = new FileWriter(pointPath); |
| | | fileWriter.write(jsonObject.toJSONString()); |
| | | fileWriter.close(); |
| | | return success(pointPath); |
| | | } |
| | | |
| | | @ApiOperation(value = "管线转cityjson") |
| | | @GetMapping(value = "/lineToCityJson", produces = "application/json; charset=UTF-8") |
| | | public R<String> lineToCityJson(@RequestParam("shpPath") String shpPath) throws Exception { |
| | | String path = outPath + "\\line\\"; |
| | | List<Map<String, Object>> list = ShpReadUtils.readPointShp(shpPath); |
| | | JSONObject jsonObject = getModule("linemodule.json"); |
| | | for (Map<String, Object> map : list |
| | | ) { |
| | | //拼装基础信息 |
| | | JSONObject cityObject = new JSONObject(); |
| | | cityObject.put("type", "+PipeLine"); |
| | | JSONObject attribute = new JSONObject(); |
| | | attribute.put("name", map.get("msfs")); |
| | | JSONArray geometry = new JSONArray(); |
| | | JSONObject metry = new JSONObject(); |
| | | metry.put("type", "MultiLineString"); |
| | | metry.put("lod", 0); |
| | | JSONArray boundarie = new JSONArray(); |
| | | JSONArray array = JSONObject.parseObject(map.get("the_geom").toString()).getJSONArray("coordinates"); |
| | | for (int i = 0; i < array.size(); i++) { |
| | | JSONObject object = JSONObject.parseObject(array.get(i).toString()); |
| | | JSONArray vertice = new JSONArray(); |
| | | //todo 未来修改坐标系 |
| | | vertice.add(object.get("x")); |
| | | vertice.add(object.get("y")); |
| | | vertice.add(0.0); |
| | | jsonObject.getJSONArray("vertices").add(vertice); |
| | | boundarie.add(jsonObject.getJSONArray("vertices").size()); |
| | | } |
| | | metry.put("boundaries", boundarie); |
| | | cityObject.put("geometry",metry); |
| | | cityObject.put("attributes",attribute); |
| | | cityObject.put("attributes", attribute); |
| | | geometry.add(metry); |
| | | jsonObject.getJSONObject("CityObjects").put("UUID_" + UUID.randomUUID().toString(), cityObject); |
| | | } |
| | | long times = System.currentTimeMillis(); |
| | | String pointPath = path + times + "\\管线.json"; |
| | | File dirFile = new File(path + times); |
| | | if (!dirFile.exists()) { |
| | | dirFile.mkdirs(); |
| | | } |
| | | FileWriter fileWriter = new FileWriter(pointPath); |