Traffic Density
Purpose
The Traffic Stats API Traffic Density service reveals the amount of data available for an area. This service is asynchronous (a specific operation begins upon the receipt of a signal that the preceding operation has been completed).
There are two endpoints consuming two types of HTTP method requests - POST and GET.
1st request - POST
- The first one is only used to order jobs with POST requests.
- In its response the user receives a
jobId
.
2nd request - GET
- This
jobId
is used in the second endpoint with aGET
request to the check job's status. - When the job is successfully finished, the user will receive links in the response to download the results.
Using this service
There are some important notes about using this API service:
- The latitude and longitude coordinates are in EPSG4326 / WGS84 format for both input and output. Other coordinate systems are not supported.
- The current API version is 1.
- The maximum length of date range is 366 days.
- The maximum number of time sets is 24.
- Network size, calculated as the size of the convex hull of a defined geometry, cannot be greater than 20 000 km².
- As the service is asynchronous it can take a while before results are available, depending on how busy the service is. Do not repost your request multiple times if you do not get feedback within seconds. We will ensure that the results are delivered.
- At the same time you can only have 5 jobs in CALCULATIONS and SCHEDULED statuses per each developer key. When you reach this limit you can still create new jobs as they will be queued until at least one of currently running jobs is done.
Request data
HTTPS method: POST
Constants and parameters enclosed in curly brackets { } must be replaced with their values.
URL format
https://{baseURL}/traffic/trafficstats/trafficdensity/{versionNumber}?key={Your_API_Key}
curl format
curl -XPOST 'https://{baseURL}/traffic/trafficstats/trafficdensity/{versionNumber}?key={Your_API_Key}'
Required headers
Header | Value |
---|---|
|
Request parameters
The following table describes all of the parameters that can be used in a request. Required parameters must be used or the call will fail. Optional parameters may be used.
Required parameters | Description |
---|---|
| Base URL for calling the API. |
| Service version number. |
| Authorization key for access to the API. |
Request POST body example - JSON
1{2 "jobName": "Test job",3 "distanceUnit": "KILOMETERS",4 "mapVersion": "2022.12",5 "acceptMode": "AUTO",6 "network": {7 "name": "test",8 "geometry": {9 "type": "MultiPolygon",10 "coordinates": [11 [12 [13 [19.44305, 51.75612],14 [19.44992, 51.75612],15 [19.44992, 51.75947],16 [19.44305, 51.75947],17 [19.44305, 51.75612]18 ]19 ],20 [21 [22 [19.45011, 51.75789],23 [19.45687, 51.75789],24 [19.45687, 51.75946],25 [19.45011, 51.75946],26 [19.45011, 51.75789]27 ]28 ]29 ]30 },31 "timeZoneId": "Europe/Warsaw",32 "frcs": ["0", "1", "2", "3", "4", "5", "6", "7"],33 "probeSource": "ALL"34 },35 "dateRange": {36 "name": "October 2022",37 "from": "2022-10-01",38 "to": "2022-10-31",39 "exclusions": ["2022-10-06"]40 },41 "timeSets": [42 {43 "name": "Friday morning hour",44 "timeGroups": [45 {46 "days": ["FRI"],47 "times": ["7:00-8:00"]48 }49 ]50 }51 ]52}
Request POST body parameters - JSON
The following JSON parameters refer to the POST request body.
Required parameters | Description |
---|---|
| Job name. Given for the user's convenience. |
| Base unit used for distance and speed values.
|
| Network for calculations. See the Structure of network section. |
| Range of dates for calculations. See the Structure of dateRange section. |
| Time sets for calculations.
See the Structure of timeSets section. |
Optional parameters | Description |
---|---|
| What map should be used. A list of currently available maps in all Traffic
Stats API services can be checked at Available Maps. |
| Defines whether the job should be accepted manually or automatically. |
| If the average sample size for any combination of network, date range,
and time set will be lower than the given value, then the output will
not be generated, and the job will be moved into the REJECTED
state, and the user will not be charged for such report. If not
specified, the output will always be generated no matter how many
samples were available. |
Structure of network
Required parameters | Description |
---|---|
| Name of the network. |
| In which time zone all times are given. |
| Functional road classes. |
| Geometry of the network in GeoJSON format. Supported geometry types are
|
Optional parameters | Description |
---|---|
| Determines from what devices data will be used.
|
Structure of dateRange
Required parameters | Description |
---|---|
| Date range name. Given for the user's convenience. |
| The date from (inclusive). |
| The date to (inclusive). |
Optional parameters | Description |
---|---|
| List of days excluded from the date range. |
| List of days of the week to be excluded.
|
Structure of timeSets
Required parameters | Description |
---|---|
| Time set name. |
| Time groups in the time set.
|
Response data
In the response to the request a jobId
is provided, which is required for further communication about
the query. A JSON response content example:
1{2 "jobId": "677",3 "responseStatus": "OK",4 "messages": ["Job created. Processing started."]5}
Check job status
When a job has been initiated via the API request, it is possible to check the status.
Job status request
https://{baseURL}/traffic/trafficstats/status/{versionNumber}/{job_id}?key={Your_API_Key}
Job status request parameters
The below table describes all of the parameters that can be used in a request. Required parameters must be used or the call will fail. Optional parameters may be used.
Parameter | Description |
---|---|
| Base URL for calling the API. |
| Service version number. |
| The job ID. |
| Authorization key for access to the API. |
JSON response
1{2 "jobId": "{job_id}",3 "jobState": "{job_status}",4 "responseStatus": "OK"5}
Job status flow
During the process there are different stages applicable. Via the get state request you can see what the state of your job is. The following table shows the different stages of the process.
Status | Description |
---|---|
| The job is waiting for scheduling. |
| Job is scheduled for calculations. |
| Mapmatching is in progress. |
| Mapmatching is done and the job is waiting for Geobase reading. |
| Geobase reading is in progress. |
| Calculations are in progress. |
| Occurs only if manual acceptance mode was used. The results are waiting to be accepted or rejected. In this state sample summaries for the job are provided when checking the job status. |
| Calculations are done. The results are waiting to be downloaded. |
| The job stopped due to the fact that something went wrong. This can occur at any place in the flow. |
| The job is rejected. During processing it turned out that the job exceeds set limits, geometry cannot be processed (it is effectively empty because there are no roads with selected frcs or it is defined on area which is not supported), or there are less samples than required (see averageSampleSizeThreshold ). This can occur at any place in the flow. |
| The job is cancelled. The owner of the job stopped processing it. It can be done at any time before the job is processed. |
| The job is older than 2 years and all data has been removed. |
Confirming job results
When the job's state is NEED_CONFIRMATION
, then a summary URL will be available in the response.
1{2 "jobId": "{job_id}",3 "jobState": "NEED_CONFIRMATION",4 "sampleDetailsUrl": "{url_for_sample_details_file}",5 "responseStatus": "OK",6 "messages": ["For more details see: {url_for_sample_details_file}"]7}
A sample details file looks like this:
1{2 "summaries": [3 {4 "locationName": "test",5 "dateRangeName": "October 2022",6 "timeSetName": "Friday morning hour",7 "averageSampleSize": 114.93,8 "networkLength": 13.39,9 "coveredNetworkLength": 9.83,10 "distanceUnit": "KILOMETERS",11 "frcDetails": [12 {13 "frc": 0,14 "averageSampleSize": 0,15 "networkLength": 0,16 "coveredNetworkLength": 0,17 "distanceUnit": "KILOMETERS"18 },19 {20 "frc": 1,21 "averageSampleSize": 0,22 "networkLength": 0,23 "coveredNetworkLength": 0,24 "distanceUnit": "KILOMETERS"25 },26 {27 "frc": 2,28 "averageSampleSize": 0,29 "networkLength": 0,30 "coveredNetworkLength": 0,31 "distanceUnit": "KILOMETERS"32 },33 {34 "frc": 3,35 "averageSampleSize": 414.64,36 "networkLength": 2.23,37 "coveredNetworkLength": 2.23,38 "distanceUnit": "KILOMETERS"39 },40 {41 "frc": 4,42 "averageSampleSize": 127.22,43 "networkLength": 3.16,44 "coveredNetworkLength": 3.16,45 "distanceUnit": "KILOMETERS"46 },47 {48 "frc": 5,49 "averageSampleSize": 94.22,50 "networkLength": 0.79,51 "coveredNetworkLength": 0.79,52 "distanceUnit": "KILOMETERS"53 },54 {55 "frc": 6,56 "averageSampleSize": 33.15,57 "networkLength": 1.22,58 "coveredNetworkLength": 1.22,59 "distanceUnit": "KILOMETERS"60 },61 {62 "frc": 7,63 "averageSampleSize": 8.13,64 "networkLength": 5.98,65 "coveredNetworkLength": 2.43,66 "distanceUnit": "KILOMETERS"67 }68 ]69 }70 ]71}
If you wish to accept the job, make the following request:
https://{baseURL}/traffic/trafficstats/status/{versionNumber}/{job_id}/accept?key={Your_API_Key}
Otherwise reject the job with the following request:
https://{baseURL}/traffic/trafficstats/status/{versionNumber}/{job_id}/reject?key={Your_API_Key}
Response data
Final DONE response
1{2 "jobId": "{job_id}",3 "jobState": "DONE",4 "responseStatus": "OK",5 "urls": [6 "{url_for_json_result_file}",7 "{url_for_geojson_result_file}",8 "{url_for_shape_result_file}"9 ]10}
Results
Output of Traffic Density is available in the following formats:
- JSON
- GeoJSON
- SHAPE
JSON and GeoJSON results are provided in a gzip compressed format. SHAPE files are packed into zip archives. If you want to get an example of these files please click the applicable link in the preceding list.
JSON result description
Field(s) | Description |
---|---|
| From the request. |
| The job creation time. |
| Requested preference. |
| From the request
|
| From the request. |
| Data for requested network. |
Structure of timeSets
Field(s) | Description |
---|---|
| Helper reference for further use (in network.segmentResults.segmentProbeCounts). |
| From and as in the request. |
| Time ranges from the request, grouped per day of the week:
|
Structure of network
Field(s) | Description |
---|---|
| From and as in the request. |
| Version of maps used for map matching. |
| Data for each segment in given area. See the Structure of segmentResults section. |
Structure of segmentResults
Field(s) | Description |
---|---|
| Depending on the map on which job is processed it can be a MultiNet
Segment ID (optionally prefixed by |
| Depending on the map on which job is processed it can be a MultiNet-R
Segment ID (optionally prefixed by |
| Speed limit (in kmph or mph according to |
| Functional Road Class. |
| The street name. |
| The length of a segment (in meters or feet according to
|
| Geometrical shape of a segment. A list of pairs: longitude & latitude. |
| See the Structure of segmentProbeCounts section. |
Structure of segmentProbeCounts
Field | Description |
---|---|
| Reference to |
| Reference to |
| The sample size visible on the segment. These are unique vehicles traveling on segment. If several measurements are received from the same vehicle on a single segment it is only counted once in the sample size count. |