0

I'm new to GeoServer and encountered the following problem that i don't know how to solve. I have PostGIS-Data in the luxemburghish SRID EPSG:2169 that I transform to EPSG:4326 (seems to be easier to use in OpenLayers) like this:

select f.objectid, f.geocode, f.btyp1_code, f.bewertung1,f.bkjahr,f.shape_ares, st_transform(f.the_geom,4326) as the_geom
from btk_f f

This query is used as a datasource in GeoServer to create a layer, that is served as WMS to be displayed in an OpenLayers Map. The data is styled using an SLD created in QGIS.

In the layer preview in GeoServer the layer displays as expected (showing polygons and labels following the style rules from QGIS) Layer preview in Geoserver

When I'm loading the layer in OpenLayers (v.5.3.0) only the labels are displayed, not the polygons. Even the labels stop rendering at a certain zoom level. The resulting map (on OSM as background map) looks like this: WMS-layers from GeoServer on OSM showing only labels

The code I use to insert the WMS-layer follows the latest tiled WMS-example from OpenLayers code.

// only the layer definition part
 var layers = [
    new ol.layer.Tile({
      source: new ol.source.OSM()
    }),
    new ol.layer.Tile({
      source: new ol.source.TileWMS({
        url: 'https://ourdomain.com/geoserver/wms',
        params: {'LAYERS': 'store:layer', CRS:'EPSG:4326'},
        serverType: 'geoserver'
      })
    })
  ];
  • 1
    what does the GeoServer log file show? It's probably related to doing 2 reprojections. I'd leave the data as is in PostGIS and allow GeoServer to reproject to WebMercator (by removing the CRS element in the PARAMS. – Ian Turton Jun 30 at 7:49
  • 1
    Does it need a STYLES parameter? OpenLayers will override that CRS (along with any attempt to set WIDTH, HEIGHT or BBOX). See the params option in the API openlayers.org/en/latest/apidoc/… The OpenLayers default projection is web mercator so if you needed EPSG:4326 from the server you would need to specify it via the projection option (but if you were going to reproject EPSG:4326 you could also reproject EPSG:2169, it only needs a proj4 definition). – Mike Jun 30 at 9:33
  • @Ian: in the GeoServer log I've found one error ERROR [renderer.lite] - The specified mark brush://dense7 was not found! – geom Jun 30 at 11:18
  • @Mike. I reprojected the EPSG:2169 directly to EPSG:3857, and removed the CRS in the PARAMS as Ian supposed, but this doesn't seem to change anything. I still only see the Labels, but no polygons. – geom Jun 30 at 11:20
  • Can you add the relevant part of the sld? – Ian Turton Jun 30 at 13:04
1

I've tried the default polygon style from GeoServer and it worked fine. So I started to rewrite my SLD using the default one as template. The problem was that the SLD created by QGIS is SLD 1.1.0 and still GeoServer uses 1.0. Even though GeoServer validates the SLD from QGIS and displays it correct in the layer-preview it still seems to have problems with complexer graphic fills (see error with brush://dense7). I'll try later what SLD from QGIS works out of the box and what one should avoid, because it is still not supported.

The following SLD works fine for me:

<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor version="1.0.0" 
 xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd" 
 xmlns="http://www.opengis.net/sld" 
 xmlns:ogc="http://www.opengis.net/ogc" 
 xmlns:xlink="http://www.w3.org/1999/xlink" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <NamedLayer>
    <Name>v_btk_f</Name>
    <UserStyle>
      <Title>Biotopkataster Flächen</Title>
      <Abstract>_</Abstract>
      <FeatureTypeStyle>
        <Rule>
          <Name>Schlammuferfluren (3130)</Name>
            <Title>Schlammuferfluren (3130)</Title>
          <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
            <ogc:PropertyIsEqualTo>
              <ogc:PropertyName>btyp1_code</ogc:PropertyName>
              <ogc:Literal>3130</ogc:Literal>
            </ogc:PropertyIsEqualTo>
          </ogc:Filter>
          <MinScaleDenominator>1</MinScaleDenominator>
          <MaxScaleDenominator>20000</MaxScaleDenominator>
          <PolygonSymbolizer>
            <Fill>
              <CssParameter name="fill">#fd6fcf</CssParameter>
              <CssParameter name="fill-opacity">0.51</CssParameter>
            </Fill>
            <Stroke>
              <CssParameter name="stroke">#000000</CssParameter>
              <CssParameter name="stroke-width">0.26000000000000001</CssParameter>
              <CssParameter name="stroke-linejoin">bevel</CssParameter>
            </Stroke>
          </PolygonSymbolizer>
        </Rule>
        <Rule>
          <Name>Characeen-Gewässer (3140)</Name>          
          <Title>Characeen-Gewässer (3140)</Title>
          <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
            <ogc:PropertyIsEqualTo>
              <ogc:PropertyName>btyp1_code</ogc:PropertyName>
              <ogc:Literal>3140</ogc:Literal>
            </ogc:PropertyIsEqualTo>
          </ogc:Filter>
          <MinScaleDenominator>1</MinScaleDenominator>
          <MaxScaleDenominator>20000</MaxScaleDenominator>
          <PolygonSymbolizer>
            <Fill>
              <CssParameter name="fill">#cc66ff</CssParameter>
            </Fill>
            <Stroke>
              <CssParameter name="stroke">#000000</CssParameter>
              <CssParameter name="stroke-width">0.26000000000000001</CssParameter>
              <CssParameter name="stroke-linejoin">bevel</CssParameter>
            </Stroke>
          </PolygonSymbolizer>
        </Rule>
        .... other rules for different codes
        <Rule>
          <MinScaleDenominator>1</MinScaleDenominator>
          <MaxScaleDenominator>5000</MaxScaleDenominator>
          <TextSymbolizer>
            <Label>
              <ogc:PropertyName>btyp1_code</ogc:PropertyName>
            </Label>
            <Font>
              <CssParameter name="font-family">Arial</CssParameter>
              <CssParameter name="font-size">13</CssParameter>
              <CssParameter name="font-style">italic</CssParameter>
            </Font>
            <LabelPlacement>
              <PointPlacement>
                <AnchorPoint>
                  <AnchorPointX>0.5</AnchorPointX>
                  <AnchorPointY>0.5</AnchorPointY>
                </AnchorPoint>
              </PointPlacement>
            </LabelPlacement>
            <Halo>
              <Radius>2</Radius>
              <Fill>
                <CssParameter name="fill">#ffffff</CssParameter>
              </Fill>
            </Halo>
            <Fill>
              <CssParameter name="fill">#fc0107</CssParameter>
            </Fill>
            <VendorOption name="maxDisplacement">1</VendorOption>
          </TextSymbolizer>
        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

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.