Giter Site home page Giter Site logo

skywise-insight-php's Introduction

Overview

A PHP class for interacting with the SkyWise Insight API. Check out the API docs to reference exposed endpoints. Also check out some examples.

Prerequisites

Examples

Instantiate the class:

require_once 'InsightAPI.php';
date_default_timezone_set('UTC');

const APPID = '<your app id>';
const APPKEY = '<your app key>';

$insight = new InsightAPI(APPID, APPKEY);

Calculate the average temperature over a time series:

$params = array(
  'start' => (new \DateTime())->modify('-5 hours')->format("Y-m-d\TH:00:00P"),
  'end' => (new \DateTime())->modify('+5 hours')->format("Y-m-d\TH:00:00P"),
);

$lat = 35;
$lon = -95;

$result = $insight->hourlyTemperatureByPoint($lat, $lon, $params);
$avg = 0;
foreach ($result->{'series'} as &$s) {
    $avg += $s->value;
}
$avg /= count($result->{'series'});
echo "average temperature: $avg\n";

Create an asset, and get statistics over the asset area:

$geojson = file_get_contents('./asset.geojson');
$asset = $insight->createAsset($geojson);

$result = $insight->hourlyTemperatureByAsset($asset->id, $params);
foreach ($result->{'series'} as &$series) {
    echo 'min: '.$series->assetStatistics->minimum.PHP_EOL;
    echo 'max: '.$series->assetStatistics->maximum.PHP_EOL;
    echo 'mean: '.$series->assetStatistics->mean.PHP_EOL;
}

Grab some asset contours:

$contours = $insight->hourlyPrecipitationContours($asset->id, $params);
echo json_encode($contours).PHP_EOL;
{
   "startDate":"2016-10-22",
   "endDate":"2016-10-27",
   "features":[
      {
         "geometry":{
            "type":"Polygon",
            "coordinates":[
               [
                  [
                     -97.3889923096,
                     35.1847140483
                  ],
                  [
                     -97.4047851562,
                     35.1842612643
                  ],
                  [
                     -97.4487304688,
                     35.1891128046
                  ],
                  [
                     -97.490272522,
                     35.1916218165
                  ],
                  [
                     -97.490272522,
                     35.2565534411
                  ],
                  [
                     -97.3889923096,
                     35.2565534411
                  ],
                  [
                     -97.3889923096,
                     35.1847140483
                  ]
               ]
            ]
         },
         "type":"Feature",
         "properties":{
            "precipitation":4.6
         }
      },
      {
         "geometry":{
            "type":"Polygon",
            "coordinates":[
               [
                  [
                     -97.400744598,
                     35.2565534411
                  ],
                  [
                     -97.4024544492,
                     35.2276723549
                  ],
                  [
                     -97.4047851562,
                     35.2272833537
                  ],
                  [
                     -97.4225764149,
                     35.2276723549
                  ],
                  [
                     -97.4369814385,
                     35.2565534411
                  ],
                  [
                     -97.400744598,
                     35.2565534411
                  ]
               ]
            ]
         },
         "type":"Feature",
         "properties":{
            "precipitation":6.3
         }
      }
   ],
   "asset":"\/assets\/6b6f8b7e-9859-11e6-a87c-1224761ecbee",
   "type":"FeatureCollection",
   "unit":{
      "description":"millimeters",
      "label":"mm"
   }
}
Loading

skywise-insight-php's People

Contributors

lrobb avatar

Watchers

Lee Robb avatar James Cloos avatar Jordan Rousseau avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.