Ejemplo n.º 1
0
function tree2kml($obj, $default_labels = 'taxa')
{
    $t = new Tree();
    $t->Parse($obj->tree->newick);
    $t->BuildWeights($t->GetRoot());
    // compute KML coordinates
    $attr = array();
    $td = new KmlTreeDrawer($t, $attr);
    $td->CalcCoordinates();
    // raw labels (OTUs)
    //	$port->StartGroup('otu', (('otu' == $default_labels) || !isset($obj->translations)) );
    $kml = '';
    $kml .= "<?xml version =\"1.0\" encoding=\"UTF-8\"?>\n";
    $kml .= "<kml xmlns=\"http://earth.google.com/kml/2.1\">\n";
    $kml .= "<Document>\n";
    $kml .= "<Style id=\"treeLine\">\n";
    $kml .= "<LineStyle><color>7fffffff</color><width>2</width></LineStyle>\n";
    $kml .= "</Style>\n";
    $kml .= "<Style id=\"whiteBall\">\n";
    $kml .= "<IconStyle>\n";
    $kml .= "<Icon>\n";
    $kml .= "<href>http://iphylo.org/~rpage/phyloinformatics/images/whiteBall.png</href>\n";
    $kml .= "</Icon>\n";
    $kml .= "</IconStyle>\n";
    $kml .= "<LineStyle>\n";
    $kml .= "<width>2</width>\n";
    $kml .= "</LineStyle>\n";
    $kml .= "</Style>\n";
    $td->Draw(null);
    $kml .= $td->kml;
    $kml .= "<Folder>\n";
    $kml .= "<name>Labels</name>\n";
    // labels
    $ni = new NodeIterator($t->getRoot());
    $q = $ni->Begin();
    while ($q != NULL) {
        if ($q->IsLeaf()) {
            $kml .= "<Placemark>\n";
            $kml .= "<name>" . $q->Getlabel() . "</name>\n";
            $kml .= "<styleUrl>#whiteBall</styleUrl>\n";
            $kml .= "<Point>\n";
            $kml .= "<altitudeMode>absolute</altitudeMode>\n";
            $kml .= "<extrude>1</extrude>\n";
            $kml .= "<coordinates>\n";
            $kml .= $q->GetAttribute('long') . "," . $q->GetAttribute('lat') . "," . $q->GetAttribute('altitude') . "\n";
            $kml .= "</coordinates>\n";
            $kml .= "</Point>\n";
            $kml .= "</Placemark>\n";
        }
        $q = $ni->Next();
    }
    $kml .= "</Folder>\n";
    $kml .= "</Document>\n";
    $kml .= "</kml>\n";
    echo $kml;
}
Ejemplo n.º 2
0
function tree2kml($t)
{
    // compute KML coordinates
    $attr = array();
    $td = new KmlTreeDrawer($t, $attr);
    $td->CalcCoordinates();
    $kml = '';
    $kml .= "<?xml version =\"1.0\" encoding=\"UTF-8\"?>\n";
    $kml .= "<kml xmlns=\"http://earth.google.com/kml/2.2\">\n";
    $kml .= "<Document>\n";
    $kml .= "<Style id=\"treeLine\">\n";
    $kml .= "<LineStyle><color>7fffffff</color><width>2</width></LineStyle>\n";
    $kml .= "</Style>\n";
    $kml .= "<Style id=\"whiteBall\">\n";
    $kml .= "<IconStyle>\n";
    $kml .= "<Icon>\n";
    $kml .= "<href>http://iphylo.org/~rpage/phyloinformatics/images/whiteBall.png</href>\n";
    $kml .= "</Icon>\n";
    $kml .= "</IconStyle>\n";
    $kml .= "<LineStyle>\n";
    $kml .= "<width>2</width>\n";
    $kml .= "</LineStyle>\n";
    $kml .= "</Style>\n";
    $td->Draw(null);
    $kml .= $td->kml;
    $kml .= "<Folder>\n";
    $kml .= "<name>Labels</name>\n";
    // labels
    $ni = new NodeIterator($t->GetRoot());
    $q = $ni->Begin();
    while ($q != NULL) {
        if ($q->IsLeaf()) {
            $kml .= "<Placemark>\n";
            $kml .= "<name>" . $q->Getlabel() . "</name>\n";
            $kml .= "<styleUrl>#whiteBall</styleUrl>\n";
            $kml .= "<Point>\n";
            $kml .= "<altitudeMode>absolute</altitudeMode>\n";
            $kml .= "<extrude>1</extrude>\n";
            $kml .= "<coordinates>\n";
            $kml .= $q->GetAttribute('long') . "," . $q->GetAttribute('lat') . "," . $q->GetAttribute('altitude') . "\n";
            $kml .= "</coordinates>\n";
            $kml .= "</Point>\n";
            $kml .= "</Placemark>\n";
        }
        $q = $ni->Next();
    }
    $kml .= "</Folder>\n";
    $kml .= "</Document>\n";
    $kml .= "</kml>\n";
    return $kml;
}