根据数据最后一个字段正负判断方向,增加字段进行区分方向的不同!? 40C

数据格式如下:
432417e51e7d340a,2018-02-07 09:20:52,120.707309,30.633297,0.0
432417e51e7d340a,2018-02-07 09:25:55,120.71122,30.64435,1.2861781
432417e51e7d340a,2018-02-07 09:26:53,120.707309,30.633297,-1.2861781
432417e51e7d340a,2018-02-07 09:28:27,120.70445,30.63925,0.7170383
432417e51e7d340a,2018-02-07 09:32:21,120.707309,30.633297,-0.7170383
432417e51e7d340a,2018-02-07 09:37:07,120.70445,30.63925,0.7170383
432417e51e7d340a,2018-02-07 09:38:59,120.707309,30.633297,-0.7170383
432417e51e7d340a,2018-02-07 09:40:33,120.707309,30.633297,0.0
432417e51e7d340a,2018-02-07 09:41:17,120.70445,30.63925,0.7170383
432417e51e7d340a,2018-02-07 09:41:58,120.707309,30.633297,-0.7170383
432417e51e7d340a,2018-02-07 09:44:00,120.70445,30.63925,0.7170383
432417e51e7d340a,2018-02-07 09:47:12,120.71122,30.64435,0.56913984
432417e51e7d340a,2018-02-07 09:47:52,120.707309,30.633297,-1.2861781
432417e51e7d340a,2018-02-07 09:49:51,120.715865,30.64935,1.9659712
432417e51e7d340a,2018-02-07 10:09:32,120.72743,30.64796,0.559644
432417e51e7d340a,2018-02-07 10:13:45,120.78822,30.678701,6.7269063
432417e51e7d340a,2018-02-07 10:15:35,120.817392,30.696594,3.4293442
432417e51e7d340a,2018-02-07 10:24:30,120.83463,30.72041,2.899088
432417e51e7d340a,2018-02-07 10:27:14,120.82615,30.70921,-1.4039326
432417e51e7d340a,2018-02-07 10:32:32,120.81779,30.70191,-1.1261663
432417e51e7d340a,2018-02-07 10:34:57,120.83463,30.72041,2.530099
432417e51e7d340a,2018-02-07 10:36:56,120.83463,30.72041,0.0
432417e51e7d340a,2018-02-07 10:37:49,120.84623,30.72688,1.3184185
432417e51e7d340a,2018-02-07 10:38:28,120.852487,30.734512,0.99814034
432417e51e7d340a,2018-02-07 10:39:45,120.86842,30.73819,1.4541836
432417e51e7d340a,2018-02-07 10:40:57,120.853132,30.745325,-0.6269398
432417e51e7d340a,2018-02-07 10:45:49,120.79159,30.691897,-8.345741
432417e51e7d340a,2018-02-07 10:55:17,120.70348,30.64357,-9.178058
432417e51e7d340a,2018-02-07 10:59:44,120.6837,30.63107,1.073965
结果文件格式:
432417e51e7d340a,2018-02-07 09:20:52,120.707309,30.633297,0.0,1
432417e51e7d340a,2018-02-07 09:25:55,120.71122,30.64435,1.2861781,1
432417e51e7d340a,2018-02-07 09:26:53,120.707309,30.633297,-1.2861781,1
432417e51e7d340a,2018-02-07 09:28:27,120.70445,30.63925,0.7170383,1
432417e51e7d340a,2018-02-07 09:32:21,120.707309,30.633297,-0.7170383,1
432417e51e7d340a,2018-02-07 09:37:07,120.70445,30.63925,0.7170383,1
432417e51e7d340a,2018-02-07 09:38:59,120.707309,30.633297,-0.7170383,1
432417e51e7d340a,2018-02-07 09:40:33,120.707309,30.633297,0.0,1
432417e51e7d340a,2018-02-07 09:41:17,120.70445,30.63925,0.7170383,1
432417e51e7d340a,2018-02-07 09:41:58,120.707309,30.633297,-0.7170383,1
432417e51e7d340a,2018-02-07 09:44:00,120.70445,30.63925,0.7170383,1
432417e51e7d340a,2018-02-07 09:47:12,120.71122,30.64435,0.56913984,1
432417e51e7d340a,2018-02-07 09:47:52,120.707309,30.633297,-1.2861781,1
432417e51e7d340a,2018-02-07 09:49:51,120.715865,30.64935,1.9659712,1
432417e51e7d340a,2018-02-07 10:09:32,120.72743,30.64796,0.559644,1
432417e51e7d340a,2018-02-07 10:13:45,120.78822,30.678701,6.7269063,1
432417e51e7d340a,2018-02-07 10:15:35,120.817392,30.696594,3.4293442,1
432417e51e7d340a,2018-02-07 10:24:30,120.83463,30.72041,2.899088,1
432417e51e7d340a,2018-02-07 10:27:14,120.82615,30.70921,-1.4039326,2
432417e51e7d340a,2018-02-07 10:32:32,120.81779,30.70191,-1.1261663,2
432417e51e7d340a,2018-02-07 10:34:57,120.83463,30.72041,2.530099,3
432417e51e7d340a,2018-02-07 10:36:56,120.83463,30.72041,0.0,3
432417e51e7d340a,2018-02-07 10:37:49,120.84623,30.72688,1.3184185,3
432417e51e7d340a,2018-02-07 10:38:28,120.852487,30.734512,0.99814034,3
432417e51e7d340a,2018-02-07 10:39:45,120.86842,30.73819,1.4541836,3
432417e51e7d340a,2018-02-07 10:40:57,120.853132,30.745325,-0.6269398,4
432417e51e7d340a,2018-02-07 10:45:49,120.79159,30.691897,-8.345741,4
432417e51e7d340a,2018-02-07 10:55:17,120.70348,30.64357,-9.178058,4
432417e51e7d340a,2018-02-07 10:59:44,120.6837,30.63107,1.073965,4
字段分别是:用户id,时间,经纬度,行驶距离(正负表示方向),若该用户行驶距离字段连续出现两个相同符号,则该用户行驶方向发生改变。
(若行驶距离字段符号为0按大于零处理)

0

2个回答

最后的方向是相对于初始经纬度的方向吧,那就直接比较经纬度就行了啊

0

int sign = 0;
if (Float.valueOf(s3[4]) >= 0){
sign = 1;
}else {
sign = -1;
}
s3[5] = new String("1");
//System.out.println(s3[5]);
int count1 = 1;

    for (int i = 0;i < str.length-1;i++){
        String[] s1 = str[i].split(",");
        String[] s2 = str[i+1].split(",");
        if (!s1[0].equals(temp)){
            temp = s1[0];
            s1[5] = String.valueOf(1);
            if (Float.valueOf(s3[4]) >= 0){
                sign = 1;
            }else {
                sign = -1;
            }
            count1 = 1;
            System.out.println(s1[0] + "," + s1[1] + "," + s1[2] + "," + s1[3] + "," + s1[4] + "," + s1[5]);
            writer.write(s1[0] + "," + s1[1] + "," + s1[2] + "," + s1[3] + "," + s1[4] + "," + s1[5] + "\r\n");
        }else if (s1[0].equals(temp) && s2[0].equals(temp)){
            if (Float.valueOf(s1[4]) >= 0 && Float.valueOf(s2[4]) >= 0 && sign == -1){
                count1+=1;
                s1[5] = String.valueOf(count1);
                sign = 1;
                System.out.println(s1[0] + "," + s1[1] + "," + s1[2] + "," + s1[3] + "," + s1[4] + "," + s1[5]);
                writer.write(s1[0] + "," + s1[1] + "," + s1[2] + "," + s1[3] + "," + s1[4] + "," + s1[5] + "\r\n");
            }else if (Float.valueOf(s1[4]) < 0 && Float.valueOf(s2[4]) < 0 && sign == 1){
                count1+=1;
                s1[5] = String.valueOf(count1);
                sign = -1;
                System.out.println(s1[0] + "," + s1[1] + "," + s1[2] + "," + s1[3] + "," + s1[4] + "," + s1[5]);
                writer.write(s1[0] + "," + s1[1] + "," + s1[2] + "," + s1[3] + "," + s1[4] + "," + s1[5] + "\r\n");
            }else {
                s1[5] = String.valueOf(count1);
                System.out.println(s1[0] + "," + s1[1] + "," + s1[2] + "," + s1[3] + "," + s1[4] + "," + s1[5]);
                writer.write(s1[0] + "," + s1[1] + "," + s1[2] + "," + s1[3] + "," + s1[4] + "," + s1[5] + "\r\n");
            }
        }else if (s1[0].equals(temp) && !s2[0].equals(temp)){
            s1[5] = String.valueOf(count1);
            count1 = 1;
            System.out.println(s1[0] + "," + s1[1] + "," + s1[2] + "," + s1[3] + "," + s1[4] + "," + s1[5]);
            writer.write(s1[0] + "," + s1[1] + "," + s1[2] + "," + s1[3] + "," + s1[4] + "," + s1[5] + "\r\n");
        }

// else if (s1[0].equals(temp) && s2[0].equals(temp) && !s1[8].equals(s2[8])){
//
// }
}

0
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!