Background
I have a huge dataset consisting of points (on a plane) together with a timestamp for each point. This is a collection of car GPS measures, giving us the location (latitude/longitude) of some car and the time at which that car was there.
I would like to store the time-series’ information on a grid. That is, I have a rectangular grid, and for each cell, I would like to have a list of the dates at which there was a GPS signal in the cell. So, in the end I would like the data to be a 2 by 2 matrix of lists. Each element of the matrix representing a cell of the grid and the attached list would contain the dates at which there was a signal in that cell.
This would be the ideal data representation for the time-series analysis I will have to perform.
Problem
The dataset is huge. So I would like to be more memory-efficient. The main point to consider is the following:
- Since I’m using a regular rectangular grid and GPS signal is confined to cells containing roads, most of the cells will be “unactivated”, i.e most of the elements of the matrix will store an empty list (no signal).
Attempt
The above remark suggests that the spatial information could be stored into a list, instead of a matrix.
We would iterate over the dataset, for each measure look if the corresponding cell already exists in the list, and if not append a new cell to the list of activated cells.
This approach has two drawbacks compared to the matrix-based one:
Computational overhead: For each datapoint, we have to search a whole list to determine if the cell it belongs to is already in the list. In the matrix approach, we can easily determine the index of the corresponding element, given the coordinates of the point and the resolution of the grid.
Loss of spatial information: In the matrix approach, it is simple to change the resolution of the grid, or perform nearest neighbor based operations. The list aproach completely dumps all spatial information.
In both cases, the matrix approach has $\mathcal{O}(1)$ complexity, whereas the list one has $\mathcal{O}(n)$ complexity.
Question
I would thus like to be able to find a representation which doesn’t need to store empty cells, while at the same time retaining the advantages of the matrix representation.
P.S.: I know kdTrees would be good for nearest-neighbor search, I'm just a little concerned about the time needed to build it. Comments?