样例数据
MULTILINESTRING((108.14717299987312 35.31269599968733,108.15066099980811 35.304562999548224,108.15240500000493),(108.89001999984056 34.3659719994762,108.91189700003866 34.37176700006458,108.93370699982427 34.377753000265905),(109.303316 34.464714,109.303316 34.464713),(109.303317 34.464716,109.303316 34.464714),)
需求
需要把上面的数据分组
实现
private void assembleData(String lonLatSet, RaillineTrackVO vo) {
List<String> temp = new ArrayList<>();
//截取前面16位
String tempLonLat = lonLatSet.substring(16);
//去掉最左边和最后边的大括号
String tempLonLat2 = tempLonLat.substring(0, tempLonLat.length() - 1);
//匹配括号
Pattern pattern = Pattern.compile("(\\([^)]*?\\))");
Matcher match = pattern.matcher(tempLonLat2);
while (match.find()) {
temp.add(match.group());
}
List<List<List<BigDecimal>>> result = new ArrayList<>();
//处理数据
for (String data : temp) {
String tempData = data.substring(1, data.length() - 1);
String[] splitLonLat = tempData.split(",");
List<List<BigDecimal>> lonLatList = new ArrayList<>();
for (int i = 0; i < splitLonLat.length; i++) {
String lonLat = splitLonLat[i];
List<BigDecimal> lonLatInfo = new ArrayList<>();
String[] split = lonLat.split(" ");
lonLatInfo.add(new BigDecimal(split[0]));
lonLatInfo.add(new BigDecimal(split[1]));
lonLatList.add(lonLatInfo);
}
result.add(lonLatList);
}
vo.setLonLatInfoList(result);
}
}