Using OpenLDBWS to get GetDepBoardWithDetails including all the service calling stations

71 views
Skip to first unread message

Dereck Jones

unread,
Jul 11, 2021, 9:34:40 AMJul 11
to A gathering place for the Open Rail Data community
Hi All,

I am trying to pt together a script that pulls data with details which includes the calling point for the service.

I am strugging with how to get the calling points into an array which later I can use to insert into a data table.

Can anyone give me a pointer to where I am going wrong. This is what I have so far:


$OpenLDBWS = new OpenLDBWS("MY TOKEN");
$response = $OpenLDBWS->GetDepBoardWithDetails(1,"GTW",0,0,60,120);
header("Content-Type: text/plain");

print_r ($response);

if (isset($response->GetStationBoardResult->trainServices->service))
        {
       
        foreach($response->GetStationBoardResult->trainServices->service as $service)
        {
       
          $destinations = array();
          foreach($service->destination->location as $location)
          {
            $destinations[] = $location->locationName;
$desticrs[] = $location->crs;
          }
  // HERE I AM USING THE SAME CONSTRUCTION AS I HAVE FOR GETTING THE DESTINATIONS, JUST CALLING THE CALLING POINTS   
  $callingpoints = array();
          foreach($service->subsequentCallingPoints->callingPointList->callingPoint as $calling)
          {
            $callingpoints[] = $calling->locationName;
          }
  
  $recordtime = substr($response->GetStationBoardResult->generatedAt, 0, 16);
  $origin_location = $response->GetStationBoardResult->locationName;
  $origin_crs= $response->GetStationBoardResult->crs;
          $time = $service->std;
  $serviceID = $service->serviceID;
  $operator = $service->operator;
          $dest = implode($destinations);
  $dest_crs = implode($desticrs);
  $calling = implode($callingpoints);
          $plat = $service->platform;
          $est= $service->etd;
  $datetime = substr($recordtime, 0, 16);
  $recordtime = str_replace('T',' ',$recordtime); 
  $recordtime = date("Y-m-d H:i",strtotime($recordtime));
}
}

RailAleFan

unread,
Jul 11, 2021, 10:09:33 AMJul 11
to A gathering place for the Open Rail Data community
Hi Dereck,

$service->subsequentCallingPoints->callingPointList is an array as trains can divide so there is a separate callingPointList for each portion.  The outer loop structure should be something like;

foreach($service->subsequentCallingPoints->callingPointList as $callingPointList)
{
  foreach($callingPointList as $calling)
  {
    // ...
  }
}


Gatwick Airport is a great go-to test location as it has pretty much everything;

- through services
- originating services
- terminating services
- joined arrivals (multiple origins)
- splitting departures (multiple destinations)

Cheers

Dereck Jones

unread,
Jul 11, 2021, 11:05:01 AMJul 11
to A gathering place for the Open Rail Data community
Hi, many thanks for your reply. I now have:
$callingpoints = array();
foreach($service->subsequentCallingPoints->callingPointList as $callingPointList)
{
  foreach($callingPointList as $calling)
  {
  print_r ($calling);
      $callingpoints[] = $calling->locationName;
  }
}
  print_r ($callingpoints);

print_r ($calling); produces an array which is populated with, first example:
  • [locationName] => East Croydon 
  •  [crs] => ECR 
  •  [st] => 17:08 
  •  [et] => Cancelled
if I then do "print_r ($callingpoints);" which I will use later in the script using "$calling = implode($callingpoints); "I get:

trainArray (
  •  [0] => 
  •  [1] =>
  •  [2] =>
  •  [3] =>
     )
I can't see why the "$callingpoints" array looks empty. Again any help would be great.

RailAleFan

unread,
Jul 11, 2021, 12:50:56 PMJul 11
to A gathering place for the Open Rail Data community
Hi Dereck,

My apologies $callingPointList->callingPoint is itself an array, it should be;

foreach($service->subsequentCallingPoints->callingPointList as $callingPointList)
{
  foreach($callingPointList->callingPoint as $calling)
  {
    // ...
  }
}

Cheers

Dereck Jones

unread,
Jul 11, 2021, 2:31:06 PMJul 11
to A gathering place for the Open Rail Data community
Perfect, many thanks for your time.
Reply all
Reply to author
Forward
0 new messages