As you've seen, there is the ST_AsKML command (http://postgis.refractions.net/documentation/manual-svn/ST_AsKML.html) that will convert a single geometry to KML.

All you need to do is add some xml tags before the export geometry tag and 
again after, closing the document.

Here's an example of a simple wrapper that does this inside the database, 
though you'd probably want to do this in PHP:
http://lists.refractions.net/pipermail/postgis-users/attachments/20070914/7a02d424/askml.sql

Example use case:
SELECT askml('my_title', 'description', collect(the_geom))
FROM my_spatial_table
WHERE ....

yields something like:
<?xml version='1.0' encoding='UTF-8'?>
<kml xmlns='http://earth.google.com/kml/2.1'>
<Document>
<name>'my_title'</name>
<description>'description'</description>

<Style id='defaultStyle'>
  <LineStyle>
    <color>ff00ff00</color>
    <width>1</width>
  </LineStyle>
  <PolyStyle>
    <color>5f00ff00</color>
  </PolyStyle>
</Style>

<Placemark>
  <styleUrl>#defaultStyle</styleUrl>
  <MultiGeometry>
    <Point>
      <coordinates>-122.319,47.164</coordinates>
    </Point>
    <Point>
      <coordinates>-122.272,47.067</coordinates>
    </Point>
  </MultiGeometry>
</Placemark>

</Document>
</kml>

Cheers,
Kevin



Stefan Schwarzer wrote:
Hi there,

I made a tour on Google to look around if there exist some KML export tool. I've seen the Set_AsKML command; I've seen this <http://postgis.refractions.net/pipermail/postgis-users/2007-September/017070.html> dicussion; and have found that someone wrote a script <http://postgis3d.blogspot.com/2007/12/googleearth-export.html> for postgis; and a phyton script <http://dev.riverchange.org/google_earth/genshi_template.kml>. But it seems that there is no easy-way-to-go export/wrapper script, enabling for example the execution of pgsql2kml...

Or can someone give be a hint how to develop a KML export for a PHP based Data Portal?

Thanks for any help,

Stef


------------------------------------------------------------------------

_______________________________________________
postgis-users mailing list
[email protected]
http://postgis.refractions.net/mailman/listinfo/postgis-users
_______________________________________________
postgis-users mailing list
[email protected]
http://postgis.refractions.net/mailman/listinfo/postgis-users

Reply via email to