| | |
| | | package com.se.simu.service; |
| | | |
| | | import cn.hutool.core.collection.ListUtil; |
| | | import cn.hutool.core.io.FileUtil; |
| | | import cn.hutool.json.JSONArray; |
| | | import cn.hutool.json.JSONObject; |
| | |
| | | |
| | | List<GeLayer> layers = getLayers(token, db); |
| | | queryData(token, db, layers); |
| | | checkData(layers); |
| | | createShps(basePath, layers); |
| | | createZoneShp(basePath, data, db.getSpatialReference()); |
| | | if (data.getPid() > 0) { |
| | | createFloodShp(basePath, data, db.getSpatialReference()); |
| | | } |
| | | } |
| | | |
| | | private void checkData(List<GeLayer> layers) { |
| | | GeLayer point = getLayerByName(layers, config.getLayerNames().get(0)); |
| | | GeLayer line = getLayerByName(layers, config.getLayerNames().get(1)); |
| | | |
| | | List<String> bsm = getValues(point, "bsm"); |
| | | List<String> bsm2 = new ArrayList<>(bsm); |
| | | List<String> qdbsm = getValues(line, "qdbsm"); |
| | | List<String> zdbsm = getValues(line, "zdbsm"); |
| | | |
| | | bsm.removeAll(qdbsm); |
| | | bsm.removeAll(zdbsm); |
| | | qdbsm.removeAll(bsm2); |
| | | zdbsm.removeAll(bsm2); |
| | | |
| | | removeValues(point, "bsm", bsm); |
| | | removeValues(line, "qdbsm", qdbsm); |
| | | removeValues(line, "zdbsm", zdbsm); |
| | | |
| | | GeLayer juncLayer = new GeLayer(point, filterLayerData(point.getData())); |
| | | juncLayer.setName("集水点"); |
| | | juncLayer.setShpName(config.getJunctionName()); |
| | | layers.add(juncLayer); |
| | | } |
| | | |
| | | private GeLayer getLayerByName(List<GeLayer> layers, String name) { |
| | | return layers.stream().filter(a -> a.getName().equals(name)).findFirst().orElse(null); |
| | | } |
| | | |
| | | private List<String> getValues(GeLayer layer, String field) { |
| | | JSONArray data = layer.getData(); |
| | | List<String> list = new ArrayList<>(); |
| | | |
| | | int i = 0; |
| | | while (i < data.size()) { |
| | | JSONObject obj = data.getJSONObject(i).getJSONObject("properties"); |
| | | if (StringHelper.isEmpty(obj.getStr(field))) { |
| | | data.remove(i); |
| | | continue; |
| | | } |
| | | list.add(obj.getStr(field)); |
| | | i++; |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | private void removeValues(GeLayer layer, String field, List<String> values) { |
| | | if (CollectionUtils.isEmpty(values)) return; |
| | | |
| | | int i = 0; |
| | | JSONArray data = layer.getData(); |
| | | while (i < data.size()) { |
| | | JSONObject obj = data.getJSONObject(i).getJSONObject("properties"); |
| | | if (values.contains(obj.getStr(field))) { |
| | | data.remove(i); |
| | | continue; |
| | | } |
| | | i++; |
| | | } |
| | | } |
| | | |
| | |
| | | String path = basePath + File.separator + layer.getShpName(); |
| | | if (!ShpHelper.createShp(path, layer)) { |
| | | throw new Exception(layer.getName() + ",创建ShapeFile文件失败!"); |
| | | } |
| | | // 管网集水点 |
| | | if (layer.getShpName().equals(config.getShpNames().get(0))) { |
| | | GeLayer juncLayer = new GeLayer(layer, filterLayerData(layer.getData())); |
| | | if (!ShpHelper.createShp(basePath + File.separator + config.getJunctionName(), juncLayer)) { |
| | | throw new Exception("集水点" + ",创建ShapeFile文件失败!"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | private void createZoneShp(String basePath, DataPo data, SpatialReference sr) { |
| | | String filePath = basePath + File.separator + config.getZoneName(); |
| | | ShpHelper.createShp(filePath,null, sr, data.getMinx(), data.getMiny(), data.getMaxx(), data.getMaxy()); |
| | | ShpHelper.createShp(filePath, null, sr, data.getMinx(), data.getMiny(), data.getMaxx(), data.getMaxy()); |
| | | } |
| | | |
| | | private void createFloodShp(String basePath, DataPo data, SpatialReference sr) { |