文章目录
一、安装GeoServer
mkdir -p ~/geoserver_data && chmod -R a+rwx ~/geoserver_data
docker run -d -v $HOME/geoserver_data:/opt/geoserver/data_dir kartoza/geoserver
二、前期数据准备
1、docker部署带postgis扩展的postgresql数据库
# 例如:拉取 postgresql 9.6 版本以及postgis 2.4 版本
docker pull kartoza/postgis:9.6-2.4
# 运行
docker run -d -p 5432:5432 --name postgresql_server --restart always -e POSTGRES_USER=root -e POSTGRES_PASS='root' -e ALLOW_IP_RANGE=0.0.0.0/0 -v /home/postgresql/data:/var/lib/postgresql -v /home/postgresql/tmp:/tmp/tmp -t kartoza/postgis:9.6-2.4
-e ALLOW_IP_RANGE=0.0.0.0/0,这个表示允许所有ip访问,如果不加,则非本机 ip 访问不了
-e POSTGRES_USER=root 用户名
-e POSTGRES_PASS=‘root’ 指定密码
2、psql 部分了解知识
本地 - 服务端中连接命令
psql -U postgres # postgres为用户名
远程 - 服务端中连接命令
psql -U postgres -h 192.168.10.223 -p 5432
psql配置文件存放位置 - 包含账号、密码、加密方式等信息
温馨小提示:这里是从容器中映射到宿主机中的存放位置
/home/postgresql/data/9.6/main/pg_hba.conf
3、Navicat远程连接数据库
4、连接好之后就是导入数据所需数据,新建关联视图等
温馨小提示:这里数据根据自己的业务来处理即可~
视图命令
SELECT
emap_bazhong_emission_3km.grid_id,
emap_bazhong_emission_3km.q_value,
emap_bazhong_emission_3km.hc_value,
emap_bazhong_emission_3km.h_value,
emap_bazhong_emission_3km.d_value,
emap_bazhong_emission_3km.s_value,
emap_bazhong_emission_3km.dv_value,
emap_bazhong_emission_3km.cat_value,
emap_bazhong_emission_3km.area,
emap_bazhong_emission_3km.sd_value,
emap_bazhong_emission_3km.pollutant_id,
bazhong_grid_new_900913.the_geom
FROM
bazhong_grid_new_900913,
emap_bazhong_emission_3km
WHERE
(emap_bazhong_emission_3km.grid_id = bazhong_grid_new_900913.gid)
bazhong_grid_900913.the_geom
代表 网格表里面的经纬度
字段
grid_id 是每个网格的编号,这个编号是唯一的,txt数据文件中每条数据中都有网格编号和排放量,用txt数据中的grid_id 与网格数据中的grid_id 匹配起来,那么排放量数据就对应到每个网格中了
三、geoserver发布视图数据
1、新建工作区 - 类型新建一个项目空间
2、新建样式
这里贴一个参考样式
<?xml version="1.0" encoding="ISO-8859-1"?>
<sld:StyledLayerDescriptor xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
xmlns:gml="http://www.opengis.net/gml" version="1.0.0">
<sld:NamedLayer>
<sld:Name>emap_bazhong_emission_3km_layer</sld:Name>
<sld:UserStyle>
<sld:FeatureTypeStyle>
<sld:Rule>
<sld:Name>rule1</sld:Name>
<sld:Title>0-5.17</sld:Title>
<sld:Abstract>Abstract</sld:Abstract>
<ogc:Filter>
<ogc:And>
<ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyName>q_value</ogc:PropertyName>
<ogc:Literal>0</ogc:Literal>
</ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>q_value</ogc:PropertyName>
<ogc:Literal>5.1701</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
<sld:PolygonSymbolizer>
<sld:Fill>
<sld:CssParameter name="fill">
<ogc:Literal>#3300cc</ogc:Literal>
</sld:CssParameter>
<sld:CssParameter name="fill-opacity">
<ogc:Literal>0.3</ogc:Literal>
</sld:CssParameter>
</sld:Fill>
<sld:Stroke>
<sld:CssParameter name="stroke">
<ogc:Literal>#3300cc</ogc:Literal>
</sld:CssParameter>
<sld:CssParameter name="stroke-opacity">
<ogc:Literal>0.3</ogc:Literal>
</sld:CssParameter>
<sld:CssParameter name="stroke-dashoffset">
<ogc:Literal>0.0</ogc:Literal>
</sld:CssParameter>
<sld:CssParameter name="stroke-width">
<ogc:Literal>0.0001</ogc:Literal>
</sld:CssParameter>
</sld:Stroke>
</sld:PolygonSymbolizer>
</sld:Rule>
<sld:Rule>
<sld:Name>rule2</sld:Name>
<sld:Title>5.17-10.34</sld:Title>
<sld:Abstract>Abstract</sld:Abstract>
<ogc:Filter>
<ogc:And>
<ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyName>q_value</ogc:PropertyName>
<ogc:Literal>5.17</ogc:Literal>
</ogc:PropertyIsGreaterThanOrEqualTo>
<ogc:PropertyIsLessThan>
<ogc:PropertyName>q_value</ogc:PropertyName>
<ogc:Literal>10.3401</ogc:Literal>
</ogc:PropertyIsLessThan>
</ogc:And>
</ogc:Filter>
<sld:PolygonSymbolizer>
<sld:Fill>
<sld:CssParameter name="fill">
<ogc:Literal>#33ccff</ogc:Literal>
</sld:CssParameter>
<sld:CssParameter name="fill-opacity">
<ogc:Literal>0.3</ogc:Literal>
</sld:CssParameter>
</sld:Fill>
<sld:Stroke>
<sld:CssParameter name="stroke">
<ogc:Literal>#33ccff</ogc:Literal>
</sld:CssParameter>
<sld:CssParameter name="stroke-opacity">
<ogc:Literal>0.3</ogc:Literal>
</sld:CssParameter>
<sld:CssParameter name="stroke-dashoffset">
<ogc:Literal>0.0</ogc:Literal>
</sld:CssParameter>
<sld:CssParameter name="stroke-width">
<ogc:Literal>0.0001</ogc:Literal>
</sld:CssParameter>
</sld:Stroke>
</sld:PolygonSymbolizer>
</sld:Rule>
</sld:FeatureTypeStyle>
</sld:UserStyle>
</sld:NamedLayer>
</sld:StyledLayerDescriptor>
3、新建数据存储
选择从psql数据库中导入数据
选择工作区、填写数据源名称、将连接参数配置好即可
4、新增图层
上面步骤2中数据存储保存后会自动跳转到图层页面,然后选择我们已经在数据库中配置好的视图数据发布~
1. 数据
依次点击下图中标识地理坐标信息
2. 发布
选择新增样式
选择后信息如下:
4、到Layer Preview
中打开查看最终效果