Tag Archives: php

UrtheCast Satellites

urthecast

I’m working my way through the UrtheCast API documentation, and got side-tracked into making a satellite tracker map. This map shows the ten most recent locations of four satellites (ISS, Deimos-1, Deimos-2, and Lansat-8) and their imagery swaths, I think. The reason I say I think is that the call for the imagery swaths (or the forecast) is set for the future, although the returned timestamps appear to be in the past.

I also think I figured out how to hide my UrtheCast api key and secret from prying eyes through a PHP proxy, but I could also be wrong about that! If you can see them, let me know. 🙂

Advertisements

CBC Sports Word Cloud

Image

Still playing around with PHP/XML. Here’s a method for parsing an RSS feed (CBC Sports) with PHP and loading the results (descriptions) into a D3 wordcloud. And, here‘s why you shouldn’t use word clouds – I don’t really care about that, though, this was about learning some PHP.

Anyways, the PHP code I used was:

<?php
//load xml
$xml_file_open = simplexml_load_file(“http://rss.cbc.ca/lineup/sports.xml&#8221;);
//parse xml
displayChildrenRecursive($xml_file_open);

function displayChildrenRecursive($xmlObj,$depth=0) {
//make array of stopwords to ignore – go get them from here.
$stopwords =
$stopwords = explode(“,”, $stopwords);

//loop through xml tags
foreach($xmlObj->children() as $child) {
//get descriptions
if($child->getName()==’description’) {
//get text
$childStringRaw = print_r((string)$child,true);
//drop excess HTML in description
$childStringMid = explode(“<p>”, $childStringRaw);
$childStringLeft = explode(“</p>”, $childStringMid[1]);
$childString = $childStringLeft[0];
//escape quotes
$childString = str_replace(“‘”,”\'”,$childString);
//separate description into individual words
$childArray = explode(” “, $childString);
//loop through words
foreach ($childArray as $word)
{
//disregard if the word is a stopword
if (!in_array(strtolower($word), $stopwords, TRUE)) {
//get rid of spaces
$trimmed = trim($word);
//add to javascript array
echo “js_array.push(‘$trimmed’);\n”;
}
}
}
//run on next tag
displayChildrenRecursive($child,$depth+1);
}
}
?>

Hat tips:

Sherif’s Tech Blog

Jason Davies Blog

Nieman Journalism Lab

SVG Trace: PaperJS on Google Maps API

Image

Don’t ask me why I thought of doing this while laying awake last night, but I think it turned out pretty nicely. The steps involved are:

  1. Add a line feature class to ArcMap. I had a polygon of Canadian provinces and used Feature to Line with a 20km tolerance, to simplify the line geometry.
  2. Export to SVG
  3. Upload the SVG to your web server.
  4. You can figure the rest out from looking at the source code (Ctrl-U), except how I parsed the SVG file with PHP, which I accomplished like this (in PHP tags):

$xml_file_open = simplexml_load_file(“http://darrenwiens.net/svg/provs.svg “);
foreach($xml_file_open->g->g->children() as $child)
{
$trimmed_child = trim($child[d]);
echo “js_array.push(‘$trimmed_child’);\n”;
}

That’s it. If you feel inspired, you could make a cool geography guessing game with this (i.e. guess the country before the shape is finished drawing). Let me know if you do!