| | |
| | | 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; |
| | |
| | | import com.se.simu.domain.dto.GeFile; |
| | | import com.se.simu.domain.dto.GeLayer; |
| | | import com.se.simu.domain.po.DataPo; |
| | | import com.se.simu.helper.CaffeineHelper; |
| | | import com.se.simu.helper.RsaHelper; |
| | | import com.se.simu.helper.ShpHelper; |
| | | import com.se.simu.helper.StringHelper; |
| | |
| | | import org.gdal.gdal.WarpOptions; |
| | | import org.gdal.gdal.gdal; |
| | | import org.gdal.gdalconst.gdalconst; |
| | | import org.gdal.ogr.Geometry; |
| | | import org.gdal.osr.SpatialReference; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | |
| | | @Resource |
| | | RestTemplate restTemplate; |
| | | |
| | | private final static String TOKEN_KEY = "gedb_token"; |
| | | |
| | | public boolean test(DataPo data) throws Exception { |
| | | createPath(config.getInPath() + File.separator + data.getInPath()); |
| | | |
| | |
| | | } |
| | | |
| | | public String getToken() throws Exception { |
| | | Object obj = CaffeineHelper.get(TOKEN_KEY); |
| | | if (obj instanceof String) { |
| | | return obj.toString(); |
| | | } |
| | | |
| | | String token = getTokenByServer(); |
| | | if (null == token) throw new Exception("获取GEDB令牌失败"); |
| | | |
| | | CaffeineHelper.put(TOKEN_KEY, token); |
| | | |
| | | return token; |
| | | } |
| | | |
| | | private String getTokenByServer() throws Exception { |
| | | Map<String, Object> map = new HashMap<>(2); |
| | | map.put("userid", config.getUser()); |
| | | map.put("password", getPassword()); |
| | | |
| | | JSONObject obj = restTemplate.postForObject(config.getHost() + "account-service/security/login", map, JSONObject.class); |
| | | log.info(obj.toString()); |
| | | |
| | | JSONObject data = obj.getJSONObject("data"); |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | public boolean queryBboxCount(String token, GeDb db, List<GeLayer> layers) { |
| | | for (GeLayer layer : layers) { |
| | | int count = getCount(token, db, layer); |
| | | if (0 == count) return false; |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | private int getCount(String token, GeDb db, GeLayer layer) { |
| | | Map<String, Object> map = new HashMap<>(6); |
| | | map.put("token", token); |
| | |
| | | |
| | | List<GeLayer> layers = getLayers(token, db); |
| | | queryData(token, db, layers); |
| | | checkData(layers); |
| | | checkData(data, db, layers); |
| | | createShps(basePath, layers); |
| | | createZoneShp(basePath, data, db.getSpatialReference()); |
| | | if (data.getPid() > 0) { |
| | |
| | | } |
| | | } |
| | | |
| | | private void checkData(List<GeLayer> layers) { |
| | | private void checkData(DataPo data, GeDb db, List<GeLayer> layers) { |
| | | GeLayer point = getLayerByName(layers, config.getLayerNames().get(0)); |
| | | GeLayer line = getLayerByName(layers, config.getLayerNames().get(1)); |
| | | GeLayer build = getLayerByName(layers, config.getLayerNames().get(2)); |
| | | |
| | | Geometry extent = ShpHelper.createPolygon(db.getSpatialReference(), data.getMinx(), data.getMiny(), data.getMaxx(), data.getMaxy()); |
| | | checkSpatialRange(extent, point); |
| | | checkSpatialRange(extent, build); |
| | | |
| | | List<String> bsm = getValues(point, "bsm"); |
| | | List<String> bsm2 = new ArrayList<>(bsm); |
| | | List<String> qdbsm = getValues(line, "qdbsm"); |
| | | List<String> qdbsm2 = new ArrayList<>(qdbsm); |
| | | List<String> zdbsm = getValues(line, "zdbsm"); |
| | | List<String> zdbsm2 = new ArrayList<>(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); |
| | | |
| | | qdbsm = getValues(line, "qdbsm"); |
| | | zdbsm = getValues(line, "zdbsm"); |
| | | bsm.removeAll(qdbsm); |
| | | bsm.removeAll(zdbsm); |
| | | removeValues(point, "bsm", bsm); |
| | | |
| | | GeLayer juncLayer = new GeLayer(point, filterLayerData(point.getData())); |
| | | juncLayer.setName("集水点"); |
| | | juncLayer.setShpName(config.getJunctionName()); |
| | | layers.add(juncLayer); |
| | | } |
| | | |
| | | private void checkSpatialRange(Geometry extent, GeLayer geLayer) { |
| | | int i = 0; |
| | | while (i < geLayer.getData().size()) { |
| | | JSONObject geom = geLayer.getData().getJSONObject(i).getJSONObject("geometry"); |
| | | Geometry g = ShpHelper.createGeometry(geLayer, geom); |
| | | g.AssignSpatialReference(extent.GetSpatialReference()); |
| | | |
| | | if (!extent.Intersects(g)) { |
| | | geLayer.getData().remove(i); |
| | | continue; |
| | | } |
| | | i++; |
| | | } |
| | | } |
| | | |
| | | private GeLayer getLayerByName(List<GeLayer> layers, String name) { |
| | |
| | | private void createShps(String basePath, List<GeLayer> layers) throws Exception { |
| | | for (GeLayer layer : layers) { |
| | | String path = basePath + File.separator + layer.getShpName(); |
| | | if (!ShpHelper.createShp(path, layer)) { |
| | | if (layer.getData().isEmpty() || !ShpHelper.createShp(path, layer)) { |
| | | throw new Exception(layer.getName() + ",创建ShapeFile文件失败!"); |
| | | } |
| | | } |