Use the SLD style released by Qgis in GeoServer for layer beautification

Table of contents

knowledge map

I. Introduction

Two, Qgis symbolic conversion into SLD

1. Symbolic generation in Qis

2. SLD style export

 3. GeoServer data release

1. Vector layer release

2. Publish styles in GeoServer

Summarize


knowledge map

serial number blog link
1 The method of using LeafLet to overlay the Geoserver wms layer to the existing basemap
2 A guide to avoiding pitfalls in data source settings when GeoServer publishes services
3 Practice of Visualization Tool in WebGIS Based on Leaflet for Township Administrative Division
4 Combat of Boundary Range Fusion of Changsha-Zhuzhou-Xiangtan Urban Agglomeration Based on QGIS
5 Connect Shp and Excel attributes in Qgis to realize public budget space analysis of top 100 counties
6 Practical operation of Qgis loading online XYZ tile image service
7 Using the QMetaTiles plugin in Qgis to download XYZ tiles offline
8 Introduction to generating XYZ tiles (directories) using raster tools in Qqis
9 Introduction to SLD knowledge of map visualization enhancement tool in GeoServer
10 Layer symbolization and labeling of Qgis basic operations

I. Introduction

        WebGIS is an Internet-based geographic information system, which can realize functions such as visualization, analysis, query and management of geographic information data on a Web browser. The core technology of WebGIS is to use Web servers and Web browsers to publish and display geographic information data and functions. It allows users to access geographic information data and functions through browsers, and can realize the sharing and interaction of spatial information through the Internet.

        WebGIS has a wide range of applications, including map services, urban planning and management, business analysis and decision support, land use and cover change monitoring, environmental monitoring and protection, disaster early warning and emergency management, and other fields. The application of WebGIS can provide users with rich geographic information data and services, help users better understand and analyze spatial information, and improve the accuracy and efficiency of decision-making.

        In the previous blog, we explained some blogs based on the desktop gis software Qgis for gis space visualization. For the blog address, see the knowledge earth index above. From spatial data to public release on the Internet, allowing users to see exquisite maps, it will definitely require the use of webgis technology. Therefore, GeoServer is used to publish the map service, and Qgis is used to assist in the production of SLD style, and finally published as a WMS service for the front-end LeafLet to display. This article runs through the entire process of Webgis map style production and visualization configuration, and explains in detail how to publish the SLD file produced by Qgis to Geoserver, so that everyone is familiar with the simple production process of Webgis.

Two, Qgis symbolic conversion into SLD

1. Symbolic generation in Qis

        Still take the general public budget revenue data and provincial data of the top 100 counties in 2022 as an example. As mentioned above, the symbolic mapping in Qgis has been completed. The effect of drawing is shown in the figure below:

         In the figure, we have labeled and symbolized two different vector layers. In Qgis, we can directly export SLD files. Generally speaking, we can publish SLD files directly in GeoServer. Here, we first export the SLD style file.

2. SLD style export

        There are two ways to export the SLD style (one way is demonstrated here), taking the public budget revenue layer of the top 100 counties in the country as an example. The first way is to use the mouse to click on the target layer, right-click to export, and then choose to save as a Qgis layer style file.

         After clicking the menu, the following window pops up.

 Click Save to get the SLD file of the current layer, and open it with a text editor to see the following content:

<?xml version="1.0" encoding="UTF-8"?>
<StyledLayerDescriptor xmlns="http://www.opengis.net/sld" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.1.0/StyledLayerDescriptor.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:se="http://www.opengis.net/se" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1.0">
  <NamedLayer>
    <se:Name>2022年全国百强县一般公共预算收入榜</se:Name>
    <UserStyle>
      <se:Name>2022年全国百强县一般公共预算收入榜</se:Name>
      <se:FeatureTypeStyle>
        <se:Rule>
          <se:Name>45 - 100</se:Name>
          <se:Description>
            <se:Title>45 - 100</se:Title>
          </se:Description>
          <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
            <ogc:And>
              <ogc:PropertyIsGreaterThanOrEqualTo>
                <ogc:PropertyName> abs("ggys")</ogc:PropertyName>
                <ogc:Literal>44.79999999999999716</ogc:Literal>
              </ogc:PropertyIsGreaterThanOrEqualTo>
              <ogc:PropertyIsLessThanOrEqualTo>
                <ogc:PropertyName> abs("ggys")</ogc:PropertyName>
                <ogc:Literal>100</ogc:Literal>
              </ogc:PropertyIsLessThanOrEqualTo>
            </ogc:And>
          </ogc:Filter>
          <se:PolygonSymbolizer>
            <se:Fill>
              <se:SvgParameter name="fill">#f7fcf5</se:SvgParameter>
            </se:Fill>
            <se:Stroke>
              <se:SvgParameter name="stroke">#232323</se:SvgParameter>
              <se:SvgParameter name="stroke-width">1</se:SvgParameter>
              <se:SvgParameter name="stroke-linejoin">bevel</se:SvgParameter>
            </se:Stroke>
          </se:PolygonSymbolizer>
        </se:Rule>
        <se:Rule>
          <se:Name>100 - 200</se:Name>
          <se:Description>
            <se:Title>100 - 200</se:Title>
          </se:Description>
          <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
            <ogc:And>
              <ogc:PropertyIsGreaterThan>
                <ogc:PropertyName> abs("ggys")</ogc:PropertyName>
                <ogc:Literal>100</ogc:Literal>
              </ogc:PropertyIsGreaterThan>
              <ogc:PropertyIsLessThanOrEqualTo>
                <ogc:PropertyName> abs("ggys")</ogc:PropertyName>
                <ogc:Literal>200</ogc:Literal>
              </ogc:PropertyIsLessThanOrEqualTo>
            </ogc:And>
          </ogc:Filter>
          <se:PolygonSymbolizer>
            <se:Fill>
              <se:SvgParameter name="fill">#caeac3</se:SvgParameter>
            </se:Fill>
            <se:Stroke>
              <se:SvgParameter name="stroke">#232323</se:SvgParameter>
              <se:SvgParameter name="stroke-width">1</se:SvgParameter>
              <se:SvgParameter name="stroke-linejoin">bevel</se:SvgParameter>
            </se:Stroke>
          </se:PolygonSymbolizer>
        </se:Rule>
        <se:Rule>
          <se:Name>200 - 300</se:Name>
          <se:Description>
            <se:Title>200 - 300</se:Title>
          </se:Description>
          <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
            <ogc:And>
              <ogc:PropertyIsGreaterThan>
                <ogc:PropertyName> abs("ggys")</ogc:PropertyName>
                <ogc:Literal>200</ogc:Literal>
              </ogc:PropertyIsGreaterThan>
              <ogc:PropertyIsLessThanOrEqualTo>
                <ogc:PropertyName> abs("ggys")</ogc:PropertyName>
                <ogc:Literal>300</ogc:Literal>
              </ogc:PropertyIsLessThanOrEqualTo>
            </ogc:And>
          </ogc:Filter>
          <se:PolygonSymbolizer>
            <se:Fill>
              <se:SvgParameter name="fill">#7bc87c</se:SvgParameter>
            </se:Fill>
            <se:Stroke>
              <se:SvgParameter name="stroke">#232323</se:SvgParameter>
              <se:SvgParameter name="stroke-width">1</se:SvgParameter>
              <se:SvgParameter name="stroke-linejoin">bevel</se:SvgParameter>
            </se:Stroke>
          </se:PolygonSymbolizer>
        </se:Rule>
        <se:Rule>
          <se:Name>300 - 400</se:Name>
          <se:Description>
            <se:Title>300 - 400</se:Title>
          </se:Description>
          <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
            <ogc:And>
              <ogc:PropertyIsGreaterThan>
                <ogc:PropertyName> abs("ggys")</ogc:PropertyName>
                <ogc:Literal>300</ogc:Literal>
              </ogc:PropertyIsGreaterThan>
              <ogc:PropertyIsLessThanOrEqualTo>
                <ogc:PropertyName> abs("ggys")</ogc:PropertyName>
                <ogc:Literal>400</ogc:Literal>
              </ogc:PropertyIsLessThanOrEqualTo>
            </ogc:And>
          </ogc:Filter>
          <se:PolygonSymbolizer>
            <se:Fill>
              <se:SvgParameter name="fill">#2a924a</se:SvgParameter>
            </se:Fill>
            <se:Stroke>
              <se:SvgParameter name="stroke">#232323</se:SvgParameter>
              <se:SvgParameter name="stroke-width">1</se:SvgParameter>
              <se:SvgParameter name="stroke-linejoin">bevel</se:SvgParameter>
            </se:Stroke>
          </se:PolygonSymbolizer>
        </se:Rule>
        <se:Rule>
          <se:Name>400 - 430</se:Name>
          <se:Description>
            <se:Title>400 - 430</se:Title>
          </se:Description>
          <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
            <ogc:And>
              <ogc:PropertyIsGreaterThan>
                <ogc:PropertyName> abs("ggys")</ogc:PropertyName>
                <ogc:Literal>400</ogc:Literal>
              </ogc:PropertyIsGreaterThan>
              <ogc:PropertyIsLessThanOrEqualTo>
                <ogc:PropertyName> abs("ggys")</ogc:PropertyName>
                <ogc:Literal>430.18000000000000682</ogc:Literal>
              </ogc:PropertyIsLessThanOrEqualTo>
            </ogc:And>
          </ogc:Filter>
          <se:PolygonSymbolizer>
            <se:Fill>
              <se:SvgParameter name="fill">#00441b</se:SvgParameter>
            </se:Fill>
            <se:Stroke>
              <se:SvgParameter name="stroke">#232323</se:SvgParameter>
              <se:SvgParameter name="stroke-width">1</se:SvgParameter>
              <se:SvgParameter name="stroke-linejoin">bevel</se:SvgParameter>
            </se:Stroke>
          </se:PolygonSymbolizer>
        </se:Rule>
        <se:Rule>
          <se:TextSymbolizer>
            <se:Label>
              <!--SE Export for NAME + '\n' + ' 预算收入' + ggys + '(亿元)' not implemented yet-->Placeholder</se:Label>
            <se:Font>
              <se:SvgParameter name="font-family">SimSun</se:SvgParameter>
              <se:SvgParameter name="font-size">13</se:SvgParameter>
            </se:Font>
            <se:LabelPlacement>
              <se:PointPlacement>
                <se:AnchorPoint>
                  <se:AnchorPointX>0</se:AnchorPointX>
                  <se:AnchorPointY>0.5</se:AnchorPointY>
                </se:AnchorPoint>
              </se:PointPlacement>
            </se:LabelPlacement>
            <se:Fill>
              <se:SvgParameter name="fill">#000000</se:SvgParameter>
            </se:Fill>
            <se:VendorOption name="maxDisplacement">1</se:VendorOption>
          </se:TextSymbolizer>
        </se:Rule>
      </se:FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

Similarly, export the SLD style of the province information.

 3. GeoServer data release

1. Vector layer release

        Create a new data source in GeoServer Manager, the detailed operation is as follows:

         Here, select Shapefile according to the data source, click Continue, create a new vector data source, select the source file, and add it to the GeoServer manager.

         It should be noted here that the setting of the character set of DBF is very important. It is best to be consistent with the data set in Qgis so that there will be no problem of Chinese garbled characters. Note that here only the layer is published with the default style, and you can see the following page when previewing the layer, taking the public budget revenue as an example.

 It can be seen that after the service is released, it is not displayed as expected.

2. Publish styles in GeoServer

        Centralized management of layer styles is possible in GeoServer. The detailed operation steps are as follows:

         Click the style hyperlink in the left menu of GeoServer, and click the Add Style button in the right list to add a style. Import the SLD file exported from Qgis into the current page.

         After the style file is uploaded, click the validate button to verify the format, and if there is no error, click Save.

Apply the current style to the specified layer data, and select the check box of the layer to be set on the publish page of the style page.

 Finally, use the default map browser of GeoServer to preview, and you can see the following effect:

        If you can see the above effect, it means that the style import is successful.

Summarize

        The above is the main content of this article. This article runs through the entire process of Webgis map style production and visualization configuration. It explains in detail how to publish the SLD file produced by Qgis to Geoserver, so that everyone is familiar with the simple production process of Webgis. Interested friends can try to release the corresponding map service by themselves, and set the layer style at the same time. During the release process, test whether the SLD generated by Qgis can be used directly. If not, have you found a solution? Instructions for solving some common problems will be given later.

Guess you like

Origin blog.csdn.net/yelangkingwuzuhu/article/details/131333825