Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm running simple local mapping service based on PostGIS/GeoServer/OpenLayers stack.

Following opengeo tutorial I've tied click events in OpenLayers to WMS GetFeatureInfo call using:

    map.events.register('click', map, function (e) {
        var url = "http://localhost:1979/geoserver/wms" 
          + "?REQUEST=GetFeatureInfo"
          + "&EXCEPTIONS=application/vnd.ogc.se_xml"
          + "&BBOX=" + map.getExtent().toBBOX()
          + "&X=" + e.xy.x
          + "&Y=" + e.xy.y
          + "&INFO_FORMAT=text/html"
          + "&QUERY_LAYERS=MYDATA:MYLAYER"
          + "&LAYERS=MYDATA:MYLAYER"
          + "&FEATURE_COUNT=5"
          + "&SRS=EPSG:3857"
          + "&STYLES="
          + "&WIDTH=" + map.size.w
          + "&HEIGHT=" + map.size.h;
        window.open(url,
          "getfeatureinfo",
          "location=0,status=0,scrollbars=1,width=800,height=125"
        );
      });

I've used GeoServer's FreeMarker templates to format the response correctly. The problem I have is that the response I get returns all of the fields from the layer.

Is there a way to select the ones that are relevant to the user?

share|improve this question
add comment

4 Answers

up vote 4 down vote accepted

Doesn't look good (source):

... GetFeatureInfo [...] is a WMS request and WFS. [...] One difference in their behaviour is that Geoserver sends always all the attributes with GetFeatureInfo but with WFS the list of attributes can be given in the request.

You could create a view that contains only the attributes your user wants to/should see and serve that through Geoserver.

An alternative would be to adjust die GetFeatureInfo template.

share|improve this answer
2  
displaying or not displaying is one thing but radek want to return only some fields values. It makes a big difference regarding transfered data and security aspects. –  simo Feb 10 '11 at 14:09
1  
That's why my first suggestion was to create a view. –  underdark Feb 10 '11 at 14:33
    
More on using VIEWs here. –  radek Oct 10 '11 at 15:36
add comment

Just don't include the fields you don't want in your freemarker template. See http://docs.geoserver.org/trunk/en/user/tutorials/GetFeatureInfo/index.html#custom-templates

share|improve this answer
    
Good link, there is some real good documentation on the Geoserver site - This example I found useful (with a little fiddling around of course)for returning only the fields I wanted. –  Ando Jun 30 '11 at 11:17
add comment

You can do this using the GeoServer propertyName WMS request parameter:

http://docs.geoserver.org/stable/en/user/services/wms/vendor.html#propertyname

share|improve this answer
add comment

What about this?

Also, for this to return attributes (and not just the layer name and feature id) you have to add "ows_include_items" "attribute1, attribute2, ..., attributeN" or "ows_include_items" "all" to the metadata section of your WMS layer's map file entry.

From : http://trac.osgeo.org/openlayers/wiki/GetFeatureInfo

share|improve this answer
    
But Radek uses Geoserver, not UMN Mapserver, so there is no map file. –  underdark Feb 10 '11 at 13:17
1  
I've seen that. I've never used geoserver but I guess there is one way to set metadata as well, no? –  simo Feb 10 '11 at 13:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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