Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am currently generating a KML file dynamically from PHP and Mysql. One latitude / longitude point is being passed to the script. What I want to do now is create two triangle polygons from this point based upon a wind variable in the database. So if the wind is blowing 'S' then I want the triangle 'point' to start at the lat/long point variable, and build a polygon with the point of the triangle headed south towards the lat / lng. Can anyone share with me how this can be done? Here is my script:

// Selects all the rows in the markers table.
$query = 'SELECT lat, lng, waves, wave_secs, current_dir, pri_id AS id FROM kml';
$result = mysql_query($query);

if (!$result) 
{
die('Invalid query: ' . mysql_error());
}

// Creates the Document.
$dom = new DOMDocument('1.0', 'UTF-8');

// Creates the root KML element and appends it to the root document.
$node = $dom->createElementNS('http://earth.google.com/kml/2.1', 'kml');
$parNode = $dom->appendChild($node);

// Creates a KML Document element and append it to the KML element.
$dnode = $dom->createElement('Document');
$docNode = $parNode->appendChild($dnode);

// Iterates through the MySQL results, creating one Placemark for each row.
while ($row = @mysql_fetch_assoc($result))
{
// Creates a Placemark and append it to the Document.

$node = $dom->createElement('Placemark');
$placeNode = $docNode->appendChild($node);

// Creates an id attribute and assign it the value of id column.
$placeNode->setAttribute('id', 'placemark' . $row['id']);

// Create name, and description elements and assigns them the values of the name and address columns from the results.
$nameNode = $dom->createElement('name', 'Wave Height '.htmlentities(ceil($row['waves'] * 3.280)).' Feet');
$placeNode->appendChild($nameNode);
$descNode = $dom->createElement('description', 'Wave Duration ' .htmlentities($row['wave_secs']). ' Seconds');
$placeNode->appendChild($descNode);
$styleUrl = $dom->createElement('styleUrl', '#' . $row['current_dir'] . '-Style');
$placeNode->appendChild($styleUrl);

// Creates a Point element.
$pointNode = $dom->createElement('Point');
$placeNode->appendChild($pointNode);

// Creates a coordinates element and gives it the value of the lng and lat columns from the results.
$coorStr = $row['lng'] . ','  . $row['lat'];
$coorNode = $dom->createElement('coordinates', $coorStr);
$pointNode->appendChild($coorNode);
}

$kmlOutput = $dom->saveXML();
header('Content-type: application/vnd.google-earth.kml+xml');
echo $kmlOutput;
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.