| | |
| | | package com.moon.server.service.data; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.moon.server.entity.all.StaticData; |
| | | import com.moon.server.entity.data.AnalysisResultEntity; |
| | | import com.moon.server.entity.data.MetaEntity; |
| | | import com.moon.server.entity.data.PublishEntity; |
| | | import com.moon.server.helper.GeoHelper; |
| | | import com.moon.server.helper.PathHelper; |
| | | import com.moon.server.service.all.WebSocketService; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.gdal.gdal.Band; |
| | |
| | | import javax.annotation.Resource; |
| | | import java.awt.geom.Point2D; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | rs.add(entity); |
| | | |
| | | return rs; |
| | | } |
| | | |
| | | /** |
| | | * 使用WKT查询分析,结果以消息推送 |
| | | */ |
| | | public void analysisForPost(Geometry geo, Integer size, String token) { |
| | | List<PublishEntity> pubs = publishService.selectRaster(); |
| | | if (null == pubs || pubs.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | // for (PublishEntity pub : pubs) { |
| | | pubs.parallelStream().forEach(pub -> { |
| | | try { |
| | | AnalysisResultEntity entity = new AnalysisResultEntity(token); |
| | | entity.setLayerName(pub.getName()); |
| | | |
| | | List<MetaEntity> metas = publishService.selectMetasByPubid(pub.getId()); |
| | | if (null == metas || metas.isEmpty()) { |
| | | setError(entity, "找不到发布数据"); |
| | | postInfo(entity); |
| | | return; |
| | | } |
| | | |
| | | String filePath = pathHelper.getConfig().getUploadPath() + File.separator + metas.get(0).getPath(); |
| | | File file = new File(filePath); |
| | | if (!file.exists() || file.isDirectory()) { |
| | | setError(entity, "源数据不存在"); |
| | | postInfo(entity); |
| | | return; |
| | | } |
| | | |
| | | openRaster(entity, filePath, geo, size); |
| | | postInfo(entity); |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 推送消息 |
| | | */ |
| | | private void postInfo(AnalysisResultEntity entity) throws IOException { |
| | | JSONObject map = new JSONObject(); |
| | | map.put("analysisForPost", entity); |
| | | |
| | | String json = JSONObject.toJSONString(map); |
| | | // System.out.println(json) |
| | | WebSocketService.broadCastInfo(json); |
| | | } |
| | | |
| | | /** |
| | |
| | | private List<Integer> getSamples(int start, int strip) { |
| | | List<Integer> list = new ArrayList<>(); |
| | | |
| | | double avg = 1.0 * strip / StaticData.I64; |
| | | for (int i = 0; i <= StaticData.I64; i++) { |
| | | double avg = 1.0 * strip / (StaticData.I64 - 1); |
| | | for (int i = 0; i < StaticData.I64; i++) { |
| | | list.add(start + (int) Math.ceil(avg * i)); |
| | | } |
| | | |