Author Topic: US National Temperatures map PHP script  (Read 9737 times)

0 Members and 1 Guest are viewing this topic.

Offline dnavarrojr

  • Member
  • *
  • Posts: 34
    • WIBW News Now
US National Temperatures map PHP script
« on: November 03, 2013, 02:15:53 PM »


I have a script that generates a current U.S. map with national temperatures on it.

The script has an option for saving the map to a folder on your web site (I run a CRON job every 15 minutes to update the map).

The base map is from Google Maps and I mess with the contrast a bit to bring out the color in the map.

The cities and weather stations are specified in an array:
Code: [Select]
$cities = [
  [ 'name' => 'Topeka',         'station' => 'KTOP' ],
  [ 'name' => 'St Louis',       'station' => 'KSTL' ],
  [ 'name' => 'Los Angeles',    'station' => 'KLAX' ],
  [ 'name' => 'San Francisco',  'station' => 'KSFO' ],
  [ 'name' => 'Las Vegas',      'station' => 'KLAS' ],
  [ 'name' => 'Seattle',        'station' => 'KBFI' ],
  [ 'name' => 'Tulsa',          'station' => 'KTUL' ],
  [ 'name' => 'El Paso',        'station' => 'KELP' ],
  [ 'name' => 'Dallas',         'station' => 'KDFW' ],
  [ 'name' => 'Houston',        'station' => 'KHOU' ],
  [ 'name' => 'Salt Lake City', 'station' => 'KSLC' ],
  [ 'name' => 'Salem',          'station' => 'KSLE' ],
  [ 'name' => 'Miami',          'station' => 'KMIA' ],
  [ 'name' => 'Denver',         'station' => 'KBKF' ],
  [ 'name' => 'Detroit',        'station' => 'KDET' ],
  [ 'name' => 'Chicago',        'station' => 'KORD' ],
  [ 'name' => 'Omaha',          'station' => 'KOMA' ],
  [ 'name' => 'Billings',       'station' => 'KBIL' ],
  [ 'name' => 'Atlanta',        'station' => 'KATL' ],
  [ 'name' => 'Minneapolis',    'station' => 'KMSP' ],
  [ 'name' => 'New York City',  'station' => 'KNYC' ],
  [ 'name' => 'Washington, DC', 'station' => 'KIAD' ],
  [ 'name' => 'Bismarck',       'station' => 'KBIS' ],
  [ 'name' => 'Bangor',         'station' => 'KBGR' ],
  [ 'name' => 'Raleigh',        'station' => 'KRDU' ],
  [ 'name' => 'Amarillo',       'station' => 'KAMA' ],
  [ 'name' => 'Nashville',      'station' => 'KBNA' ],
  [ 'name' => 'Jacksonville',   'station' => 'KJAX' ],
  [ 'name' => 'Boise',          'station' => 'KBOI' ],
];

You can replace the logo file with your own.  The only changes you HAVE to make are to the $image_folder and $font_folder variables.  Point them at where you store your image base, logo files and font file.

http://weather.wibwradio.com/usa-temps-map.zip

Let me know if you have any questions, suggestions or comments.



Dave Navarro, Jr. - Director of Digital Media - Alpha Media USA
WIBW News Now - http://wibwnewsnow.com
Kansas Ag Network - http://kansasagnetwork.com
94.5 Country - http://94country.com
KGNC News Now - http://kgncnewsnow.com

Offline cospringswx

  • Forecaster
  • *****
  • Posts: 4046
    • Colorado Springs Weather
Re: US National Temperatures map PHP script
« Reply #1 on: November 03, 2013, 02:30:05 PM »
Any way to add your location to the map?




Ryan 

Colorado Springs, CO
www.cospringsweather.com
Davis Vantage Vue
Weather Display Software
Hikvision HD IP Camera

Offline dnavarrojr

  • Member
  • *
  • Posts: 34
    • WIBW News Now
Re: US National Temperatures map PHP script
« Reply #2 on: November 03, 2013, 05:39:27 PM »
Any way to add your location to the map?

Sure, just modify the array and add your city/station.
Dave Navarro, Jr. - Director of Digital Media - Alpha Media USA
WIBW News Now - http://wibwnewsnow.com
Kansas Ag Network - http://kansasagnetwork.com
94.5 Country - http://94country.com
KGNC News Now - http://kgncnewsnow.com

Offline dnavarrojr

  • Member
  • *
  • Posts: 34
    • WIBW News Now
Re: US National Temperatures map PHP script
« Reply #3 on: November 03, 2013, 05:42:07 PM »
Oh, wait.. You want to add your personal weather station?

You'd have to add it manually.  My script only supports official stations on NWS.

Are you on Weather Underground?  If so, I could modify the script to support any station on WU.
Dave Navarro, Jr. - Director of Digital Media - Alpha Media USA
WIBW News Now - http://wibwnewsnow.com
Kansas Ag Network - http://kansasagnetwork.com
94.5 Country - http://94country.com
KGNC News Now - http://kgncnewsnow.com

Offline cospringswx

  • Forecaster
  • *****
  • Posts: 4046
    • Colorado Springs Weather
Re: US National Temperatures map PHP script
« Reply #4 on: November 03, 2013, 06:12:20 PM »




Ryan 

Colorado Springs, CO
www.cospringsweather.com
Davis Vantage Vue
Weather Display Software
Hikvision HD IP Camera

Offline chief-david

  • Educational Weather
  • Forecaster
  • *****
  • Posts: 1965
  • Space Academy for Educators
    • Robbinsdale Middle School Weather
Re: US National Temperatures map PHP script
« Reply #5 on: November 03, 2013, 06:15:53 PM »
someone could make that a map of forum members from WU
Vantage Pro Plus 6163
Robbinsdale, MN 55422@ 45 degrees North Latitude.
http://weather.rms.rdale.org

You can't phase me-I teach Middle School.

Offline cospringswx

  • Forecaster
  • *****
  • Posts: 4046
    • Colorado Springs Weather
Re: US National Temperatures map PHP script
« Reply #6 on: November 03, 2013, 08:05:22 PM »
My map is here http://www.hayskansasweather.com/images/usa-weather-base2.png

Is this path correct?

Code: [Select]
$image_folder = '/hayskansasweather.com/images/';
$font_folder  = '/hayskansasweather.com/images/';




Ryan 

Colorado Springs, CO
www.cospringsweather.com
Davis Vantage Vue
Weather Display Software
Hikvision HD IP Camera

Offline dnavarrojr

  • Member
  • *
  • Posts: 34
    • WIBW News Now
Re: US National Temperatures map PHP script
« Reply #7 on: November 03, 2013, 10:50:59 PM »
My map is here http://www.hayskansasweather.com/images/usa-weather-base2.png

Is this path correct?

Code: [Select]
$image_folder = '/hayskansasweather.com/images/';
$font_folder  = '/hayskansasweather.com/images/';

Only if that's the physical location of your web site.  I don't know how things are on your back end.

I'll update the code to "do the math" on the file locations.
Dave Navarro, Jr. - Director of Digital Media - Alpha Media USA
WIBW News Now - http://wibwnewsnow.com
Kansas Ag Network - http://kansasagnetwork.com
94.5 Country - http://94country.com
KGNC News Now - http://kgncnewsnow.com

Offline SteveFitz1

  • Forecaster
  • *****
  • Posts: 305
    • http://www.TylerTexasWeather.Com
Re: US National Temperatures map PHP script
« Reply #8 on: November 04, 2013, 01:07:56 PM »
Dave,

I changed the $image_folder and $font_folder variables as you recommended and I get this error:

Parse error: syntax error, unexpected '[' in /home/stevefitz1/tylertexasweather.com/usa-temps-map.php on line 78

And this is line 78

$cities = [

Any suggestions?

Thanks,

Steve

Offline cospringswx

  • Forecaster
  • *****
  • Posts: 4046
    • Colorado Springs Weather
Re: US National Temperatures map PHP script
« Reply #9 on: November 04, 2013, 01:42:58 PM »
Dave,

I changed the $image_folder and $font_folder variables as you recommended and I get this error:

Parse error: syntax error, unexpected '[' in /home/stevefitz1/tylertexasweather.com/usa-temps-map.php on line 78

And this is line 78

$cities = [

Any suggestions?

Thanks,

Steve

Me too!  http://www.hayskansasweather.com/usatemps.php




Ryan 

Colorado Springs, CO
www.cospringsweather.com
Davis Vantage Vue
Weather Display Software
Hikvision HD IP Camera

Offline Andy G

  • Senior Contributor
  • ****
  • Posts: 279
    • SunPrairieWeather.com
Re: US National Temperatures map PHP script
« Reply #10 on: November 04, 2013, 02:44:07 PM »
Once you can accept the universe as being something expanding into an infinite nothing which is something, wearing stripes with plaid is easy.
~Einstein


SunPrairieWeather.com
Davis VP2 24 FARS

Offline dnavarrojr

  • Member
  • *
  • Posts: 34
    • WIBW News Now
Re: US National Temperatures map PHP script
« Reply #11 on: November 04, 2013, 03:19:39 PM »
Dave,

I changed the $image_folder and $font_folder variables as you recommended and I get this error:

Parse error: syntax error, unexpected '[' in /home/stevefitz1/tylertexasweather.com/usa-temps-map.php on line 78

And this is line 78

$cities = [

Any suggestions?

Thanks,

Steve

What version of PhP are you running?

Dave Navarro, Jr. - Director of Digital Media - Alpha Media USA
WIBW News Now - http://wibwnewsnow.com
Kansas Ag Network - http://kansasagnetwork.com
94.5 Country - http://94country.com
KGNC News Now - http://kgncnewsnow.com

Offline dnavarrojr

  • Member
  • *
  • Posts: 34
    • WIBW News Now
Re: US National Temperatures map PHP script
« Reply #12 on: November 04, 2013, 03:46:26 PM »
Okay, I am running the latest version of PHP which supports the array syntax of:

Code: [Select]
$ar = [ ];
However, earlier versions do not.  So I'll rewrite the array to work with earlier versions of PhP.
Dave Navarro, Jr. - Director of Digital Media - Alpha Media USA
WIBW News Now - http://wibwnewsnow.com
Kansas Ag Network - http://kansasagnetwork.com
94.5 Country - http://94country.com
KGNC News Now - http://kgncnewsnow.com

Offline dnavarrojr

  • Member
  • *
  • Posts: 34
    • WIBW News Now
Re: US National Temperatures map PHP script
« Reply #13 on: November 04, 2013, 03:52:51 PM »
Re-download the script from the original link.  Hopefully that fixes everything.

Make sure you edit the MAP, LOGO and FONT variables if you are not using "maps/" or "fonts/" to store your files in those folders.
Dave Navarro, Jr. - Director of Digital Media - Alpha Media USA
WIBW News Now - http://wibwnewsnow.com
Kansas Ag Network - http://kansasagnetwork.com
94.5 Country - http://94country.com
KGNC News Now - http://kgncnewsnow.com

Offline SteveFitz1

  • Forecaster
  • *****
  • Posts: 305
    • http://www.TylerTexasWeather.Com
Re: US National Temperatures map PHP script
« Reply #14 on: November 04, 2013, 05:29:25 PM »
Dave,

Your updated version worked for me. Thanks very much.

I'm on PHP 5.3.27. Based on the error in the array, I suspected you had possibly written for PHP 5.5.

Steve

Offline cospringswx

  • Forecaster
  • *****
  • Posts: 4046
    • Colorado Springs Weather
Re: US National Temperatures map PHP script
« Reply #15 on: November 04, 2013, 05:37:17 PM »
Dave,

Your updated version worked for me. Thanks very much.

I'm on PHP 5.3.27. Based on the error in the array, I suspected you had possibly written for PHP 5.5.

Steve

Post a link to your page Steve. I'm running PHP 5.2.14.




Ryan 

Colorado Springs, CO
www.cospringsweather.com
Davis Vantage Vue
Weather Display Software
Hikvision HD IP Camera

Offline SteveFitz1

  • Forecaster
  • *****
  • Posts: 305
    • http://www.TylerTexasWeather.Com
Re: US National Temperatures map PHP script
« Reply #16 on: November 04, 2013, 05:55:08 PM »

Post a link to your page Steve. I'm running PHP 5.2.14.

Here ya go, Ryan.

http://www.tylertexasweather.com/usa-temps-map.php

All I changed was just the directory entries.

Steve

Offline cospringswx

  • Forecaster
  • *****
  • Posts: 4046
    • Colorado Springs Weather
Re: US National Temperatures map PHP script
« Reply #17 on: November 04, 2013, 06:09:16 PM »

Post a link to your page Steve. I'm running PHP 5.2.14.

Here ya go, Ryan.

http://www.tylertexasweather.com/usa-temps-map.php

All I changed was just the directory entries.



Steve

Guess I got it on here http://www.hayskansasweather.com/usa-temps-map.php but with no data? How are you updating yours Steve? Can you post what you changed?
« Last Edit: November 04, 2013, 06:16:38 PM by hayskswx »




Ryan 

Colorado Springs, CO
www.cospringsweather.com
Davis Vantage Vue
Weather Display Software
Hikvision HD IP Camera

Offline blizzardof78

  • Forecaster
  • *****
  • Posts: 538
Re: US National Temperatures map PHP script
« Reply #18 on: November 04, 2013, 06:47:19 PM »
Any way of doing this with humidity, pressure, wind speed, and so on? Boy if there was and I could figure out what in sam hill to do to make it work  #-o I'd drop my subscription to my current service in a minute!

Offline sacreyweather

  • Echo Valley Weather
  • Forecaster
  • *****
  • Posts: 1542
    • Echo Valley Weather
Re: US National Temperatures map PHP script
« Reply #19 on: November 04, 2013, 07:26:09 PM »
Hi Dave,

Thanks for the script. Have it working here: USA Temps

John
CWOP: D2073, GR2AE, GR3, Cumulus, PWSweather,  CoCoRaHS: AR-SL-23  

Saline Weather on Twitter
Blitzortung Station 1387

Offline sacreyweather

  • Echo Valley Weather
  • Forecaster
  • *****
  • Posts: 1542
    • Echo Valley Weather
Re: US National Temperatures map PHP script
« Reply #20 on: November 04, 2013, 07:26:51 PM »
Ryan,

Please check your directory settings in the script for the map background. I'm almost guessing the info is there, but without the background being there, its hard to check that.

John
CWOP: D2073, GR2AE, GR3, Cumulus, PWSweather,  CoCoRaHS: AR-SL-23  

Saline Weather on Twitter
Blitzortung Station 1387

Offline cospringswx

  • Forecaster
  • *****
  • Posts: 4046
    • Colorado Springs Weather
Re: US National Temperatures map PHP script
« Reply #21 on: November 04, 2013, 07:30:09 PM »
John post your settings here if you don't mind. How are u updating it?




Ryan 

Colorado Springs, CO
www.cospringsweather.com
Davis Vantage Vue
Weather Display Software
Hikvision HD IP Camera

Offline sacreyweather

  • Echo Valley Weather
  • Forecaster
  • *****
  • Posts: 1542
    • Echo Valley Weather
Re: US National Temperatures map PHP script
« Reply #22 on: November 04, 2013, 07:33:11 PM »
Hi Ryan,

Here ya go:

$map_base  = $dirbase . 'images/usa-weather-base2.png';
$logo      = $dirbase . 'images/usa-logo.png';

$outfile = "usa-temps-map";

$text_font = $dirbase . 'fonts/franklin_medium_condensed.ttf';
$font_size = 11;

Currently I'm updating it manually, but will probably set up a cron to it every 15 minutes or so.

John
CWOP: D2073, GR2AE, GR3, Cumulus, PWSweather,  CoCoRaHS: AR-SL-23  

Saline Weather on Twitter
Blitzortung Station 1387

Offline cospringswx

  • Forecaster
  • *****
  • Posts: 4046
    • Colorado Springs Weather
Re: US National Temperatures map PHP script
« Reply #23 on: November 04, 2013, 08:48:45 PM »

What do you have for this line? My usa-temps-map.php file is in the root.
Code: [Select]

[code$dirbase   = dirname(__FILE__) . '/';      // current folder where PHP file is installed]
« Last Edit: November 04, 2013, 09:05:28 PM by hayskswx »




Ryan 

Colorado Springs, CO
www.cospringsweather.com
Davis Vantage Vue
Weather Display Software
Hikvision HD IP Camera

Offline sacreyweather

  • Echo Valley Weather
  • Forecaster
  • *****
  • Posts: 1542
    • Echo Valley Weather
Re: US National Temperatures map PHP script
« Reply #24 on: November 04, 2013, 09:03:49 PM »
Code: [Select]
What do you have for this line?

[code$dirbase   = dirname(__FILE__) . '/';      // current folder where PHP file is installed]

Hi Ryan,

This line is right above the map base line in the new version of the script. Around line 67 or so.
CWOP: D2073, GR2AE, GR3, Cumulus, PWSweather,  CoCoRaHS: AR-SL-23  

Saline Weather on Twitter
Blitzortung Station 1387