月球大数据地理空间分析展示平台-【后端】-月球后台服务
13693261870
2023-12-04 aa23fdacb23b6e7e194d3e02760ab47590345205
src/main/java/com/moon/server/service/data/RasterAnalysisService.java
@@ -74,11 +74,12 @@
            return;
        }
        // for (PublishEntity pub : pubs) {
        //for (PublishEntity pub : pubs) {
        pubs.parallelStream().forEach(pub -> {
            try {
                AnalysisResultEntity entity = new AnalysisResultEntity(token);
                entity.setLayerName(pub.getName());
                entity.setUnit(pub.getUnit());
                List<MetaEntity> metas = publishService.selectMetasByPubid(pub.getId());
                if (null == metas || metas.isEmpty()) {
@@ -115,8 +116,9 @@
        String tempPath = pathHelper.getTempPath() + File.separator, guid = StringHelper.getGuid();
        String fileList = tempPath + guid + ".txt";
        FileWriter fw = new FileWriter(fileList);
        for (MetaEntity meta : metas) {
            fw.write((basePath + meta.getPath()).toCharArray());
        for (int i = 0, c = metas.size(); i < c; i++) {
            String str = (i > 0 ? "\r\n" : "") + basePath + metas.get(i).getPath();
            fw.write(str.toCharArray());
        }
        fw.close();
@@ -135,7 +137,8 @@
        map.put("analysisForPost", entity);
        String json = JSONObject.toJSONString(map);
        // System.out.println(json)
        //System.out.println(json)
        WebSocketService.broadCastInfo(json);
    }
@@ -151,26 +154,30 @@
        }
        for (PublishEntity pub : pubs) {
            AnalysisResultEntity entity = new AnalysisResultEntity();
            entity.setLayerName(pub.getName());
            try {
                AnalysisResultEntity entity = new AnalysisResultEntity();
                entity.setLayerName(pub.getName());
                entity.setUnit(pub.getUnit());
            List<MetaEntity> metas = publishService.selectMetasByPubid(pub.getId());
            if (null == metas || metas.isEmpty()) {
                setError(entity, "找不到发布数据");
                continue;
                List<MetaEntity> metas = publishService.selectMetasByPubid(pub.getId());
                if (null == metas || metas.isEmpty()) {
                    setError(entity, "找不到发布数据");
                    continue;
                }
                String filePath = getFilePath(metas);
                File file = new File(filePath);
                if (!file.exists() || file.isDirectory()) {
                    setError(entity, "源数据不存在");
                    continue;
                }
                openRaster(entity, filePath, geo, size);
                rs.add(entity);
            } catch (Exception ex) {
                log.error(ex.getMessage(), ex);
            }
            String filePath = pathHelper.getConfig().getUploadPath() + File.separator + metas.get(0).getPath();
            File file = new File(filePath);
            if (!file.exists() || file.isDirectory()) {
                setError(entity, "源数据不存在");
                continue;
            }
            openRaster(entity, filePath, geo, size);
            rs.add(entity);
        }
        return rs;
    }
@@ -251,7 +258,7 @@
            for (int j = 1; j <= bandCount; j++) {
                double[] pixelValues = new double[1];
                ds.GetRasterBand(j).ReadRaster(xPixel, yPixel, 1, 1, pixelValues);
                if (!Double.isNaN(pixelValues[0])) {
                if (isValid(pixelValues[0])) {
                    vals.add(WebHelper.round(pixelValues[0], 3));
                }
            }
@@ -309,7 +316,7 @@
            for (Integer x : xList) {
                for (Integer y : yList) {
                    ds.GetRasterBand(i).ReadRaster(x, y, 1, 1, pixelValues);
                    if (!Double.isNaN(pixelValues[0])) {
                    if (isValid(pixelValues[0])) {
                        list.add(pixelValues[0]);
                    }
                }
@@ -350,7 +357,7 @@
        List<Double> list = new ArrayList<>();
        for (double val : pixelValues) {
            if (!Double.isNaN(val)) {
            if (isValid(val)) {
                list.add(val);
            }
        }
@@ -358,6 +365,13 @@
    }
    /**
     * 值是否有效
     */
    public static boolean isValid(Double val) {
        return !Double.isNaN(val) && val > Integer.MIN_VALUE;
    }
    /**
     * 设置Band值
     */
    private void setBandVals(AnalysisResultEntity entity, List<Double> list) {