geoserver+postgre加载海量数据的办法
最近在开发GIS系统,碰巧遇到了海量数据加载的问题。特以博客以记之
1.openlayers解决点的海量数据加载
openlayers加载海量点数据openlayer在官网提供了支持,主要是通过聚合来实现:
https://openlayers.org/en/latest/examples/cluster.html
2.openlayers加载非点状海量数据
主要是通过postgreSql来过滤掉一部分数据,过滤通过缩放级别zoom来限制,当缩放到一定区域时逐渐提高加载的数量,使得加载的feature在缩放到指定的级别时总是大体保持相同的数量。
核心方式: 缩放级别*k >= Feature长度倒叙的列表
使用GeoServer 的SQLView
select pipelineid,shape,tenantid,linename,devicemodel,pointlength,depth,projectid,sectionid,jobid,createtime,color,createuid,deviceid from
(
select * ,row_number() over(partition by projectid order by ST_Length(shape) desc) as rn from pm_spatial_design_pipeline
) as r
where 1=1 and
case
when %all%=1 then
0=0
else
rn <= %maplevel%
end and tenantid like '%tenantid%%'
然后请求http设置如下
let geoServerAddress = getGeoServerAddress();zoom = parseInt(zoom)if(type === 1) {
if(zoom > 10) {
return `${
geoServerAddress}/geoserver/szygis/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=szygis:${
layerName}&outputFormat=application/json&viewparams=maplevel:1;all:1;`;} else {
return `${
geoServerAddress}/geoserver/szygis/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=szygis:${
layerName}&outputFormat=application/json&viewparams=maplevel:${
(zoom * 4)};`;}} else {
return `${
geoServerAddress}/geoserver/szygis/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=szygis:${
layerName}&outputFormat=application/json&srsname=`}
通过maplevel设置加载数量
all 是否加载所有
tenantid 租户id
这样使得始终加载的数据是常数,在全屏的时候间接的进行抽稀