提取浮动车OD的代码

预处理处理浮动车数据的习惯是

  • 按照车牌或者日期+车牌分割原始数据
  • 从matlab提取OD矩阵

分割

分割的程序基于c++,并且使用双线程读取加快速度

// ReadData.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include "time.h"
#include <windows.h>
#include<stdlib.h>
#include <iomanip>
#include <io.h>
#include <direct.h>

using namespace std;

HANDLE g_hEventRead;//句柄 
HANDLE g_hEventWrite;//句柄 
HANDLE g_hEventTreadEnd1;//句柄 
HANDLE g_hEventTreadEnd2;//句柄 

bool isThreadEnd1 = false;
bool isThreadEnd2 = false;
int ThreadWriteNum = 0;

ifstream fin;  
long int LineID = 0;
string  dirName = "";

DWORD  WINAPI  parseSignleLineRecordA1(LPVOID lpParameter)  
{ 
    while (true)
    {
        WaitForSingleObject(g_hEventRead,INFINITE);  
        if(fin.eof())
        {
            printf("read file have finish!\n");
            SetEvent(g_hEventRead);
            break;
        }
        string ReadLine;
        getline(fin,ReadLine);
        SetEvent(g_hEventRead);
        if(ReadLine.c_str() == NULL ||ReadLine == "")
        {
            printf("read file have finish!\n");
            break;
        }
        LineID++;
        int con[20],n=0;   //con数组记录逗号位置
        int curLineLength = ReadLine.length();
        string   INDATE,      INTIME,      CARID1,     CARID2,
                 Longitude,   Latitude,    Speed,      Satellite,
                 StateFlag,   BrakeFlag;
        string   carName;
        int dotFirstPos = ReadLine.find_first_of(',', 0);
        while(dotFirstPos != string::npos)      //行末之前
        {
            con[n]= dotFirstPos;
            n++;
            dotFirstPos = ReadLine.find_first_of(',', dotFirstPos + 1);
        }           
        if (n!=9) //不符合标准列数
        {   
            printf("%s\na bad line record.\n",ReadLine.c_str());
            continue;
        }

        else //符合标准列
        {
            INDATE = ReadLine.substr(0, con[0]);
            if (INDATE != "20170301")
            {
                printf("%s\na bad line standard.\n", ReadLine.c_str());
                continue;
            }

            INTIME = ReadLine.substr(con[0] + 1, con[1] - con[0] - 1);
            CARID1 = ReadLine.substr(con[1] + 1, con[2] - con[1] - 1); 
            CARID2 = ReadLine.substr(con[2] + 1, con[3] - con[2] - 1);
            if (CARID2.length() != 12)
            {
                printf("%s\na bad line standard.\n", ReadLine.c_str());
                continue;
            }

            Longitude = ReadL
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值