Page 1 of 2

Xserver Internet APIs with MatLab

Posted: Wed Jan 25, 2017 10:16 am
by g.fiume
Hi to everyone, I'm a student of the Polytechnic of Bari. I'm trying to make a simple program using Matlab and Xserver Internet APIs.
I'm having problems finding resources for json requests with xroute.
With xlocate I've found an example that was really useful and with that I was able to make this simple program:

Code: Select all

token = '';
url = 'https://xlocate-eu-n-test.cloud.ptvgroup.com/xlocate/rs/XLocate/findAddress';
addr = struct('country' , 'i','city', '', 'postCode', '', 'street', '');
data = struct('addr', addr);
options = weboptions('MediaType', 'application/json', 'Username', 'xtok', 'Password', token);
response = webwrite(url, data, options);
The aim of reasearch is to find the best route from bari to torino and comparing the various scenarios that may arise (traffic, closed roads etc).

Thank you in advance anyone who can help me out
Gianni

Re: Xserver Internet APIs with MatLab

Posted: Wed Jan 25, 2017 11:58 am
by Marco
Hi Gianni,
Thank you for using PTV xServer Internet.
To get some plain JSON request samples, you will find templates at the PTV xServer RawRequestRunner.
For your different scenarios, please have a look to our technology PTV xServer Feature Layer. You will find a YouTube tutorial here and on this page you see all available content for xServer Internet . Further check our GitHub project fl-labs. This sample is written in JavaScript, sent it's requests as JSON and demonstrates the FeatureLayer technology with routing samples.

Let me know, if you have some further questions.

Marco

Re: Xserver Internet APIs with MatLab

Posted: Thu Jan 26, 2017 12:27 pm
by g.fiume
Thank you so much. your reply was really helpful.
Now I'm trying to use xroute api.
Is this url (https://xroute-eu-n-test.cloud.ptvgroup ... ulateRoute) correct to calculate the route between two points?
I'm having back error 500.

Thank you again

Re: Xserver Internet APIs with MatLab

Posted: Thu Jan 26, 2017 12:31 pm
by Bernd Welter
Hello Gianni,

from my perspective: yes, the URL is ok.
But: you need a token to comsume the cloud services. Therefore you have to register for a trial period.

Depending on the required output of the route it might be necessary to access another method:
  • If you only need driving time and driving distance: calculateRouteInfo
  • If you need additional info such as polyon points or detailed segment data: calculateRoute
  • If you need further info such as international toll : calculateExtendedRoute
Best regards
Bernd

Re: Xserver Internet APIs with MatLab

Posted: Thu Jan 26, 2017 1:14 pm
by Marco
Do you see the response content from xServer xRoute service? Normally you schould get an error message, which help you to find the error. If you don't get it with MathLab, have a look to this tutorial.

http://xserver.ptvgroup.com/de/cookbook ... k-fiddler/

Re: Xserver Internet APIs with MatLab

Posted: Fri Jan 27, 2017 8:33 am
by g.fiume
Finally I've found the problem: Matlab has some problems in managing json files. Now I think that I've solved.

Thank you a lot for your help.

Re: Xserver Internet APIs with MatLab

Posted: Tue Jan 31, 2017 12:30 pm
by g.fiume
Hello again, first of all thanks for all previous helps. Now I'm trying to compare different routes, but I can't figure out how to request this to PTV Xserver.
It's easy to request a route from point a to b, but I haven't found yet a command to receive different choices, the only command that I've found is exeptionpath. Is this the only way to calculate different routes?

Thanks, have a good day

Re: Xserver Internet APIs with MatLab

Posted: Tue Jan 31, 2017 1:36 pm
by Marco
Hi, there are a lot of options, which affect different route results. Depending on what you want to consider. Have a look to PTV xRoute Use Case documentation, it cover a lot of scenarios.

As example, have a look to this request. It routes inside of Karlsruhe Germany and considers live traffic incidents (with PTV Traffic Incidents Feature Layer) for calculating.

Code: Select all

{
	"waypoints": [{
			"coords": [{
					"point": {
						"x": 8.37922,
						"y": 49.01502
					}
				}
			],
			"linkType": "NEXT_SEGMENT"
		}, {
			"coords": [{
					"point": {
						"x": 8.42806,
						"y": 49.01328
					}
				}
			],
			"linkType": "NEXT_SEGMENT"
		}
	],
	"options": [{
			"parameter": "START_TIME",
			"value": "2017-01-31T14:45:24+01:00"
		}, {
			"parameter": "DYNAMIC_TIME_ON_STATICROUTE",
			"value": true
		}, {
			"parameter": "ROUTE_LANGUAGE",
			"value": "EN"
		}
	],
	"details": {
		"detailLevel": "STANDARD",
		"polygon": true,
		"manoeuvres": true,
		"segments": true
	},
	"callerContext": {
		"properties": [{
				"key": "CoordFormat",
				"value": "OG_GEODECIMAL"
			}, {
				"key": "ProfileXMLSnippet",
				"value": "<Profile xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><FeatureLayer majorVersion=\"1\" minorVersion=\"0\"><GlobalSettings enableTimeDependency=\"true\"/><Themes><Theme id=\"PTV_RestrictionZones\" enabled=\"false\" priorityLevel=\"0\"></Theme><Theme id=\"PTV_SpeedPatterns\" enabled=\"false\" priorityLevel=\"0\"/><Theme id=\"PTV_TrafficIncidents\" enabled=\"true\" priorityLevel=\"0\"/><Theme id=\"PTV_TruckAttributes\" enabled=\"false\" priorityLevel=\"0\"/><Theme id=\"PTV_TimeZones\" enabled=\"true\" priorityLevel=\"0\"/></Themes></FeatureLayer><Routing majorVersion=\"2\" minorVersion=\"0\"><Course><AdditionalDataRules enabled=\"true\"/></Course></Routing></Profile>"
			}, {
				"key": "Profile",
				"value": "carfast"
			}
		]
	}
}

Regards

Re: Xserver Internet APIs with MatLab

Posted: Tue Jan 31, 2017 3:12 pm
by g.fiume
It routes inside of Karlsruhe Germany and considers live traffic incidents (with PTV Traffic Incidents Feature Layer) for calculating.
If I've understood correctly, this request gives me one route as response, the response changes depending on traffic condition in a specific time.
But what I'm looking for is a response with 2 or 3 different routes given after only one request.

Thank you again

Re: Xserver Internet APIs with MatLab

Posted: Tue Jan 31, 2017 3:16 pm
by Marco
You have to send one request for each scenario.