# Trajectory Clustering and k-NN for Robust Privacy Preserving Spatiotemporal Databases
## 2 Materials and Methods
### System Architecture  
In this section, we briefly describe how the system, used to extract the desired datasets, operates and extracts the trajectory data points. The system architecture is based on SMaRT (Spatiotemporal Mysql ReTrieval) framework [12] and works as an expansion sub-system that produces new datasets out of sample points that are stored in a relational database. It exploits Google maps API to define trajectories between two randomly chosen points that follow road paths over a geographical area of interest. To support the above functionality, a class was created by extending the existing framework and giving the corresponding user interface. The data flow of this sub-system, as shown in Figure 1, follows a three-stage path. Before the beginning of the process, there is an initialization phase, while the database is populated with manually pre-created trajectories from a coma separated file (csv) through the importing class that is implemented on SMaRT framework. The trajectory objects \(T_{i}\) are in the form of sequential spatiotemporal points \(P_{n}\) and stored in the database as tuples of latitude, longitude, time-stamp and objid where objid is a unique identification integer number of the moving object that participates in our analysis and takes values from 1 (the first mobile object objid) to \(N\) (the \(N\)th mobile object objid). Moreover, the dimensions of latitude and longitude are transformed to the equivalent Cartesian coordinates (\(x\),\(y\)), through Mercator transformation, to efficiently calculate measures such as distance between points, velocity and angle vectors. After the initialization phase is over, a repeated procedure takes place as described below. First, two points are randomly chosen from a relational database with a significant Euclidean distance between them. Because the transformation every point is at a distance measured in meters, the distance between them is given by \(\sqrt{(x^{2}+y^{2})}\) and should be over a threshold of 10 m. This threshold is given by heuristic way and it eliminates the problem of zero velocity and angle calculations. Then, an API call (see Figure 2) is raised against Google Maps Directions API Service given the points along with route settings information. This information may contain the way in which the target object moves, as it could be pedestrian, car or bicycle, if it should follow toll roads or not, and is most helpful if the response should contain other relative routing paths beside the first proposed one. By this last attribute, trajectories can be multiplied by obtaining not only the proposed routing path but also the relative ones. This method also solves the drawback that Google service imposes, which restricts the service calls to 10 per second by introducing a slight delay time in the insertion process. Second, the API response, which contains the routing paths following the road network that connect the two points of reference, provides the information to the class that constructs the trajectory object. For each point of the trajectory, several calculations take place, such as acquiring the time-stamp \(t_{n}\) of the moving object at this specific point compared with the user defined velocity scale \(v_{n}\) and the Euclidean distance \(d_{n}\) from the previous point. In addition, the angle vector \(g_{n}\) is measured using the coordinates \((x_{n},y_{n})\) of the specific point and the next point \((x_{n+1},y_{n+1})\) of the trajectory. Because of the randomness of the chosen reference points of the API request, there is a difference between the number of points that the user provided as the trajectory multitude and the API response routing path. In case some routing path \(R_{n}\) has more points than the user defined upper limit, it is shortened by that number and the endpoint of the final trajectory object \(T_{n}\) becomes the last point in the array. In the opposite situation, the trajectory is discarded and the current thread resets its state to make a new request.