燕山石化溯源三维电子沙盘-【后端】-服务
13693261870
2023-06-06 ec3e7326246b5543089b14e53275e2aca8e39f96
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package com.yssh.service.impl;
 
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
 
import org.geotools.geojson.geom.GeometryJSON;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.triangulate.DelaunayTriangulationBuilder;
import org.locationtech.jts.triangulate.VoronoiDiagramBuilder;
import org.springframework.stereotype.Service;
 
import com.yssh.dao.ExpPointMapper;
import com.yssh.entity.ExpPoint;
import com.yssh.entity.Stratum;
import com.yssh.service.IExpPointServer;
import com.yssh.utils.GisUtil;
 
import javax.annotation.Resource;
 
@Service
public class ExpPointServerImpl implements IExpPointServer {
    @Resource
    private ExpPointMapper expPointMapper;
 
    @Override
    public GeometryJSON selectList() throws IOException {
        String sourceCRS = "EPSG:4530";
        String targetCRS = "EPSG:4490";
        List<ExpPoint> list = expPointMapper.selectList();
        System.err.println(list.size());
        /*AtomicInteger i = new AtomicInteger(0);
        Coordinate[] coordinates = new Coordinate[list.size()];*/
        List<Coordinate> coordinates = new ArrayList<>();
        list.forEach(e -> {
            Coordinate transform = GisUtil.coordinateTransform(sourceCRS, targetCRS, e.getOrdinateX(), e.getAbscissaY());
            transform.setZ(e.getElevation());
            coordinates.add(transform);
        });
        
        //创建Delaunay三角网:
        DelaunayTriangulationBuilder builder = new DelaunayTriangulationBuilder();
        builder.setSites(coordinates);
        Geometry geo = builder.getEdges(new GeometryFactory());
    
        GeometryJSON geometryJson = new GeometryJSON(6);
        StringWriter writer = new StringWriter();
        geometryJson.write(geo, writer);
        System.err.println(writer.toString());
        writer.close();
        
        int numPoints = geo.getNumPoints();
        return geometryJson;
    }
 
    public List<ExpPoint> selectList2() {
        String sourceCRS = "EPSG:4530";
        String targetCRS = "EPSG:4490";
        List<ExpPoint> list = expPointMapper.selectList();
        System.err.println(list.size());
        AtomicInteger i = new AtomicInteger(0);
        Coordinate[] coordinates = new Coordinate[list.size()];
        list.forEach(e -> {
            Coordinate transform = GisUtil.coordinateTransform(sourceCRS, targetCRS, e.getOrdinateX(), e.getAbscissaY());
            transform.setZ(e.getElevation());
            coordinates[i.intValue()] = transform;
        });
        
        //创建Delaunay三角网:
        /*GeometryFactory geoFactory = new GeometryFactory();
        ConformingDelaunayTriangulationBuilder builder = new ConformingDelaunayTriangulationBuilder();
        builder.setSites(geoFactory.createMultiPointFromCoords(coordinates));*/
        GeometryFactory geoFactory = new GeometryFactory();
        VoronoiDiagramBuilder voronoiBuilder = new VoronoiDiagramBuilder();
        voronoiBuilder.setSites(geoFactory.createMultiPointFromCoords(coordinates));
        Geometry geo =voronoiBuilder.getDiagram(geoFactory);
        
        int numPoints = geo.getNumPoints();
        
        /*List<Coordinate> cs = new ArrayList<>(Arrays.asList(geo.getCoordinates()));
        cs.forEach(c -> {
            System.out.println(c.getY() + " " + c.getX() + " " + c.getZ());
        });*/
        System.out.println(numPoints);
 
        /*String text = union.toText();
        System.out.println(text);*/
        
        /*List<String> expSiteNumbers = new ArrayList<>();
        list.forEach(e -> {expSiteNumbers.add(e.getExpSiteNumber());});
        //第一层
        List<Stratum> one = stratumMapper.selectByExpSiteNumbers(expSiteNumbers);
        //1、获取一次层结构分类
        List<Stratum> geotechnicalNames = filterGeotechnicalName(one);
        //2、遍历结构分类
        geotechnicalNames.forEach(s -> {
            System.err.println(s.toString());
            Map<String, Object> param = new HashMap<>();
            param.put("expSiteNumber", s.getExpSiteNumber());
            param.put("geotechnicalName", s.getGeotechnicalName());
            param.put("start", 1);
            param.put("rows", 1);
            Stratum stratum = stratumMapper.selectByGeotechnicalName(param);
            System.err.println(stratum);
            
        });
        List<String> ess = new ArrayList<>();
        one.forEach(s -> {
            String geotechnicalName = "粉质黏土";
            if (s.getGeotechnicalName().equals(geotechnicalName)) {
                Map<String, Object> param = new HashMap<>();
                param.put("expSiteNumber", s.getExpSiteNumber());
                param.put("geotechnicalName", s.getGeotechnicalName());
                param.put("start", 1);
                param.put("rows", 1);
                Stratum stratum = stratumMapper.selectByGeotechnicalName(param);
                if (StringUtils.isNotNull(stratum)) {
                    s.setLayerDepth(stratum.getLayerDepth());
                }
                ess.add(s.getExpSiteNumber());
            }
        });
        List<ExpPoint> numbers = expPointMapper.selectByExpSiteNumbers(ess);
        numbers.forEach(e -> {
            Coordinate transform = GisUtil.coordinateTransform(sourceCRS, targetCRS, e.getOrdinateX(), e.getAbscissaY());
            one.forEach(s -> {
                if (s.getExpSiteNumber().equals(e.getExpSiteNumber())) {
                    e.setElevation(e.getElevation() - s.getLayerDepth());
                }
            });
            System.err.println("------");
            System.out.println(transform.getY() + " " + transform.getX()  + " " + e.getElevation());
        });*/
        /*Boolean flag = true;
        while (flag) {
        }*/
        
        //第二层
        /*List<Stratum> two = stratumMapper.select(e.getExpSiteNumber(), 1, 1);
        two.forEach(s -> {
            System.out.println(s.toString());
        });
        //第三层
        List<Stratum> three = stratumMapper.select(e.getExpSiteNumber(), 2, 1);
        three.forEach(s -> {
            System.err.println(s.toString());
        });
        System.out.println();*/
        
        //3、获取第二层该结构的信息
        //4、遍历第三层是满足条件的点位
        return list;
    }
    
    private List<Stratum> filterGeotechnicalName(List<Stratum> list){
        List<Stratum> result = new ArrayList<Stratum>();
        List<String> temp = new ArrayList<String>();
        list.forEach(e -> {
            String geotechnicalName = e.getGeotechnicalName();
            if (!temp.contains(geotechnicalName)) {
                result.add(e);
                temp.add(geotechnicalName);
            }
        });
        return result;
    }
}