When you add WFS data to your map, LuciadLightspeed automatically sends a WFS request to the WFS server with a spatial filter that matches the area that you are visualizing. You can also add your own filters to further restrict the data that you want to query and visualize.

By configuring an OGC Filter on the WFS model

One approach to add such a filter is to construct an OGC Filter with your filter criteria, and set it on the WFS model.

This example shows how you can add a filter for a US Cities WFS feature type. We want to query only those cities that have a name starting with "New":

// Create a WFS model for the WFS feature type 'cities' provided by the WFS server 'http://sampleservices.luciad.com/wfs'.
TLcdWFSProxyModel model = TLcdWFSProxyModel.Builder.newBuilder().server("http://sampleservices.luciad.com/wfs").featureTypeName("cities").build();

// We only want to query cities that have a name starting with "New".
// To achieve this, we can rely on the IsLike filter condition, which can compare a property with a value containing a wildcard.
TLcdOGCFilter filter = new TLcdOGCFilter(TLcdOGCFilterFactory.like(TLcdOGCFilterFactory.property("CITY"), "New*"));

// By setting an explicit filter on the WFS model, all future access to the WFS data will include the filter.
model.setFilter(filter);

You can also combine filter conditions. The following example extends the earlier example with an extra filter condition that specifies a search area. To apply both conditions together, the example combines them using a boolean filter condition that specifies an and relationship:

// We only want to query cities that are located within a specific area and that have a name starting with "New".
// To achieve this, we first create an IsLike filter condition and a bounding box spatial filter condition.
ILcdOGCCondition isLikeCondition = TLcdOGCFilterFactory.like(TLcdOGCFilterFactory.property("CITY"), "New*");
ILcdOGCCondition bboxCondition = TLcdOGCFilterFactory.bbox(new TLcdLonLatBounds(-75, 40, 10, 10), new TLcdGeodeticReference());
// Next, we create a boolean condition that combines both conditions with an 'and' relationship
// and use this to create the filter.
TLcdOGCFilter filter = new TLcdOGCFilter(TLcdOGCFilterFactory.and(isLikeCondition, bboxCondition));

By configuring an SLD on the WFS layer

Another approach is to define an OGC Filter within an SLD styling definition, and set it on the WFS layer. An SLD consists of one or more styling rules that define how to render the data. Each styling rule also has an optional scale range and OGC Filter that selects the data for that rule. Within a WFS environment, the main benefit of this SLD approach to filtering is that you can decide which data to query and visualize for each zoom level.

The following example shows an SLD that renders cities according to their population and the current zoom level.

Program: Using parameter value for channel selection
<?xml version='1.0' encoding='UTF-8'?>
<FeatureTypeStyle xmlns="http://www.opengis.net/se"
                  xmlns:ogc="http://www.opengis.net/ogc"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/filter/1.1.0/filter.xsd http://www.opengis.net/se http://schemas.opengis.net/se/1.1.0/FeatureStyle.xsd"
                  version="1.1.0">
  <Name>Cities with level of detail</Name>
  <Description>
    <Title>Cities with level of detail</Title>
    <Abstract>A style that renders city locations with different levels of detail depending on the population:
      - cities with a population greater than or equal to 1000000: always visible,
      - cities with a population between 500000 and 999999: visible at scale 1:30,000,000 and below,
      - cities with a population smaller than 500000: visible at scale 1:8,000,000 and below,
      Each of these visualization rules uses an appropriate size for the icon and text label.
    </Abstract>
  </Description>
  <Rule>
    <Name>large_scale_cities</Name>
    <Description>
      <Title>Large scale cities rule</Title>
      <Abstract>Rule to render a city location with a large icon and label
        when the population is greater than or equal to 1000000.</Abstract>
    </Description>
    <ogc:Filter>
      <ogc:PropertyIsGreaterThanOrEqualTo>
        <ogc:PropertyName>TOT_POP</ogc:PropertyName>
        <ogc:Literal>1000000</ogc:Literal>
      </ogc:PropertyIsGreaterThanOrEqualTo>
    </ogc:Filter>
    <PointSymbolizer>
      <Graphic>
        <Mark>
          <WellKnownName>circle</WellKnownName>
          <Fill>
            <SvgParameter name="fill">#666666</SvgParameter>
          </Fill>
          <Stroke>
            <SvgParameter name="fill">#CCCCCC</SvgParameter>
          </Stroke>
        </Mark>
        <Size>14.0</Size>
      </Graphic>
    </PointSymbolizer>
    <TextSymbolizer>
      <Label><ogc:PropertyName>CITY</ogc:PropertyName></Label>
      <Font>
        <SvgParameter name="font-family">Arial</SvgParameter>
        <SvgParameter name="font-size">16</SvgParameter>
      </Font>
      <Halo>
        <Radius>1</Radius>
        <Fill>
          <SvgParameter name="fill">#000000</SvgParameter>
        </Fill>
      </Halo>
      <Fill>
        <SvgParameter name="fill">#ffffff</SvgParameter>
      </Fill>
    </TextSymbolizer>
  </Rule>
  <Rule>
    <Name>medium_scale_cities</Name>
    <Description>
      <Title>Medium scale cities rule</Title>
      <Abstract>Rule to render a city location with a medium-sized icon and label
        when the population is between 500000 and 999999 and when the map scale
        is at most 1:30,000,000.</Abstract>
    </Description>
    <ogc:Filter>
      <ogc:PropertyIsBetween>
        <ogc:PropertyName>TOT_POP</ogc:PropertyName>
        <ogc:LowerBoundary>
          <ogc:Literal>500000</ogc:Literal>
        </ogc:LowerBoundary>
        <ogc:UpperBoundary>
          <ogc:Literal>999999</ogc:Literal>
        </ogc:UpperBoundary>
      </ogc:PropertyIsBetween>
    </ogc:Filter>
    <MaxScaleDenominator>3.0E7</MaxScaleDenominator>
    <PointSymbolizer>
      <Graphic>
        <Mark>
          <WellKnownName>circle</WellKnownName>
          <Fill>
            <SvgParameter name="fill">#666666</SvgParameter>
          </Fill>
          <Stroke>
            <SvgParameter name="fill">#CCCCCC</SvgParameter>
          </Stroke>
        </Mark>
        <Size>10.0</Size>
      </Graphic>
    </PointSymbolizer>
    <TextSymbolizer>
      <Label><ogc:PropertyName>CITY</ogc:PropertyName></Label>
      <Font>
        <SvgParameter name="font-family">Arial</SvgParameter>
        <SvgParameter name="font-size">14</SvgParameter>
      </Font>
      <Halo>
        <Radius>1</Radius>
        <Fill>
          <SvgParameter name="fill">#000000</SvgParameter>
        </Fill>
      </Halo>
      <Fill>
        <SvgParameter name="fill">#ffffff</SvgParameter>
      </Fill>
    </TextSymbolizer>
  </Rule>
  <Rule>
    <Name>small_scale_cities</Name>
    <Description>
      <Title>Small scale cities rule</Title>
      <Abstract>Rule to render a city location with a small icon and label
        when the population is smaller than 500000 and when the map scale
        is at most 1:8,000,000.</Abstract>
    </Description>
    <ogc:Filter>
      <ogc:PropertyIsLessThan>
        <ogc:PropertyName>TOT_POP</ogc:PropertyName>
        <ogc:Literal>500000</ogc:Literal>
      </ogc:PropertyIsLessThan>
    </ogc:Filter>
    <MaxScaleDenominator>8000000.0</MaxScaleDenominator>
    <PointSymbolizer>
      <Graphic>
        <Mark>
          <WellKnownName>circle</WellKnownName>
          <Fill>
            <SvgParameter name="fill">#666666</SvgParameter>
          </Fill>
          <Stroke>
            <SvgParameter name="fill">#CCCCCC</SvgParameter>
          </Stroke>
        </Mark>
        <Size>6.0</Size>
      </Graphic>
    </PointSymbolizer>
    <TextSymbolizer>
      <Label><ogc:PropertyName>CITY</ogc:PropertyName></Label>
      <Font>
        <SvgParameter name="font-family">Arial</SvgParameter>
        <SvgParameter name="font-size">12</SvgParameter>
      </Font>
      <Halo>
        <Radius>1</Radius>
        <Fill>
          <SvgParameter name="fill">#000000</SvgParameter>
        </Fill>
      </Halo>
      <Fill>
        <SvgParameter name="fill">#ffffff</SvgParameter>
      </Fill>
    </TextSymbolizer>
  </Rule>
</FeatureTypeStyle>

This example illustrates the creation of a Lightspeed layer using the preceding SLD and a WFS cities dataset.

// Create a WFS model for the WFS feature type 'cities' provided by the WFS server 'http://sampleservices.luciad.com/wfs'.
TLcdWFSProxyModel model = TLcdWFSProxyModel.Builder.newBuilder().server("http://sampleservices.luciad.com/wfs").featureTypeName("cities").build();

// Decode the SLD defining which data should be queried at each zoom level and how it should be rendered.
TLcdSLDFeatureTypeStyle featureTypeStyle = new TLcdSLDFeatureTypeStyleDecoder().decodeFeatureTypeStyle("sld_cities_with_level_of_detail.txt");

// Create a layer for the WFS model and the SLD.
ILspLayer layer = TLspShapeLayerBuilder.newBuilder().model(model).sldStyle(featureTypeStyle).build();

See OGC SLD Styling for more information on how to use and apply OGC SLD styling.