Page 1 of 1

pls ck my code

Posted: Tue May 13, 2008 12:44 am
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);

?>

Re: pls ck my code

Posted: Tue May 13, 2008 2:20 am
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.

Re: pls ck my code

Posted: Tue May 13, 2008 2:29 am
by Christopher
And tell us which lines you think are causing the problem...

Re: pls ck my code

Posted: Tue May 13, 2008 2:34 am
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

Re: pls ck my code

Posted: Tue May 13, 2008 11:39 am
by califdon
You still haven't said why you think it is "going wrong." What is it that isn't working????????????

Re: pls ck my code

Posted: Tue May 13, 2008 10:59 pm
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 .

Re: pls ck my code

Posted: Wed May 14, 2008 1:05 am
by lafever
Don't double post dude.