| | |
| | | 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); |
| | |
| | | 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) { |
| | | return layers.stream().filter(a -> a.getName().equals(name)).findFirst().orElse(null); |
| | | } |