I'm trying to render tiles out of a KML file. Normally, I'd render tiles out of an planet.osm extract. For example, I'd select a tag using osmosis and then process it with osm2pgsql. Then I'd generate the tiles using Mapnik's python script and I'd serve them with OpenLayers.

Maintaining this structure, i.e. PostgreSQL (with PostGIS) and OpenLayers, I'd like to know what's the best way to do this starting from a kml file, rather than an osm one. An option would be to transform the kml file into an osm file. Another option would be to find something like kml2pgsql. I haven't found any questions nor ways to do this (I'm specially surprised this is not a duplicated question).

Do you know how to do this? (might be using something else, as far as it's supported in Linux and uses Postgresql - Openlayers).

Answer: I marked Andre answer as the final one because while I'm not using exactly what he said it put me in the right path. I ended up using TileMill rather than QGIS, but the process is practically the same...

  • Mapnik supports rendering KML files with OGR Plugin (built-in). Alternatively you can load KML on the client side with OpenLayers. Commented Jul 18, 2014 at 12:17

1 Answer 1


I usually do this using QGIS. I load the kml layer, save as shapefile and add the columns that are necessary for rendering.

Then I open a connection to my postgis database, delete everything inside the current view, and copy-and-paste the kml data into the postgis layer.

I have created a separate bboxdb inside postgis for such cases, so my original osm dataset is not disturbed.

Now I can use my Mapnik toolchain to render the tiles as usual.

  • I don't have much experience with QGIS. Can you see all that process being automated by something like a python script? (or at least the qgis part of it as I could prepare the database once to receive the data...)
    – zom-pro
    Commented Jul 16, 2014 at 20:29
  • Unfortunately, I have experience with QGIS, but did not yet get around to learn python. Alternatively, a batch script using GDAL ogr2ogr could do the same, once you have successfully got it working manually.
    – AndreJ
    Commented Jul 17, 2014 at 5:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.