| | |
| | | import com.se.simu.domain.dto.GeField; |
| | | 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.RsaHelper; |
| | | import com.se.simu.helper.ShpHelper; |
| | | import com.se.simu.helper.StringHelper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.gdal.gdal.Dataset; |
| | | import org.gdal.gdal.WarpOptions; |
| | | import org.gdal.gdal.gdal; |
| | | import org.gdal.gdalconst.gdalconst; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | |
| | | @Resource |
| | | RestTemplate restTemplate; |
| | | |
| | | public boolean test(String bbox, String taskName) throws Exception { |
| | | String token = getToken(); |
| | | public boolean test(DataPo data) throws Exception { |
| | | /*String token = getToken(); |
| | | GeDb db = getSeDb(token); |
| | | db.setBbox(bbox); |
| | | |
| | |
| | | |
| | | String filePath = inPath + File.separator + fileDb.getDbid(); |
| | | downloadFiles(token, filePath, files, fileDb.getDbid(), fileId); |
| | | clipDemFile(filePath, files, basePath, bbox); |
| | | clipDemFile(filePath, files, basePath, bbox, 4548);*/ |
| | | |
| | | String token = getToken(); |
| | | GeDb db = connectGedb(token, data); |
| | | |
| | | copeVectors(token, data, db); |
| | | |
| | | copeDem(token, data); |
| | | |
| | | return true; |
| | | } |
| | | |
| | | private void createPath(String basePath) { |
| | | File f = new File(basePath); |
| | | private void createPath(String path) { |
| | | File f = new File(path); |
| | | if (f.exists() && f.isDirectory()) { |
| | | FileUtil.del(f); |
| | | } |
| | |
| | | return data.getStr("token"); |
| | | } |
| | | |
| | | public String getPassword() throws Exception { |
| | | private String getPassword() throws Exception { |
| | | if (StringHelper.isEmpty(password)) { |
| | | String key = getPublicKey(); |
| | | RsaHelper.setPublicKey(key); |
| | |
| | | return password; |
| | | } |
| | | |
| | | public String getPublicKey() { |
| | | private String getPublicKey() { |
| | | //{"datetime":"2024-09-12 17:24:38","code":200,"data":"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCtFwJCh2taVTEi05C8qT2oG7Y+rDmJhlO4zicpSeRtiro9LsytePeWI7BXM6sfDU0WeKun1izawcfgGkZgnoJuMBluAOKI1tL0uCrR+DreNLqMVtnXHwoWEIk/hGJedDWaf3q22aGDyEB5h9qCq0JklSShP1Ih4ppap4LmgxdTPQIDAQAB"} |
| | | JSONObject obj = restTemplate.getForObject(host + "account-service/security/publickey", JSONObject.class); |
| | | |
| | | return obj.getStr("data"); |
| | | } |
| | | |
| | | public GeDb getSeDb(String token) { |
| | | public GeDb connectGedb(String token, DataPo data) { |
| | | GeDb db = getSeDb(token); |
| | | db.setBbox(data.getBbox()); |
| | | data.setEpsg(db.getEpsg()); |
| | | |
| | | return db; |
| | | } |
| | | |
| | | private GeDb getSeDb(String token) { |
| | | Map<String, Object> map = new HashMap<>(1); |
| | | map.put("token", token); |
| | | |
| | |
| | | return data.getJSONArray("features"); |
| | | } |
| | | |
| | | public void createShps(String basePath, List<GeLayer> layers) throws Exception { |
| | | public void copeVectors(String token, DataPo data, GeDb db) throws Exception { |
| | | String basePath = inPath + File.separator + data.getInPath(); |
| | | |
| | | List<GeLayer> layers = getLayers(token, db); |
| | | queryData(token, db, layers); |
| | | createShps(basePath, layers); |
| | | } |
| | | |
| | | private void createShps(String basePath, List<GeLayer> layers) throws Exception { |
| | | for (GeLayer layer : layers) { |
| | | String path = String.format("%s\\%s.shp", basePath, layer.getShpName()); |
| | | if (!ShpHelper.createShp(path, layer)) { |
| | |
| | | } |
| | | } |
| | | |
| | | public GeDb getFileDb(String token) { |
| | | public void copeDem(String token, DataPo data) throws Exception { |
| | | GeDb fileDb = getFileDb(token); |
| | | String fileId = getFileId(token, fileDb.getDbid()); |
| | | List<GeFile> files = getFileNames(token, fileDb.getDbid(), fileId); |
| | | |
| | | String filePath = inPath + File.separator + fileDb.getDbid(); |
| | | downloadFiles(token, filePath, files, fileDb.getDbid(), fileId); |
| | | clipDemFile(filePath, files, data); |
| | | } |
| | | |
| | | private GeDb getFileDb(String token) { |
| | | String uri = String.format("%sfile-service/docdb/query/canview?token=%s", host, token); |
| | | JSONObject obj = restTemplate.getForObject(uri, JSONObject.class); |
| | | JSONArray data = obj.getJSONArray("data"); |
| | |
| | | return list.stream().filter(db -> null != db.getName() && db.getName().contains(dbName)).findFirst().orElse(null); |
| | | } |
| | | |
| | | public String getFileId(String token, String dbid) { |
| | | private String getFileId(String token, String dbid) { |
| | | String uri = String.format("%sfile-service/doc/catagory/file/query?token=%s&dbid=%s&catagory=%s&count=%d&start=%d&like=", |
| | | host, token, dbid, "image", 9999, 1); |
| | | |
| | |
| | | return null; |
| | | } |
| | | |
| | | public List<GeFile> getFileNames(String token, String dbid, String fileId) { |
| | | private List<GeFile> getFileNames(String token, String dbid, String fileId) { |
| | | String uri = String.format("%sfile-service/doc/cluster/struct/list?token=%s&dbid=%s&cluster_fileid=%s&onlychild=true&folder_stairs=", |
| | | host, token, dbid, fileId); |
| | | |
| | |
| | | return JSONUtil.toList(data, GeFile.class); |
| | | } |
| | | |
| | | public void downloadFiles(String token, String path, List<GeFile> files, String dbid, String fileId) throws IOException { |
| | | private void downloadFiles(String token, String path, List<GeFile> files, String dbid, String fileId) throws IOException { |
| | | File f = new File(path); |
| | | if (!f.exists() || !f.isDirectory()) { |
| | | f.mkdirs(); |
| | |
| | | is.close(); |
| | | } |
| | | |
| | | private void clipDemFile(String filePath, List<GeFile> files, String basePath, String bbox) throws Exception { |
| | | String target = basePath + File.separator + demName; |
| | | private void clipDemFile(String filePath, List<GeFile> files, DataPo data) throws Exception { |
| | | String target = inPath + File.separator + data.getInPath() + File.separator + demFile; |
| | | for (GeFile file : files) { |
| | | if (file.getName().toLowerCase().endsWith(demType)) { |
| | | String source = filePath + File.separator + file.getName(); |
| | | clipDem(source, target, bbox); |
| | | clipDem(source, target, data); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void clipDem(String source, String target, String bbox) throws Exception { |
| | | private void clipDem(String source, String target, DataPo data) throws Exception { |
| | | Dataset ds = null; |
| | | try { |
| | | ds = gdal.Open(source, gdalconst.GA_ReadOnly); |
| | | if (null == ds || ds.getRasterCount() < 1 || null == ds.GetSpatialRef()) throw new Exception("DEM数据无效"); |
| | | |
| | | // String bbox = "116.64388473935195,39.884315914604464,116.64754729082588,39.887069143903496"; |
| | | Vector<String> vector = new Vector<>(); |
| | | //vector.add("-s_srs"); |
| | | //vector.add("EPSG:" + 4326); |
| | | vector.add("-t_srs"); |
| | | vector.add("EPSG:" + data.getEpsg()); |
| | | vector.add("-r"); |
| | | vector.add("bilinear"); |
| | | vector.add("-of"); |
| | | vector.add("GTiff"); |
| | | vector.add("-te"); |
| | | vector.add(data.getMinx().toString()); |
| | | vector.add(data.getMiny().toString()); |
| | | vector.add(data.getMaxx().toString()); |
| | | vector.add(data.getMaxy().toString()); |
| | | vector.add("-te_srs"); |
| | | vector.add("EPSG:" + 4326); |
| | | WarpOptions warpOptions = new WarpOptions(vector); |
| | | |
| | | // gdalwarp -ot UInt16 -s_srs EPSG:4326 -t_srs EPSG:2382 -r bilinear -of GTiff -te 116.526854182 40.0481829856 116.532848182 40.0541769856 |
| | | // -te_srs EPSG:4326 -co COMPRESS=DEFLATE -co PREDICTOR=1 -co ZLEVEL=6 -co TILED=YES -wo OPTIMIZE_SIZE=TRUE E:\GDALhomework\000002.tif E:/CSDN/warped1.tif |
| | | |
| | | Dataset destDs = gdal.Warp(target, new Dataset[]{ds}, warpOptions); |
| | | destDs.delete(); |
| | | } finally { |
| | | if (null != ds) ds.delete(); |
| | | } |