Conversion tables A-K
  Conversion tables L-Z
  SPAM database query
  Reverse WHOIS utility
  North America area codes
  PHP Example forums

PHP example repository.

Web www.web-max.ca
Back to examples
GIS Mapping in PHP: Part 4

Another article which is taking a brief step back in time. The main point of this example is to show how you can use the functions we defined eariler to plot a number of points on a map instead of just a single one.

We are storing the points we want to plot ( as it happens a list of volcanoes ) in a text file. The records are CR/LF delimited. The columns in the list are separated with a space ( 0x20 ). For example -

54.6025 160.2825
-0.4 -91.1
54.6025 160.2825
40.85 14.2
54.6025 160.2825
38.4 14.9666667
52.6111111 158.0472222

To load the file into an array we are using the file function. This PHP function will load a CR/LF delimited file directly into an array, saving us a lot of overhead. To extract the columns we explode each element in the array.

To finish, we just add a loop to convert and plot each point in the array using our mighty getlocationcoords. The code here has been reduced - all the files you need to run and generate the example image are included in the ZIP file downloadable from the link below.

<?php

// We are assuming getlocationcoords is included somewhere else.

// First we load the text file containing the coordinated

$coord_array = file("vol.txt");

// This is our source raster file. For this example we are
// using a larger file

$im = imagecreatefromjpeg("earth_620.jpg");

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

$scale_x = imagesx($im);
$scale_y = imagesy($im);

// Loop though each element of the array loaded from the
// text file

foreach($coord_array as $value)
{

// Explode out the latitude and longitude coordinates

    $co = explode(" ",$value);

// And we have done all this before ......

    $pt = getlocationcoords($co[0], $co[1], $scale_x, $scale_y);
    imagefilledrectangle($im,$pt["x"]-1,
                         $pt["y"]-1,$pt["x"]+1,$pt["y"]+1,$red);
}

// Return the image as a JPEG - it would be @ 230k as PNG!

header("Content-Type: image/jpeg");
imagejpeg($im,"",80);
imagedestroy($im);

?>


 
Downloads

 article_4.zip

Related Links
Mapinfo
Microsoft Mappoint