Java带括号数据进行分组

样例数据

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);

    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值