Storage of spatial data and generation of heat map by GeoServer

Keywords: SQL Database xml encoding

The requirements are as follows. There are already generated good spatial data, including date, hour, longitude, latitude, number of people. Use GeoServer to generate heat map.
This article uses the PostgreSQL10 database and has added PostGIS support.

Create table

create table table_test(
day varchar(8),
hour int,
lon numeric(8,5),
lat numeric(8,5),
count_people int,
geom geometry
);

Import data (omitted)

Generate geometry field data

update table_test set geom=(ST_GeomFromText('POINT(' || lon || ' ' || lat || ')'));

GeoServer publishing layers

  • Access local GeoServer, http://localhost:8080/geoserver/web/.
  • Select layer – > add new resources, select your own spatial database, and click Configure new SQL view.
    In creating a new SQL view page
    View name: table UU test
    SQL statement: select * from table \ U test where day = '% day%' and hour=%hour%
    Click the parameter guessed from SQL, enter the default value, and delete the validation expression.
    Refresh single machine, fill in 4326 with SRID, and click save.

  • In the edit layers page,
    Change the definition SRS to EPSG:4326, if not.
    In the border, click Native Bounding Box to calculate from the data. The latitude / longitude border is calculated from native borders.

  • Switch to release label:
    Default Style: select a heat map style and click save.
    You can preview it in Layer Preview.

You need to create a heat map style before publishing layers.

Creating a heat map style in GeoServer

<?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>person_point_heat</Name>
       <UserStyle>
         <Title>person_point_heat</Title>
         <Abstract>A heatmap </Abstract>
         <FeatureTypeStyle>
           <Transformation>
             <ogc:Function name="gs:Heatmap">
               <ogc:Function name="parameter">
                 <ogc:Literal>data</ogc:Literal>
               </ogc:Function>
               <ogc:Function name="parameter">
                 <ogc:Literal>weightAttr</ogc:Literal>
                 <ogc:Literal>count_people</ogc:Literal>
               </ogc:Function>
               <ogc:Function name="parameter">
                 <ogc:Literal>radiusPixels</ogc:Literal>
                 <ogc:Function name="env">
                   <ogc:Literal>radius</ogc:Literal>
                   <ogc:Literal>35</ogc:Literal>
                 </ogc:Function>
               </ogc:Function>
               <ogc:Function name="parameter">
                 <ogc:Literal>pixelsPerCell</ogc:Literal>
                 <ogc:Literal>2</ogc:Literal>
               </ogc:Function>
               <ogc:Function name="parameter">
                 <ogc:Literal>outputBBOX</ogc:Literal>
                 <ogc:Function name="env">
                   <ogc:Literal>wms_bbox</ogc:Literal>
                 </ogc:Function>
               </ogc:Function>
               <ogc:Function name="parameter">
                 <ogc:Literal>outputWidth</ogc:Literal>
                 <ogc:Function name="env">
                   <ogc:Literal>wms_width</ogc:Literal>
                 </ogc:Function>
               </ogc:Function>
               <ogc:Function name="parameter">
                 <ogc:Literal>outputHeight</ogc:Literal>
                 <ogc:Function name="env">
                   <ogc:Literal>wms_height</ogc:Literal>
                 </ogc:Function>
               </ogc:Function>
             </ogc:Function>
           </Transformation>
          <Rule>
            <RasterSymbolizer>
            <!-- specify geometry attribute to pass validation -->
              <Geometry>
                <ogc:PropertyName>geom</ogc:PropertyName>
              </Geometry>
              <Opacity>1</Opacity>
                <ColorMap type="ramp" >
                  <ColorMapEntry color="#FFFFFF" quantity="0" opacity="0" label="FFFFF" />
                  <ColorMapEntry color="#7F95E6" quantity="0.1" opacity="0.5" label="7F95E6" />
                  <ColorMapEntry color="#7DFC3F" quantity="0.3" opacity="0.5" label="7DFC3F" />
                  <ColorMapEntry color="#F6FD01" quantity="0.4" opacity="0.5" label="F6FD01" />
                  <ColorMapEntry color="#EF8C07" quantity="0.5" opacity="0.5" label="EF8C07" />
                  <ColorMapEntry color="#FE0409" quantity="0.7" opacity="0.5" label="FE0409" />
                  <ColorMapEntry color="#FE0409" quantity="1" opacity="0.5" label="FE0409" />
                  </ColorMap>
            </RasterSymbolizer>
           </Rule>
         </FeatureTypeStyle>
       </UserStyle>
     </NamedLayer>
    </StyledLayerDescriptor>

Note that the count "people" and geom fields correspond to the fields in the table.

Posted by bob1660 on Sun, 29 Mar 2020 08:18:17 -0700