Features templating

Create features templates for GeoJSON

Enter the Features Templating section on GeoServer user interface, and click on Add new. Configure the template info as the following example:

../../_images/features_templates01.png

Set the template editor content with this JSON template:

{
   "$source":"st:MeteoStationsFeature",
   "Identifier":"${@id}",
   "geometry":"${st:position}",
   "properties":{
   "Name":"${st:common_name}",
   "Code":"$${strConcat('STATION-', xpath('st:code'))}",
   "Location":"$${toWKT(xpath('st:position'))}",
   "Temperatures":[
      {
         "$source":"st:meteoObservations/st:MeteoObservationsFeature",
         "$filter":"xpath('st:meteoParameters/st:MeteoParametersFeature/st:param_name') = 'temperature'"
      },
      {
         "Timestamp": "${st:time}",
         "Value": "${st:value}"
      }
   ],
   "Pressures":[
      {
         "$source":"st:meteoObservations/st:MeteoObservationsFeature",
         "$filter":"xpath('st:meteoParameters/st:MeteoParametersFeature/st:param_name') = 'pressure'"
      },
      {
         "Timestamp": "${st:time}",
         "Value": "${st:value}"
      }
   ],
   "Winds_speed":[
      {
         "$source":"st:meteoObservations/st:MeteoObservationsFeature",
         "$filter":"xpath('st:meteoParameters/st:MeteoParametersFeature/st:param_name') = 'wind speed'"
      },
      {
         "Timestamp": "${st:time}",
         "Value": "${st:value}"
      }
   ]
   }
}

Then click on save.

Create features templates for GML

Enter the Features Templating section on GeoServer user interface, and click on Add new. Configure the template info as the following example:

../../_images/features_templates02.png

Set the template editor content with this XML template:

<gft:Template>
   <gft:Options>
      <gft:Namespaces xmlns:st="http://www.stations.org/1.0"/>
   </gft:Options>
   <st:MeteoStations gml:id="${@id}">
   <st:code>$${strConcat('Station_',st:code)}</st:code>
   <st:name>${st:common_name}</st:name>
   <st:geometry>${st:position}</st:geometry>
   <st:temperature gft:isCollection="true" gft:source="st:meteoObservations/st:MeteoObservationsFeature" gft:filter="xpath('st:meteoParameters/st:MeteoParametersFeature/st:param_name') = 'temperature'">
   <st:Temperature>
      <st:time>${st:time}</st:time>
      <st:value>${st:value}</st:value>
   </st:Temperature>
   </st:temperature>
   <st:pressure gft:isCollection="true" gft:source="st:meteoObservations/st:MeteoObservationsFeature"  gft:filter="xpath('st:meteoParameters/st:MeteoParametersFeature/st:param_name') = 'pressure'">
   <st:Pressure>
      <st:time>${st:time}</st:time>
      <st:value>${st:value}</st:value>
   </st:Pressure>
   </st:pressure>
   <st:wind_speed gft:isCollection="true" gft:source="st:meteoObservations/st:MeteoObservationsFeature"  gft:filter="xpath('st:meteoParameters/st:MeteoParametersFeature/st:param_name') = 'wind speed'">
   <st:Wind_speed>
      <st:time>${st:time}</st:time>
      <st:value>${st:value}</st:value>
   </st:Wind_speed>
   </st:wind_speed>
   </st:MeteoStations>
   </gft:Template>

Then click on save.

Configure the features templates rules on the layer

Open GeoServer Admin UI and Enter the Layers page, find the st:MeteoStationsFeature layer. Click on Features Templating tab and add the following rules:

../../_images/features_templates03.png