预处理处理浮动车数据的习惯是
- 按照车牌或者日期+车牌分割原始数据
- 从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