zoukankan      html  css  js  c++  java
  • GeoServer 查询sql视图

    说明:

    最近项目中遇到一个需求,需要统计管网的长度,但管网数据量非常大,前端用openlayers接口统计直接就奔溃了。

    后尝试使用调后台接口查数据库的方式,虽然可行但是又要多一层与后台交互的工作。

    后来研究发现,GeoServer还能发布数据库表或视图,这样的话就可以跳过后台直接查询数据库了,完美解决了统计大数据的问题。

    解决方案:

    1、登陆GeoServer ==> 找到图层目录 ==> 添加新的资源

    2、添加新图层里选中以PG为源的图层,点击“配置新的SQL视图”

    3、从上至下,填完信息,并点击保存

    4、保存sql源后,进行发布

     5、依次填入正确信息即可发布

     6、发布成功后,在Layer Preview里进行验证,下拉表中选则GeoJson(发布的数据库表没有图形要素信息,所以只能看到GeoJson)

    7、代码调用url:

    http://localhost:8080/geoserver/gas/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=gas%3Atest_pipe&maxFeatures=50&outputFormat=application%2Fjson

    8、附上SQL

    CREATE OR REPLACE FUNCTION public.func_pipelength()
      RETURNS TABLE(pipetype integer, pipelength double precision) AS
    $BODY$
    BEGIN
    RETURN QUERY 
    select 1 as pipetype,sum(st_length(geom)) as pipelength from t_pressureline tp left join t_pressureline_type tpt on tp.pressuratingcode = tpt.id where tpt.belong = 1
    union 
    select 2 as pipetype,sum(st_length(geom)) as pipelength from t_pressureline tp left join t_pressureline_type tpt on tp.pressuratingcode = tpt.id where tpt.belong = 2 
    union 
    select 3 as pipetype,sum(st_length(geom)) as pipelength from t_pressureline tp left join t_pressureline_type tpt on tp.pressuratingcode = tpt.id where tpt.belong = 3
    union 
    select 0 as pipetype,sum(st_length(geom)) as pipelength from t_pressureline tp left join t_pressureline_type tpt on tp.pressuratingcode = tpt.id where tpt.belong is null;
    END;

    问题:

     在尝试过程中还是遇到不少问题的,在此记录一下,以后再用时可以继续深入研究

    1、GeoServer发布后,常常遇到这个错,度娘说是返回数据的格式问题,但是不知道怎么查。

  • 相关阅读:
    css解决display:inline-block;产生的缝隙(间隙)
    js二进制与十进制互转
    js获取HTTP的请求头信息
    安装WampServer时出现的问题(丢失VCRUNTIME140.dll或MSVCR110.dll)以及解决办法
    学习安装并配置前端自动化工具Gulp
    解决overflow:hidden在安卓微信页面没有效果的办法
    Python 调用 ES、Solr、Phoenix
    Python 调用 Hprose接口、Dubbo接口、Java方法
    Python调用Redis
    robot用例执行常用命令(转)
  • 原文地址:https://www.cnblogs.com/giser-s/p/11496466.html
Copyright © 2011-2022 走看看