rain
2024-05-09 74d0031c16c468fa82208dbcdde4fa3766a58eeb
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
package com.dji.sample.patches.utils;
 
import com.dji.sample.patches.model.entity.LotInfo;
import org.geotools.geometry.jts.JTSFactoryFinder;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.Point;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;
 
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
 
import static com.dji.sample.patches.utils.GeoToolsUtil.getCentro;
import static com.dji.sample.patches.utils.GeoToolsUtil.getExtremePoints;
 
public class FormatConversionUtil {
    static String str = "";
    //优化Polygon格式
    public static String[] formatConversion(List<String> s) {
        String str = s.toString().trim();
        String ses = str.substring(1, str.length() - 2);
        String see = ses.replaceAll("\\[\\[\\[\\[", "((")
                .replaceAll("].\\[", " ")
                .replaceAll("]]]", "))");
        String[] arr1 = see.split("],");
        return arr1;
    }
    //优化Polygon格式
    public static String modifySpacesAndCommas(String str) {
        StringBuilder modified = new StringBuilder();
        for (char c : str.toCharArray()) {
            if (c == ' ') {
                modified.append(',');
            } else if (c == ',') {
                modified.append(' ');
            } else {
                modified.append(c);
            }
        }
        return modified.toString();
    }
    //获取Polygon的中心点,X轴和Y轴
    public static String getCentros(List<LotInfo> list) {
        List<Coordinate> centros = new ArrayList<>();
        List<List<Coordinate>> extremePoints = new ArrayList<>();
        Map<Coordinate, List<Coordinate>> points = new HashMap<>();
        list.forEach(patche -> {
            String wkt = patche.getDkfw();
            // 解析WKT字符串为多边形
            WKTReader wktReader = new WKTReader(JTSFactoryFinder.getGeometryFactory());
            Geometry polygon = null;
            try {
                polygon = wktReader.read(wkt);
            } catch (ParseException e) {
                throw new RuntimeException(e);
            }
 
            // 开始封装中心点坐标
            Coordinate coordinateCentro = getCentro(polygon);
            centros.add(coordinateCentro);
            str = coordinateCentro.toString();
            // 开始封装图斑4个航线
            List<Coordinate> coordinatePointList = getExtremePoints(polygon);
            extremePoints.add(coordinatePointList);
            points.put(coordinateCentro, coordinatePointList);
 
        });
        return str;
    }
 
}