pls ck my code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shradhaparab
Forum Newbie
Posts: 6
Joined: Fri May 09, 2008 6:50 am

pls ck my code

Post by shradhaparab »

can any one check and tell me wat is wrong in my code
map.php

<?php
//define constants
define("MAPFILE","testmap.png");

define("MINX",0);
define("MAXX",699+MINX);
define("MINY", 0);
define("MAXY", 419+MINY);

define("MINLAT", -1288888);
define("MAXLAT", 2297888);
define("MINLONG", 4098989);
define("MAXLONG", 9999898);
define("GRIDSIZE", 10);

if(trim($minLat)=="") $minLat=MINLAT;
if(trim($maxLat)=="") $maxLat=MAXLAT;
if(trim($minLong)=="") $minLong=MINLONG;
if(trim($maxLong)=="") $maxLong=MAXLONG;

function getPixelValueofLat($l)
{
$scaleY = (MAXY - MINY)/(MAXLAT - MINLAT);
$LAT_PIXEL = round(MINY + (MAXLAT - $l) * $scaleY);
return $LAT_PIXEL;
}

function getPixelValueofLong($l)
{
$scaleX = (MAXX - MINX)/( MAXLONG - MINLONG);
$LONG_PIXEL = round(MINX + ($l - MINLONG) * $scaleX);
return $LONG_PIXEL;
}

$im=imagecreatefrompng(MAPFILE);
//$background = imagecolorallocate($im, 150, 200, 255);

$background = imagecolorallocate($im, 255, 255, 255);
//$background = imagecolorallocate($im,102, 102, 102);
//imagestring ($im, 1, 5, 5, "A Simple Text String", $text_color);

// output image in the browser
$red=imagecolorallocate($im, 255, 0, 0);
$green=imagecolorallocate($im, 0, 255, 0);
$darkgreen=imagecolorallocate($im, 105, 155, 160);
$darkgray=imagecolorallocate($im, 102, 102, 102);
$blue=imagecolorallocate($im, 0, 0, 255);
$black=imagecolorallocate($im, 0, 0, 0);
$linecolour=$darkgray;

$str="(".getPixelValueofLat(-90)." ,".getPixelValueofLong(180).")";

imageline ( $im, MINX, MINY, MAXX, MINY, $darkgreen );
imageline ( $im, MINX, MINY, MINX, MAXY, $darkgreen );
imageline ( $im, MINX, MAXY, MAXX, MAXY, $darkgreen );
imageline ( $im, MAXX, MINY, MAXX, MAXY, $darkgreen );

$text_color = $black;
$font_size=2;

for($i = 0 ; $i <= ((MAXLONG-MINLONG)/GRIDSIZE); $i++)
{
$lo=(MINLONG-(MINLONG-((MINLONG%GRIDSIZE)*GRIDSIZE)))+$i*GRIDSIZE;

if($lo < 0 )
{
$s="- ".($lo*-1);
}
else if($lo == 0 )
{
$s=" ".$lo;
}
else
{
$s="+ ".$lo;
}
$xcord=getPixelValueofLong($lo);

imagestringup($im, $font_size, $xcord-6, MINY-8, $s , $linecolour);
imageline ( $im, $xcord, MINY, $xcord, MAXY, $drakgray);
}

for($j = 0 ; $j <= ((MAXLAT-MINLAT)/GRIDSIZE) ; $j++)
{
$la=(MAXLAT-(MAXLAT-((MAXLAT%GRIDSIZE)*GRIDSIZE)))-$j*GRIDSIZE;

if($la < 0 )
{
$s="- ".($la*-1);
}
else if($la == 0 )
{
$s=" ".$la;
}
else
{
$s="+ ".$la;
}
$ycord=getPixelValueofLat($la);

imagestring($im, $font_size, 7, $ycord-7, str_pad($s,5, " ",STR_PAD_LEFT) , $linecolour);
imageline ($im, MINX, $ycord, MAXX, $ycord, $drakgray);
}

// header("Content-type: image/png");
//Output graph and clear image from memory
// imagepng($im);
?>
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
graph.php

<?php

include_once("connect_db.php");

include_once("map.php");

header("Content-type: image/png");



$colorRed=imagecolorallocate($im, 255, 0, 0);



//ploting graph with different colors

$color=array(

$colorYellow=ImageColorAllocate($im, 204,204,204),

$colorBlue=ImageColorAllocate($im, 0, 0, 255),

$colorWhite=imagecolorallocate($im, 255, 255, 255),

$colorGreen=imagecolorallocate($im, 0, 255, 0),

$colorRed=imagecolorallocate($im, 255, 0, 0),

$colorWhite=imagecolorallocate($im, 255, 255, 255),

);



$color=array("colorBlue","colorGreen","colorRed","colorGrey");

$col=count($color);

//query to take values plot graph



$minLat=$_GET["minLat"];

//echo "minlat".$minLat."<br>";

$maxLat=$_GET["maxLat"];

//echo "maxlat".$maxLat."<br>";

$minLong=$_GET["minLong"];

//echo "minlong".$minLong."<br>";

$maxLong=$_GET["maxLong"];

//echo "maxlong".$maxLong."<br>";



$query="select distinct LATITUDE,LONGITUDE from tablename where LATITUDE >= $minLat and LATITUDE <= $maxLat and LONGITUDE >= $minLong and LONGITUDE <= $maxLong";

//echo "query".$query."<br>";



$result = mysql_query($query,$link);



$lat0="";

$lon0="";

$dotSize=2;



while($row = mysql_fetch_array($result))

{

/*$lat111=getPixelValueofLat($row[0]);

$lat1=$lat111/100000;

$lon111=getPixelValueofLong($row[1]);

$lon1=$long111/100000;*/



$lat1=getPixelValueofLat($row[0]);

$lon1=getPixelValueofLong($row[1]);



if($lat0<>"" and $lon0<>"")

{

// ImageLine($im,$lon0,$lat0,$lon1,$lat1,${$color[$i%$col]}); //ploting a graph in different colors

// ImagePoints($im,$lon0,$lat0,$lon1,$lat1,${$color[$i%$col]});



imagefilledarc($im,$lon1,$lat1, $dotSize, $dotSize, 0, 360, $colorRed, IMG_ARC_PIE);

}


$lat0=getPixelValueofLat($row[0]);

$lon0=getPixelValueofLong($row[1]);

}



// Output graph and clear image from memory

imagepng($im);

imagedestroy($im);

mysql_free_result($result);

?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Re: pls ck my code

Post by volka »

shradhaparab wrote:can any one check and tell me wat is wrong in my code
You might want to tell us first what it is supposed to do and what it is actually doing right now.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: pls ck my code

Post by Christopher »

And tell us which lines you think are causing the problem...
(#10850)
shradhaparab
Forum Newbie
Posts: 6
Joined: Fri May 09, 2008 6:50 am

Re: pls ck my code

Post by shradhaparab »

arborint wrote:And tell us which lines you think are causing the problem...
i think it is going wrong in map.php file where i am defining the values of latitude and longitude
define("MINLAT", -1288888);
define("MAXLAT", 2297888);
define("MINLONG", 4098989);
define("MAXLONG", 9999898);
define("GRIDSIZE", 10);


than again in graph.php i plot a graph with dot

imagefilledarc($im,$lon1,$lat1, $dotSize, $dotSize, 0, 360, $colorRed, IMG_ARC_PIE);

here syntax of imagefilledarc () is in int and my latitude -longitude values are in lakhs so i think it may give a problem because i think int will not take long int values
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: pls ck my code

Post by califdon »

You still haven't said why you think it is "going wrong." What is it that isn't working????????????
shradhaparab
Forum Newbie
Posts: 6
Joined: Fri May 09, 2008 6:50 am

Re: pls ck my code

Post by shradhaparab »

califdon wrote:You still haven't said why you think it is "going wrong." What is it that isn't working????????????

hi ..........

i have first taken one png file which contains only graph and it is called in map.php file.
In map.php file i am calling the image and defining all values
eg.


<?php
//define constants
define("MAPFILE","testmap.png");

define("MINX",0);
define("MAXX",699+MINX);
define("MINY", 0);
define("MAXY", 419+MINY);

define("MINLAT", -1210000);
define("MAXLAT", 2210000);
define("MINLONG", 5100000);
define("MAXLONG", 9310000);
define("GRIDSIZE", 10);
?>

and then wrote the function to change values to Pixel.

note: i think the problem is in defining the latitude-longitude constant values and map.php file is called in graph.php file . in graph file the function is written to plot the graph
ie. imagefilledarc($im,$lon1,$lat1, $dotSize, $dotSize, 0, 180, $colorRed, IMG_ARC_PIE);
here syntax of the function is in terms of integer and my value is crossing the limit of interger i feel because my values stored are in terms of lakhs


2nd file is graph.php, in this file i am calling map.php file .
In this file i am taking the values which user has entered and form a query a fetch it from the database and plot a dot graph.

plot is coming correct but one thick black border comes in middle which is not correct and should not come .i want that black border should not come .
User avatar
lafever
Forum Commoner
Posts: 99
Joined: Sat Apr 05, 2008 2:03 pm
Location: Taylor, MI

Re: pls ck my code

Post by lafever »

Don't double post dude.
Post Reply