PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old November 4th, 2009, 12:16 PM
bruced39 bruced39 is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 9 bruced39 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 35 sec
Reputation Power: 0
HELP with PHP Weather map plotting code

Hello all, i am a new user and have found a code that I can't palce on this site since i am a new user, but if anyone is willing to help i could send you to the site where i found the code, the creator has said anyone can use or recreate it as they wish.

I just cant get it working. Its a script that pulls weather temperatures from data and can plot them on a map. I can give more info if anyone wishes to email me to help.

i can be reached at david_bruce002hotmail.com I don't think its a hard thing to get working since its already been written but rather after seeing it i need help to put it all together correctly to get it working. Thanks.

-dave

Reply With Quote
  #2  
Old November 4th, 2009, 01:11 PM
MatthewJ MatthewJ is offline
Contributing User
Click here for more information.
 
Join Date: May 2007
Location: Davenport, Iowa
Posts: 564 MatthewJ User rank is Private First Class (20 - 50 Reputation Level)MatthewJ User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 21 h 23 m 45 sec
Reputation Power: 3
Hey Dave,

Welcome to the forums... what you should do is try and post your code that contains the code you found on the other site.

Most likely the issue lies with trying to incorporate it into your code.

So post up what you have that you think is relevant and we'll try and help

Matt

Reply With Quote
  #3  
Old November 4th, 2009, 01:16 PM
bruced39 bruced39 is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 9 bruced39 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 35 sec
Reputation Power: 0
Thanks Matt for the welcome,

Well good news is I got the script to work, though when i correctly put the x,y coordinates in they are not placed correctly on the final outcome of the map. So I need to figure this problem out also how to change the color of outputted text from a the php script. The creator has it out put in white but mine comes out in black. Yet I have the same code.


Here's all the code for the main script in my .php page

<?php
///////////////////////////////////////////////////////////
// Copyright (c) 2009, Robert Kerr All rights reserved.
// Basically, modify the heck outta this or keep my
// copyright line intact and add your own.
///////////////////////////////////////////////////////////

$handle = fopen("WEBSITE TO GO FETCH DATA HERE", "r");
$contents = stream_get_contents($handle);

// lop off the beginning and end of that file's contents we won't use.
$contents = ereg_replace("(.*)WEATHER","",$contents);
$contents = preg_replace('/\x24\x24\x20/','',$contents);
fclose($handle);
// The above will be reused for other files and simply concatenated each time

// Because we want to delimit by two or more spaces, we #1. make them printable
// then #2. Reduce them to a single occurance (the single space stays in tact.
// then #3. Convert the end of line. (hex equivalents - space: x20 end of line: x0a and $ x24)

$str = preg_replace('/\x20\x20/', '~', $contents);
$str = preg_replace('/~~+/', '~', $str);
$str = preg_replace('/\x0a/', ';', $str);
// Split into an array of lines.
$aCity = split(';',$str);

// Now we are going to create another array, this time multidimensional

function my_explode($line) {
return explode('~' , $line);
}
$arrC = array_map('my_explode', preg_split("/;/", $str));


// For each line, we will look up the x,y plotting points from plots.txt

$i=0;
foreach ($aCity as $sValue) {
$pattern=$arrC[$i][0]; $pattern2='/'.$pattern.'.*\x0a/';
$plots = file_get_contents('plots.txt');
preg_match($pattern2, $plots, $match);
$arrC[$i][4]=substr($match[0], -8);

// More cleanup based on x, y - not always nnn,nnn
$arrC[$i][4]=ereg_replace("([A-Z])([~])", '', $arrC[$i][4]);
$arrC[$i][4]=ereg_replace("~", '', $arrC[$i][4]);

// Now if we have no match from plots.txt OR if the key element is null,
// we'll disqualify and remove this city

if ($arrC[$i][4]=="" || $arrC[$i][0]=="") {
unset($arrC[$i]);
}

$i++;
}

//Just to stay tidy, we'll renumber the remaining keys.
sort($arrC);

// NOW WE HAVE OUR ARRAY OF CITIES, TEMPS, WX AND PLOTTING POINTS
// TO PLUG INTO A GD SCRIPT.

// To see what the array now looks like:
// print_r ($arrC);
//////////////////////////////////////////////////////////////
// Send our variables out to the resulting script to display
// $TOTAL is the new script we are creating on the fly.
/////////////////////////////////////////////////////////////
$TOTAL='<? $img=imagecreatefromjpeg("./map.jpg"); $im = imagecreatetruecolor(10,10); $black = imagecolorallocate ($im,255,255,255); ';

$i=0; $ADD="";
foreach ($arrC[$i] as $sValue) {

if ($arrC[$i][4]!="") {
$NEXT="\$text$i".'=imagettftext($img, 21, 0, '. $arrC[$i][4]. ', $black, "./MONOFONT.TTF",'.$arrC[$i][1].');'."\n";
$ADD=$ADD.$NEXT;
}
$i++;
}

$TOTAL=$TOTAL.$ADD;
$TOTAL=$TOTAL.'header("Content-type:image/jpeg");header("Content-Disposition:inline ; filename=weathers.png");imagejpeg($img); ?>';


//// The Chmod commands will insist on appropriate permissions (not root!).
//chmod("TheWeather.php",777);
$fp = fopen("TheWeather.php", "w");
fwrite($fp, $TOTAL);
//chmod("TheWeather.php",755);
fclose($fp);
?>

Reply With Quote
  #4  
Old November 4th, 2009, 01:47 PM
MatthewJ MatthewJ is offline
Contributing User
Click here for more information.
 
Join Date: May 2007
Location: Davenport, Iowa
Posts: 564 MatthewJ User rank is Private First Class (20 - 50 Reputation Level)MatthewJ User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 21 h 23 m 45 sec
Reputation Power: 3
When working with map coords make sure the x and y are not transposed... Sometimes the apps want lat first, sometimes long first. I have had that problem before.

For the text you need to change the value of imagecolorallocate() to
PHP Code:
 $black imagecolorallocate ($im,0,0,0); 


Hope that helps,

Matt

Reply With Quote
  #5  
Old November 4th, 2009, 01:54 PM
bruced39 bruced39 is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 9 bruced39 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 35 sec
Reputation Power: 0
Thanks for your time matt, yes i did change that line to 0,0,0. I have been fooling around with different combo's of coordinates x,y for one data point and it has no rime or reason. If I place it at 87,77 it may place the data in the upper right area of the map then anytime i go over any x up to 99 it moves slightly right, which it should as i go higher for x, yet when i go over 100 for x it automatically places the data on the left side of the image. I have no clue why. any ideas.

Reply With Quote
  #6  
Old November 4th, 2009, 06:00 PM
bruced39 bruced39 is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 9 bruced39 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 35 sec
Reputation Power: 0
Matt,

I see whats going on, for some reason when my x value go over 99 the data plot goes straight to the left edge i can make it move correctly up to 99 but anything over that causes it to not act correctly. I think the y axis is working ok. Would you know why based on the script i put on this thread? also, i changed the word black to white to change the data plot text to print white but it remains black, can you tell me how i can change the color to what i want it.

Reply With Quote
  #7  
Old November 4th, 2009, 06:10 PM
MatthewJ MatthewJ is offline
Contributing User
Click here for more information.
 
Join Date: May 2007
Location: Davenport, Iowa
Posts: 564 MatthewJ User rank is Private First Class (20 - 50 Reputation Level)MatthewJ User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 21 h 23 m 45 sec
Reputation Power: 3
PHP Code:
 $black imagecolorallocate ($im,0,0,0); 


I'll have to look a bit more after the gym to see if I can help with the x value, but you need to change TO the line above... in your original code it was

PHP Code:
 $black imagecolorallocate ($im,255,255,255); 


$black is just the variable name passed to the image function

Reply With Quote
  #8  
Old November 4th, 2009, 06:12 PM
bruced39 bruced39 is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 9 bruced39 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 35 sec
Reputation Power: 0
Matt, thanks I changed the 255's to 0's.. If you have time please email me when you return. I will try to figure this out until i hear from you. Thanks so much. I am trying to learn as i go after this i plan on learning php. I could really use my own maps such as this to update automatically. With dewpoints, wind speeds and other info. I never knew this was possible to create.

Reply With Quote
  #9  
Old November 5th, 2009, 03:20 AM
IAmALlama IAmALlama is offline
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,937 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 5 Days 1 h 54 m 18 sec
Reputation Power: 4
I'm just reading through the code and there is probably just a problem with reading 3 digit x plot points from plots.txt. it would really depend on what that data looks like in plots.txt. could you post maybe like 3-4 lines of example data? maybe at least one good plot and one bad just to compare.

Reply With Quote
  #10  
Old November 5th, 2009, 02:18 PM
bruced39 bruced39 is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 9 bruced39 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 35 sec
Reputation Power: 0
Matt,

Here is all he has set up plots.txt to be

BOSTON~566,415
BUFFALO~16,385

(TILDES AS DELIMITERS IS ARBITRARY)

UI can add as many plots as i wish. I aset up a php page with the same map i am using in the wxcities.php page to get the coordinates correctly. If you go to my site www. billericaweather . com / test / test.php you will see the buffalo temperature is correct as its x number is less than the 99 i told you about. But the Boston temperature which has an x of 566 is near the buffalo. Any ideas.

-Dave

Reply With Quote
  #11  
Old November 5th, 2009, 02:21 PM
bruced39 bruced39 is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 9 bruced39 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 35 sec
Reputation Power: 0
[QUOTE=bruced39]Matt,

Here is all he has set up plots.txt to be

BOSTON~566,415
BUFFALO~16,385

(TILDES AS DELIMITERS IS ARBITRARY)

UI can add as many plots as i wish. I aset up a php page with the same map i am using in the wxcities.php page to get the coordinates correctly. If you go to my site www.billericaweather.com/test/test.php you will see the buffalo temperature is correct as its x number is less than the 99 i told you about. But the Boston temperature which has an x of 566 is near the buffalo. Any ideas.
The site I got the script from is at http://robkerr.net/sofar.html

Reply With Quote
  #12  
Old November 6th, 2009, 05:46 PM
bruced39 bruced39 is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 9 bruced39 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 35 sec
Reputation Power: 0
Hello All,

If you have been reading my thread i have solved the color issue to change the printed text to white, but i can't seem to find the problem why the script is only reading the last 2 digits of the x value. (eg. x value in the plots.txt file for BOSTON is BOSTON~562,408, yet when i have the script print the value it says 62,408) which is why the temperature for boston at www.billericaweather.com/test/test.php if over the word buffalo. Buffalo's temperature is ok since the x value is only 2 digits. Yet it reads the y value all 3 digits. Can anyone look into the full script below and see why this is happening.

<?php
///////////////////////////////////////////////////////////
// Copyright (c) 2009, Robert Kerr All rights reserved.
// Released under The BSD License:
// http://www.opensource.org/licenses/bsd-license.php
// Basically, modify the heck outta this or keep my
// copyright line intact and add your own.
///////////////////////////////////////////////////////////

$handle = fopen("http://weather.noaa.gov/pub/data/summaries/selected_cities/current/eastern_us.txt", "r");
$contents = stream_get_contents($handle);

// lop off the beginning and end of that file's contents we won't use.
$contents = ereg_replace("(.*)WEATHER","",$contents);
$contents = preg_replace('/\x24\x24\x20/','',$contents);
fclose($handle);
// The above will be reused for other files and simply concatenated each time

// Because we want to delimit by two or more spaces, we #1. make them printable
// then #2. Reduce them to a single occurance (the single space stays in tact.
// then #3. Convert the end of line. (hex equivalents - space: x20 end of line: x0a and $ x24)

$str = preg_replace('/\x20\x20/', '~', $contents);
$str = preg_replace('/~~+/', '~', $str);
$str = preg_replace('/\x0a/', ';', $str);
// Split into an array of lines.
$aCity = split(';',$str);

// Now we are going to create another array, this time multidimensional

function my_explode($line) {
return explode('~' , $line);
}
$arrC = array_map('my_explode', preg_split("/;/", $str));


// For each line, we will look up the x,y plotting points from plots.txt

$i=0;
foreach ($aCity as $sValue) {
$pattern=$arrC[$i][0]; $pattern2='/'.$pattern.'.*\x0a/';
$plots = file_get_contents('plots.txt');
preg_match($pattern2, $plots, $match);

$arrC[$i][4]=substr($match[0], -8);

// More cleanup based on x, y - not always nnn,nnn
$arrC[$i][4]=ereg_replace("([A-Z])([~])", '', $arrC[$i][4]);
$arrC[$i][4]=ereg_replace("~", '', $arrC[$i][4]);

// Now if we have no match from plots.txt OR if the key element is null,
// we'll disqualify and remove this city

if ($arrC[$i][4]=="" || $arrC[$i][0]=="") {
unset($arrC[$i]);
}

$i++;
}

//Just to stay tidy, we'll renumber the remaining keys.
sort($arrC);

// NOW WE HAVE OUR ARRAY OF CITIES, TEMPS, WX AND PLOTTING POINTS
// TO PLUG INTO A GD SCRIPT.

// To see what the array now looks like:
//print_r ($arrC);
//////////////////////////////////////////////////////////////
// Send our variables out to the resulting script to display
// $TOTAL is the new script we are creating on the fly.
/////////////////////////////////////////////////////////////
$TOTAL='<? $img=imagecreatefromjpeg("./map2.jpg"); $im = imagecreatetruecolor(10,10); $black = imagecolorallocate ($im,0,0,0); ';

$i=0; $ADD="";
foreach ($arrC[$i] as $sValue) {

if ($arrC[$i][4]!="") {
$NEXT="\$text$i".'=imagettftext($img, 25, 0, '. $arrC[$i][4]. ', $white = imagecolorallocate($im, 255, 255, 255), "./MONOFONT.TTF",'.$arrC[$i][1].');'."\n" ;

$ADD=$ADD.$NEXT;
}
$i++;
}

$TOTAL=$TOTAL.$ADD;
$TOTAL=$TOTAL.'header("Content-type:image/jpeg");header("Content-Disposition:inline ; filename=weathers.png");imagejpeg($img); ?>';


//// The Chmod commands will insist on appropriate permissions (not root!).
//chmod("TheWeather.php",777);
$fp = fopen("TheWeather.php", "w");
fwrite($fp, $TOTAL);
//chmod("TheWeather.php",755);
fclose($fp);
?>


<a href="http://www.billericaweather.com" title="This weather should be rather current as its fetched directly from the NOAA (National Weather Service).">
<img src="http://www.billericaweather.com/test/TheWeather.php" />

-Dave

Reply With Quote
  #13  
Old November 6th, 2009, 06:47 PM
bruced39 bruced39 is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 9 bruced39 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 15 m 35 sec
Reputation Power: 0
UPDATE....

I fixed the x coordinate problem. on this line as it was before

$arrC[$i][4]=substr($match[0], -8);

I changed to $arrC[$i][4]=substr($match[0], -10);

after just fooling around it fixed the problem so x can read 3 digit coordinates. I have yet to learn php but i have r4ead enough and searched enough to figure what and where i needed to change to try and make it work. No on to understanding how this whole thing works so i can have it use a different webpage with data that i want it to choose from. The site the author uses doesnt have the cities. i want.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > HELP with PHP Weather map plotting code


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek