Reduction API

This API provides polygonal approximation of GPS trajectories. It supports both GET and POST request types, however, the post variant is recommended to use because trajectories typically have a large number of points that often exceed the capacity of the GET method.

Input:
URL: http://cs.uef.fi/mopsi/routes/reductionApi/api.php
Parameters: param containing a JSON description of the request.
JSON attributes:


Output:
A JSON Array with five elements, one for each reduction level. Each element contains the reduced points.

The example JavaScript code below loads a sample GPS trajectory from here and calls the POST variant of the API to perform the reduction.

						var REDUCTION_SERVER=
	"http://cs.uef.fi/mopsi/routes/reductionApi/api.php";
	
processRouteFromTxtFile("data/route.txt");

function computeReduction(route){
	var param={
		"request_type":"reduction",
		"route":route
	}
	//
	httpPost(REDUCTION_SERVER,
		"param="+JSON.stringify(param),
		processResponse);
}

function processResponse(jsonString){
	// outputing to console
	console.log(jsonString);
}

function httpPost(url, dataString, callback){
	var request = new XMLHttpRequest();
	request.open('POST', url, true);
	request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	request.onreadystatechange = function() { 
        if (request.readyState == 4 && request.status == 200){
            callback(request.responseText);
		}
    }
	request.send( dataString );
}

function processRouteFromTxtFile(file){
	httpPost(file,"",function(stringFormat){
		var route=parseRouteTxt(stringFormat);
		computeReduction(route);
	});
}

function parseRouteTxt(stringFormat){
	var points=stringFormat.split("\n");
	var route=new Array();
	for(var i = 0;i<=points.length-1;i++){
		var components=points[i].split(" ");
		route.push({
			lat:(Number)(components[0]),
			lng:(Number)(components[1]),
			time:(Number)(components[2])
		});
	}
	return route;
}