Создание метки времени KML из php - PullRequest
0 голосов
/ 01 апреля 2012

Я пытаюсь выделить точку KML с отметкой времени. Вывод MySQL выглядит следующим образом:

KML_time,coordinates
2012-3-26T04:36:39-01:00,"9.92016904,57.04809917,0"
2012-3-26T04:36:54-01:00,"9.92017704,57.04809437,0"
2012-3-26T04:37:08-01:00,"9.92011376,57.04819547,0"

Я сделал другой php-скрипт для создания KML, который работает нормально, но по какой-то причине этот продолжает ничего не делать. PHP-код выглядит так:

<?php
require('../db_conf2.php');

// Opens a connection to a MySQL server
$connection = mysql_connect ($server, $username, $password);

if (!$connection) 
{
   die('Not connected : ' . mysql_error());
}

// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);

if (!$db_selected) 
{
  die ('Can\'t use db : ' . mysql_error());
}

// Select all the rows in the markers table

$query_trips = "SELECT KML_time, GROUP_CONCAT(lon, ',', lat, ',', '0' ORDER BY ts DESC SEPARATOR ' ') AS coordinates FROM demo_timespan GROUP BY id";

$result_trips = mysql_query($query_trips);
if (!$result_trips) 
{
  die('Invalid query: ' . mysql_error());
}

// Start KML file, create parent node
$dom = new DOMDocument('1.0','UTF-8');

//Create the root KML element
$node = $dom->createElementNS('http://www.opengis.net/kml/2.2','kml');
$dom->appendChild($node);

//Create a Document element and append it to the KML element
$documentNode = $dom->createElement('Document');
$node->appendChild($documentNode);

//Create a hiker icon Style element and append it to the Document
$styleNode = $dom->createElement('Style');
$documentNode->appendChild($styleNode);
$styleNode->setAttribute('id','hiker-icon');

$iconStyleNode = $dom->createElement('IconStyle');
$styleNode->appendChild($iconStyleNode);

$iconNode = $dom->createElement('Icon');
$iconStyleNode->appendChild($iconNode);
$hrefNode = $dom->createElement('href', 'http://maps.google.com/mapfiles/ms/icons/hiker.png');
$iconNode->appendChild($hrefNode);

//Create a check-hide-children Style element and append it to the KML element
$styleNode = $dom->createElement('Style');
$documentNode->appendChild($styleNode);
$styleNode->setAttribute('id','check-hide-children');

$ListStyleNode = $dom->createElement('ListStyle');
$styleNode->appendChild($ListStyleNode);

$listItemTypeNode = $dom->createElement('listItemType', 'checkHideChildren');
$ListStyleNode->appendChild($listItemTypeNode);


//Create a check-hide-children URL element and append it to the KML element
$styleUrlNode = $dom->createElement('styleUrl', '#check-hide-children');
$documentNode->appendChild($styleUrlNode);


//Iterate through the MySQL results
while ($row_trip = mysql_fetch_assoc($result_trips))
{

//Create a Placemark and append it to the document
$placenode = $dom->createElement('Placemark');
$documentNode->appendChild($placenode);

//Create a Timestamp and append it to the PlaceMark
$Timestampnode = $dom->createElement('Timestamp');
$placeNode->appendChild($Timestampnode);

//Create a When and append it to the Timestamp
$whenNode = $dom->createElement('when',$row_trip['KML_time']);
$Timestampnode->appendChild($whenNode);

//Create a StyleUrl and append it to the PlaceMark
$styleURLNode= $dom->createElement('styleUrl', '#hiker-icon');
$placeNode->appendChild($styleURLNode);

//Create a Point element
$PointNode = $dom->createElement('Point');
$placeNode->appendChild($PointNode);
//Create a coordinates element and give it the value of the lng and lat columns from the results
$coorNode = $dom->createElement('coordinates',$row_trip['coordinates']);
$PointNode->appendChild($coorNode);

}
$dom->saveXML();

//assign the KML headers. 
header('Content-type: application/vnd.google-earth.kml+xml');

$dom->save("../store_kml/Timespan.kml");
?>

Пожалуйста, помогите, прежде чем это сделает меня сумасшедшим!


Это php-скрипт, который я использую для создания полилиний, и он прекрасно работает. Поэтому я не могу понять, почему другие не работают.

<?php
require('../db_conf2.php');

// Opens a connection to a MySQL server
$connection = mysql_connect ($server, $username, $password);

if (!$connection) 
{
   die('Not connected : ' . mysql_error());
}

// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);

if (!$db_selected) 
{
  die ('Can\'t use db : ' . mysql_error());
}

// Select all the rows in the markers table

$query_trips = "SELECT trip_id, type, mood, why, GROUP_CONCAT(lon, ',', lat, ',', '0' ORDER BY ts DESC SEPARATOR ' ') AS coordinates FROM data_demo WHERE lat>50 AND lon>8 GROUP BY trip_id";

$result_trips = mysql_query($query_trips);
if (!$result_trips) 
{
  die('Invalid query: ' . mysql_error());
}

// Start KML file, create parent node
$dom = new DOMDocument('1.0','UTF-8');

//Create the root KML element and append it to the Document
$node = $dom->createElementNS('http://www.opengis.net/kml/2.2','kml');
$dom->appendChild($node);

//Create a Document element and append it to the KML element
$dNode = $dom->createElement('Document');
$node->appendChild($dNode);

//Create a gå Style element and append it to the KML element
$styleNode = $dom->createElement('Style');
$dNode->appendChild($styleNode);
$styleNode->setAttribute('id','gå');

$lineStyleNode = $dom->createElement('LineStyle');
$styleNode->appendChild($lineStyleNode);

$colorNode = $dom->createElement('color', 'AABF3900');
$lineStyleNode->appendChild($colorNode);
$widthNode =$dom->createElement('width','6');
$lineStyleNode->appendChild($widthNode);

//Create a cykel Style element and append it to the KML element
$styleNode = $dom->createElement('Style');
$dNode->appendChild($styleNode);
$styleNode->setAttribute('id','cykel');

$lineStyleNode = $dom->createElement('LineStyle');
$styleNode->appendChild($lineStyleNode);

$colorNode = $dom->createElement('color', 'AA16BF00');
$lineStyleNode->appendChild($colorNode);
$widthNode =$dom->createElement('width','6');
$lineStyleNode->appendChild($widthNode);

//Create a kollektiv Style element and append it to the KML element
$styleNode = $dom->createElement('Style');
$dNode->appendChild($styleNode);
$styleNode->setAttribute('id','kollektiv');

$lineStyleNode = $dom->createElement('LineStyle');
$styleNode->appendChild($lineStyleNode);

$colorNode = $dom->createElement('color', 'AA00BFAC');
$lineStyleNode->appendChild($colorNode);
$widthNode =$dom->createElement('width','6');
$lineStyleNode->appendChild($widthNode);

//Create a bil Style element and append it to the KML element
$styleNode = $dom->createElement('Style');
$dNode->appendChild($styleNode);
$styleNode->setAttribute('id','bil');

$lineStyleNode = $dom->createElement('LineStyle');
$styleNode->appendChild($lineStyleNode);

$colorNode = $dom->createElement('color', 'AA9600BF');
$lineStyleNode->appendChild($colorNode);
$widthNode =$dom->createElement('width','6');
$lineStyleNode->appendChild($widthNode);




//Iterate through the MySQL results
while ($row_trip = mysql_fetch_assoc($result_trips))
{
//Create a Placemark and append it to the document
$placeNode = $dom->createElement('Placemark');
$dNode->appendChild($placeNode);

//Create an id attribute and assign it the value of id column
$placeNode->setAttribute('id','linestring' . $row_trip['trip_id'] . '');

//Create name, description, and address elements and assign them the values of 
//the name, type, and address columns from the results

$nameNode = $dom->createElement('name','Tur nummer: '. $row_trip['trip_id'] .'');
$placeNode->appendChild($nameNode);
$descNode= $dom->createElement('description', '' . $row_trip['mood'] . ' '. $row_trip['type'] .'tur fordi "'. $row_trip['why'] .'".');
$placeNode->appendChild($descNode);
$styleURLNode= $dom->createElement('styleUrl', '#' . $row_trip['type'] . '');
$placeNode->appendChild($styleURLNode);

//Create a LineString element
$lineNode = $dom->createElement('LineString');
$placeNode->appendChild($lineNode);
$exnode = $dom->createElement('tessellate', '1');
$lineNode->appendChild($exnode);
$almodenode =$dom->createElement(altitudeMode,'relativeToGround');
$lineNode->appendChild($almodenode);

//Create a coordinates element and give it the value of the lng and lat columns from the results
$coorNode = $dom->createElement('coordinates',$row_trip['coordinates']);
$lineNode->appendChild($coorNode);


}
$dom->saveXML();

//assign the KML headers. 
header('Content-type: application/vnd.google-earth.kml+xml');

$dom->save("../store_kml/PolylineType.kml");
?>

Ответы [ 2 ]

0 голосов
/ 02 апреля 2012

Не думаю, что вы правильно создаете метку времени. Во-первых, правильный синтаксис - TimeStamp (не Timestamp), и вам может потребоваться заключить его в TimePrimitive

так код должен выглядеть как

       $Timestampnode = $dom->createElement('TimeStamp');

и, возможно, есть

       $TimePrimitivenode = $dom->createElement('TimePrimitive');

, который содержит метку времени

Редактировать: Похоже, ваша временная метка тоже может быть неправильной. Если включить секунды, я думаю, вам нужно либо добавить «Z» в конце, чтобы указать UTC, либо добавить что-то вроде «+03: 00», чтобы указать, как преобразовать время в UTC. ссылка

0 голосов
/ 01 апреля 2012
$query_trips = "SELECT KML_time, GROUP_CONCAT(lon, ',', lat, ',', '0' ORDER BY ts DESC SEPARATOR ' ') AS coordinates FROM demo_timespan GROUP BY id";

Вероятно, это ГДЕ должно быть в нем ..

   $query_trips = "SELECT KML_time, GROUP_CONCAT(lon, ',', lat, ',', '0' ORDER BY ts DESC SEPARATOR ' ') AS coordinates FROM demo_timespan WHERE lat>50 AND lon>8 GROUP BY id";

или только это

   $query_trips = "SELECT KML_time, GROUP_CONCAT(coordinates) AS coordinates FROM demo_timespan ORDER BY id";

Извините, я неправильно понял, чего вы пытаетесь достичь с помощью координат CONCAT, слишком много чего-то другого,Усталый.Так как другой запрос делает это, угадайте, где отсутствует lat> 50 AND lon> 8.Все выглядит хорошо.

...