Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exporting OpenLayers.Layer.WMS to GeoJSON / KML

I'm looking for a way to export a specific region of a WMS layer to some XML format (GeoJSON, GML, KML) using OpenLayers and Geoserver. I've found how to export feature objects with OpenLayers.Format.GeoJSON.write(), but this method only allows converting feature objects or geometry objects.

An example of my idea: I'm viewing a map of a certain country with a couple of WMS layers with some data. Then I zoom to a particular state of that country and I want to export what I'm viewing to GeoJSON or KML for use that in a desktop GIS application (like QGIS).

Does anyone know how to do this?

Thanks.

like image 564
Lucas Avatar asked Feb 03 '26 01:02

Lucas


1 Answers

GeoServer WMS can return data in KML format, since it's a styled format like SVG, but not in GeoJSON, which is instead generated by WFS, since it's just raw data. In order to return KML just make the same request you would have made for a PNG, but ask for "kml" as the output format

like image 74
Andrea Aime Avatar answered Feb 04 '26 16:02

Andrea Aime



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!