I was wondering if there is a good way to check to see if a property exists on a particular feature layer in GeoServer? My use case is that I have a bunch of features I want to display on a map. Some of the feature layers will have a date property associated with them. If they have a date property I want to be able to display a control to filter the features shown by date. I noticed that WFS has an operation called GetPropertyValue which will return an exception if the property doesn't exist. However, if it does it (as expected) returns the value for that property for all features which can be very slow. My general algorithm is as follows:

var wfsLayer = new OpenLayers.Layer.Vector('MyVectorLayer', {
    strategies: [new Openlayers.Strategy.BBOX()],
    protocol: new OpenLayers.Protocol.WFS({
        url: 'http://mygeoserver/geoserver/wfs',
        featureType: 'MyVectorLayer',

// if layer has date property (this is the part I need help with)
    var dateFilter = new OpenLayers.Filter.Comparison({
        type: OpenLayers.Filter.Comparison.BETWEEN,
        property: 'date',
        lowerBoundary: startDateVal,
        upperBoundary: endDateVal
    wfsLayer.filter = dateFilter;
// end if

1 Answer 1


You can utilize the WFS service requests DescribeFeatureType to identify all the attributes and their types for a specific typeName. This is probably the most appropriate way to identify whether there is a datetime field on your layer of interest. There is no existing WFS DescribeFeatureType example for OpenLayers, but I slightly modified the WMS DescribeLayer example to show how you could accomplish this.

Here is the HTML/JS example:

<!DOCTYPE html>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <title>OpenLayers WFSDescribeFeatureType Parser Example</title>
    <link rel="stylesheet" href="style.css" type="text/css">
    <script src="../OpenLayers.js"></script>
    <script type="text/javascript">
        function parseData(req) {
          format = new OpenLayers.Format.WFSDescribeFeatureType();
          html = "<br>";
          resp = format.read(req.responseText);
          var featureTypes = resp.featureTypes;
          for(var i = 0; i < featureTypes.length; i++) {
        html += "Layer: typeName: "+ featureTypes[i].typeName+",";
        for (var j = 0; j < featureTypes[i].properties.length; j++) {
                html += "<ul>";
                html += "<li>name: " + featureTypes[i].properties[j].name + "</li>";
                html += "<li>localType: " + featureTypes[i].properties[j].localType + "</li>";
                html += "<li>nillable: " + featureTypes[i].properties[j].nillable + "</li>";
                html += "</ul>"
          document.getElementById('output').innerHTML = html;
        function load() {
                url: "xml/wfsdescribefeaturetype.xml",
                success: parseData
  <body onload="load()">
      <h1 id="title">WFSDescribeFeatureType Parser Example</h1>

      <div id="tags">
          wfsdescribefeaturetype, parser, cleanup

      <p id="shortdesc">
          Demonstrate the operation of the WFSDescribeFeatureType parser.

      <div id="output"></div>

      <div id="docs">
          <p>This script reads data from a file and parses out attributes on a typeName,
          appending them to a HTML string with markup tags. This markup is
          dumped to an element in the page.</p>

Here is also the xml file that I used as input:

<?xml version="1.0" encoding="UTF-8"?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:geonode="http://www.geonode.org/" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" targetNamespace="http://www.geonode.org/">
  <xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://localhost:8080/geoserver/schemas/gml/2.1.2/feature.xsd"/>
  <xsd:complexType name="modis_fire_2013_365_conusType">
      <xsd:extension base="gml:AbstractFeatureType">
          <xsd:element maxOccurs="1" minOccurs="0" name="the_geom" nillable="true" type="gml:PointPropertyType"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="AREA" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="PERIMETER" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="FIRE_" nillable="true" type="xsd:long"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="FIRE_ID" nillable="true" type="xsd:long"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="LAT" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="LONG" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="DATE" nillable="true" type="xsd:dateTime"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="JULIAN" nillable="true" type="xsd:int"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="GMT" nillable="true" type="xsd:int"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="TEMP" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="SPIX" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="TPIX" nillable="true" type="xsd:double"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="SRC" nillable="true" type="xsd:string"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="SAT_SRC" nillable="true" type="xsd:string"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="CONF" nillable="true" type="xsd:int"/>
          <xsd:element maxOccurs="1" minOccurs="0" name="FRP" nillable="true" type="xsd:double"/>
  <xsd:element name="modis_fire_2013_365_conus" substitutionGroup="gml:_Feature" type="geonode:modis_fire_2013_365_conusType"/>

I placed my html in the openlayers/examples directory of the source tree and the xml in openlayers/examples/xml directory. I then just served it up using apache.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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