3

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.

olly_uk
  • 11,559
  • 3
  • 39
  • 45
Lucas
  • 347
  • 4
  • 11

2 Answers2

2

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

Andrea Aime
  • 1,706
  • 11
  • 16
  • Thanks @Andrea Aime. I'm trying that, but I have another problem. When I export a kml with more than 1 geometry in it, Qgis load the kml but it doesn't display the kml. When a look the properties, I see that there is no geometry type associated. – Lucas Sep 13 '12 at 15:43
0

Web Map Service (WMS) only deals with images. To 'export' as XML you would need to use something like Web Map Context (WMC) as detailed here :

I'm not sure if Qgis supports the use of WMC though.

olly_uk
  • 11,559
  • 3
  • 39
  • 45
  • Thanks @olly_uk. Apparently, Qgis is implementing WMC. [http://hub.qgis.org/projects/17/wiki/QGISWebClientIdeas/annotate/1] – Lucas Sep 12 '12 at 15:41
  • So, Is there no chance to implement an export strategy to GeoJSON/KML using OpenLayers or Geoserver for WMS layers? I'm thinking on implementing my own strategy using directly tables of PostGIS. What do you think of that? Can it be worth? – Lucas Sep 12 '12 at 15:56
  • not sure either of those standards (although geojson isnt really a standard) could do it. Also how would you get qgis to understand your custom output? – olly_uk Sep 12 '12 at 15:58
  • Qgis supports GeoJSON, KML and GML formats. What I want is export the data that I'm seeing in the map in any format that can be used in a desktop GIS app. – Lucas Sep 12 '12 at 16:10
  • but without the back end wms information what would the geojson actually do? again wms returns only images, how can they be converted to json? – olly_uk Sep 12 '12 at 16:17
  • also qgis supports WMS import so is that not sufficient? – olly_uk Sep 12 '12 at 16:19
  • I understand you. I'd like not to access the entire WMS layer but to access only an specific region of it from Qgis. So, I thought that export that region was a good idea :) Also, I need the access to the data of the layer, and I don't have WFS because I provide my own service that connects directly with PostGIS (by performance issues). So, I'm going to think again the solution, but I imagine that the export strategy I'm going to implement in the server side. – Lucas Sep 12 '12 at 16:55