Hi Stefan. Geometry Outputs[1] functions (ST_As*) allow you output geometric fields as geometric representations. ST_AsKML do not return full KML documents, but descendant objects of <Geometry>[2] abstract object in KML.
This is a best expression of your query: SELECT ST_AsKML(the_geom) FROM my_spatial_table WHERE .... [1] http://www.postgis.org/documentation/manual-1.4/ch07.html#Geometry_Outputs [2] http://code.google.com/intl/en/apis/kml/documentation/kmlreference.html#geometry Eduin Yesid Carrillo Vega Ingeniero Civil, Esp. Sistemas de Información Geográfica Grupo IDE & GIG Centro de Investigación y Desarrollo en Información Geográfica Instituto Geográfico Agustín Codazzi - IGAC Cr 30 48-51 Tel +57 1 3694000 ext 4305 Bogotá D.C., Colombia On Wed, Jul 15, 2009 at 2:44 AM, Stefan Schwarzer<[email protected]> wrote: > Ah, thanks a lot! That sounds great! > However, when inserting the function and executing this: > SELECT askml('my_title', 'description', collect(the_geom)) FROM (SELECT > c.the_geom FROM countries_view AS c) AS foo > I get this error: > > ERROR: geometry_to_kml: 'GeometryCollection' geometry type not > supported > by Google Earth > CONTEXT: SQL function "askml" statement 1 > PL/pgSQL function "askml" line 21 at assignment > > If I understand it correctly from this conversation, I'd need the latest > version of Postgis to solve that issue, right? > Thanks for your valuable help, > Stefan > On Jul 14, 2009, at 5:50 PM, Kevin Neufeld wrote: > > 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 > > > _______________________________________________ > 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
