PHP code example of stormgeo / advisorcore

1. Go to this page and download the library: Download stormgeo/advisorcore library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stormgeo / advisorcore example snippets




use StormGeo\AdvisorCore\AdvisorCore;

$advisor = new AdvisorCore('<your-token>');

use StormGeo\AdvisorCore\Payloads\WeatherPayload;

$payload = new WeatherPayload([
  'localeId' => 3477,
  'variables' => ['temperature', 'precipitation']
]);

// requesting daily forecast chart image
$response = $advisor->chart->getForecastDaily($payload);

// requesting hourly forecast chart image
$response = $advisor->chart->getForecastHourly($payload);

// requesting daily observed chart image
$response = $advisor->chart->getObservedDaily($payload);

// requesting hourly observed chart image
$response = $advisor->chart->getObservedHourly($payload);

if (is_null($response->error)) {
  $file = fopen('chart.png', 'wb');
  fwrite($file, $response->data);
  fclose($file);
} else {
  print_r($response->error);
}

use StormGeo\AdvisorCore\Payloads\ClimatologyPayload;

$climatologyPayload = new ClimatologyPayload([
  'localeId' => 3477,
  'variables' => ['precipitation']
]);

// requesting daily climatology data
$response = $advisor->climatology->getDaily($climatologyPayload);

// requesting monthly climatology data
$response = $advisor->climatology->getMonthly($climatologyPayload);


if (is_null($response->error)) {
  print_r($response->data);
} else {
  print_r('Error trying to get data!');
  print_r($response->error);
}

use StormGeo\AdvisorCore\Payloads\CurrentWeatherPayload;

$payload = new CurrentWeatherPayload([
  'localeId' => 3477,
  'variables' => ['temperature', 'precipitation']
]);

$response = $advisor->currentWeather->get($payload);

if (is_null($response->error)) {
  print_r($response->data);
} else {
  print_r('Error trying to get data!');
  print_r($response->error);
}

use StormGeo\AdvisorCore\Payloads\WeatherPayload;

$payload = new WeatherPayload([
  'localeId' => 3477,
  'variables' => ['temperature', 'precipitation']
]);

// requesting daily forecast data
$response = $advisor->forecast->getDaily($payload);

// requesting hourly forecast data
$response = $advisor->forecast->getHourly($payload);

// requesting period forecast data
$response = $advisor->forecast->getPeriod($payload);

if (is_null($response->error)) {
  print_r($response->data);
} else {
  print_r('Error trying to get data!');
  print_r($response->error);
}

$response = $advisor->monitoring->getAlerts();

if (is_null($response->error)) {
  print_r($response->data);
} else {
  print_r('Error trying to get data!');
  print_r($response->error);
}

use StormGeo\AdvisorCore\Payloads\WeatherPayload;
use StormGeo\AdvisorCore\Payloads\GeometryPayload;
use StormGeo\AdvisorCore\Payloads\LightningLitePayload;
use StormGeo\AdvisorCore\Payloads\RadiusPayload;
use StormGeo\AdvisorCore\Payloads\StationPayload;

$payload = new WeatherPayload([
  'localeId' => 3477,
  'variables' => ['temperature', 'precipitation']
]);

// requesting daily observed data
$response = $advisor->observed->getDaily($payload);

// requesting hourly observed data
$response = $advisor->observed->getHourly($payload);

// requesting period observed data
$response = $advisor->observed->getPeriod($payload);


$stationPayload = new StationPayload([
  'stationId' => 'bWV0b3M6MDEyMEM5RkU6LTIzLjkzMDY4NDotNDYuNDg4NTQ4'
]);

// requesting station observed data
$response = $advisor->observed->getStationData($stationPayload);


$radiusPayload = new RadiusPayload([
  'localeId' => 3477,
  'radius' => 10000
]);

// requesting fire-focus observed data
$response = $advisor->observed->getFireFocus($radiusPayload);

// requesting lightning observed data
$response = $advisor->observed->getLightning($radiusPayload);

// requesting lightning observed details data
$response = $advisor->observed->getLightningDetails($radiusPayload);


$geometryPayload = new GeometryPayload([
  'startDate' => '2024-11-28 00:00:00',
  'endDate' => '2024-11-28 12:59:59',
  'geometry' => '{"type": "MultiPoint", "coordinates": [[-41.88, -22.74]]}'
]);

$lightningLitePayload = new LightningLitePayload([
  'startDate' => '2024-11-28 00:00:00',
  'endDate' => '2024-11-28 12:59:59',
  'geometry' => '{"type": "MultiPoint", "coordinates": [[-41.88, -22.74]]}',
  'page' => 1,
  'pageSize' => 10
]);

// requesting fire-focus observed data by geometry
$response = $advisor->observed->getFireFocusByGeometry($geometryPayload);

// requesting lightning observed data by geometry
$response = $advisor->observed->getLightningByGeometry($geometryPayload);

// requesting lightning lite observed data by geometry
$response = $advisor->observed->getLightningLite($lightningLitePayload);

if (is_null($response->error)) {
  print_r($response->data);
} else {
  print_r('Error trying to get data!');
  print_r($response->error);
}

use StormGeo\AdvisorCore\Payloads\StationsLastDataPayload;

$payload = new StationsLastDataPayload([
  'stationIds' => ['station-id-1', 'station-id-2'], // optional
  'variables' => ['temperature', 'precipitation'] // optional
]);

// requesting last data from stations
$response = $advisor->stations->getLastData($payload);

if (is_null($response->error)) {
  print_r($response->data);
} else {
  print_r('Error trying to get data!');
  print_r($response->error);
}

$payload = new PlanInfoPayload([
  'timezone' => -3  # default timezone is 0 (UTC)
]);

$payloadForRequestDetails = new RequestDetailsPayload([
  'page' => 1,
  'pageSize' => 3
]);

$localePayload = new PlanLocalePayload([
  'localeId' => 3477,
  // You can also set Latitude/Longitude or StationId instead of LocaleId
]);

// requesting plan information
$response = $advisor->plan->getInfo($payload);

// requesting access history
$response = $advisor->plan->getRequestDetails($payloadForRequestDetails);

// requesting plan locale information
$response = $advisor->plan->getLocale($localePayload);

if (is_null($response->error)) {
  print_r($response->data);
} else {
  print_r('Error trying to get data!');
  print_r($response->error);
}

// Arbitrary example on how to define a schema
$schemaPayload = [
  'identifier' => 'arbitraryIdentifier',
  'arbitraryField1' => [
    'type' => 'string',
    'r',
  'arbitraryField1' => 'some text',
];

// requesting all schemas from token
$response = $advisor->schema->getDefinition();

// requesting to upload a new schema
$response = $advisor->schema->postDefinition($schemaPayload);

// requesting to upload data to parameters from schema
$response = $advisor->schema->postParameters($parametersPayload);

if (is_null($response->error)) {
  print_r($response->data);
} else {
  print_r('Error trying to get data!');
  print_r($response->error);
}

$payload = new StaticMapPayload([
  'startDate' => '2025-07-21 00:00:00',
  'endDate' => '2025-07-25 23:59:59',
  'aggregation' => 'sum',
  'dpi' => 100,
  'title' => 'true',
  'titlevariable' => 'precipitation',
  'type' => 'periods',
  'category' => 'observed',
  'variable' => 'precipitation'
]);

$response = $advisor->staticMap->getStaticMap($payload);

if (is_null($response->error)) {
  $file = fopen('staticMap.png', 'wb');
  fwrite($file, $response->data);
  fclose($file);
} else {
  print_r('Error trying to get data!');
  print_r($response->error);
}

$payloadForListing = new StorageListPayload([
  'page' => 1,
  'pageSize' => 5
]);

$payloadForDownload = new StorageDownloadPayload([
  'fileName' => 'Example.pdf',
  'accessKey' => 'a1b2c3d4-0010'
]);

# requesting the files list
$response = $advisor->storage->listFiles($payloadForListing);

if (is_null($response->error)) {
  print_r($response->data);
} else {
  print_r("Error trying to get data!");
  print_r($response->error);
}

# downloading a file from the list
$response = $advisor->storage->downloadFile($payloadForDownload);

if (is_null($response->error)) {
  $file = fopen($payloadForDownload->fileName, 'wb');
  fwrite($file, $response->data);
  fclose($file);
} else {
  print_r("Error trying to get file!");
  print_r($response->error);
}

# downloading a file by stream
$response = $advisor->storage->downloadFileByStream($downloadPayload);

if (is_null($response->error)) {
  $file = fopen($payloadForDownload->fileName, 'wb');
  if (is_resource($response->data)) {
    stream_copy_to_stream($response->data, $file);
  } else {
    fwrite($file, $response->data);
  }
  fclose($file);
} else {
  print_r("Error trying to get file!");
  print_r($response->error);
}

use StormGeo\AdvisorCore\Payloads\TmsPayload;

$payload = new TmsPayload([
  'istep' => '2025-01-24 10:00:00',
  'fstep' => '2025-01-25 12:00:00',
  'server' => 'a',
  'mode' => 'forecast',
  'variable' => 'precipitation',
  'aggregation' => 'sum',
  'x' => 2,
  'y' => 3,
  'z' => 4,
  'timezone' => -3  # default timezone is 0 (UTC)
]);

$response = $advisor->tms->get($payload);

if (is_null($response->error)) {
  $file = fopen('tile.png', 'wb');
  fwrite($file, $response->data);
  fclose($file);
} else {
  print_r($response);
}

use StormGeo\AdvisorCore\Payloads\PmtilesPayload;

$payload = new PmtilesPayload([
  'mode' => 'forecast',
  'model' => 'ct2w15_as',
  'aggregation' => 'sum',
  'variable' => 'precipitation',
  'istep' => '2026-03-06 00:00:00',
  'fstep' => '2026-03-06 01:00:00',
  'maxZoom' => 4,
  'timezone' => -3  # optional, default timezone is 0 (UTC)
]);

$response = $advisor->pmtiles->get($payload);

if (is_null($response->error)) {
  $file = fopen('layer.pmtiles', 'wb');
  fwrite($file, $response->data);
  fclose($file);
} else {
  print_r($response);
}

use StormGeo\AdvisorCore\AdvisorCore;

$advisor = new AdvisorCore('invalid-token');

$advisor->setHeaderAccept('application/xml');
$advisor->setHeaderAcceptLanguage('es-ES');

$response = $advisor->plan->getInfo();

print_r($response->error);

// <response>
//   <error>
//     <type>UNAUTHORIZED_ACCESS</type>
//     <message>UNAUTHORIZED_REQUEST</message>
//     <description>La solicitud no está autorizada.</description>
//   </error>
// </response>

{
  "data": array|string|null,
  "error": array|string|null,
}