Search code examples
kmlpostgis

Postgis to KML, including color field


I would like to export a Postgis table to a KML file. I am using the ogr2ogr program for this, but my problem is that I want to include the color associated with each linestring in the output KML. Is this possible? Thank you


Solution

  • I do not believe that this is possible. You would need to write a plpgsql function to do this using the ST_AsKML function in postgis and concatenating the color attribute data around it or use the xml functions built into Postgres, see: http://www.postgresql.org/docs/9.1/static/functions-xml.html in conjunction with ST_AsKML. There is an interesting example here, http://www.postgresonline.com/journal/archives/267-Creating-GeoJSON-Feature-Collections-with-JSON-and-PostGIS-functions.html, of how to use ST_AsGeoJSON to add extra attributes other than just the coordinates to the output.

    There is also a Python library, from Google themselves, to manipulate KML, so this might be a good bet: http://googlegeodevelopers.blogspot.co.uk/2012/01/introducing-pykml-python-library-for.html

    I realize that this is not what you asked, but I hope this helps.