array(),
"unique_id_array" => array(),
"name_array" => array(),
"latitude_array" => array(),
"longitude_array" => array(),
"coord_accuracy_array" => array(),
"begin_date_array" => array(),
"end_date_array" => array()
);
private $point_count = 0;
private $input_file;
private $output_file;
private $coordinates_elements;
private $coordinates_element;
private $coordinates_element_string;
private $coords_atomised;
private $return_string;
public function readPointsFromKMLFile($input_file_path) {
$this->point_count = 0;
// read GML input file
$this->input_file = new DOMDocument();
$this->input_file->load("$input_file_path");
// Look for placemarks
$this->coordinates_elements = $this->input_file->getElementsByTagName("coordinates");
foreach ($this->coordinates_elements as $this->point_element) {
$this->points_array["id_array"][$this->point_count] = $this->point_count;
// pos in GML is given as longitude (comma) latitude (comma) height
// but we don't take height into account here
$this->coordinates_element_string = $this->point_element->nodeValue;
$this->coords_atomised = explode(",", $this->coordinates_element_string);
$this->points_array["longitude_array"][$this->point_count] = $this->coords_atomised[0];
$this->points_array["latitude_array"][$this->point_count] = $this->coords_atomised[1];
$this->point_count++;
} // foreach
return($this->points_array);
} // function readPointsFromKMLFile
public function writePointsToKMLFile_asWaypoints($points_array,$structure_array,$output_file_path,$point_colour="blue") {
$this->point_count = 0;
$this->return_string = '
some_name.kml
normal
#sn_pushpinshighlight
#sh_pushpins
Temporary Places1';
foreach ($points_array["unique_id_array"] as $this->point_element) {
$this->return_string .= ''
. $points_array ["unique_id_array"][$this->point_count]
. ''
. $points_array ["longitude_array"][$this->point_count]
. ''
. $points_array ["latitude_array"][$this->point_count]
. '01780.819342437584
18.830628593075890.006014305373924733
#msn_ylw-pushpin_copy0'
.$points_array ["longitude_array"][$this->point_count].","
.$points_array ["latitude_array"][$this->point_count].",0"
.'';
$this->point_count++;
} //foreach
$this->return_string .= '';
if (!file_exists($output_file_path)) {
$this->output_file = fopen("$output_file_path","x");
} else {$this->output_file = fopen("$output_file_path","w");}
fwrite ($this->output_file,$this->return_string);
} // function writePointsToKMLFile_asWaypoints
public function writePointsToKMLFile_asPath($points_array,$structure_array,$output_file_path,$line_colour="7f00ff00") {
$this->point_count = 0;
$this->return_string = '
Paths
Examples of paths. Note that the tessellate tag is by default
set to 0. If you want to create tessellated lines, they must be authored
(or edited) directly in KML.
Absolute Extruded
Transparent green wall with yellow outlines
#yellowLineGreenPoly
0
1
relativeToGround';
foreach ($points_array["unique_id_array"] as $this->point_element) {
// coordinates in kml are given as longitude (comma) latitude (comma) altitude
if ($this->point_count <> 0) {$this->return_string .= ''; }
$this->return_string .= $points_array ["longitude_array"][$this->point_count].",";
$this->return_string .= $points_array ["latitude_array"][$this->point_count].",0";
$this->return_string .= "\n";
$this->point_count++;
}
$this->return_string .= '';
if (!file_exists($output_file_path)) {
$this->output_file = fopen("$output_file_path","x");
} else {$this->output_file = fopen("$output_file_path","w");}
fwrite ($this->output_file,$this->return_string);
} // writePointsToKMLFile_asPath
} // class KML_Module
?>