• 【PostGIS】实时坐标-电子围栏-判断-(参考遥想公瑾当年postgres+socket.io+nodejs实时地图应用实践)


    CREATE OR REPLACE FUNCTION "public"."process_t_gps"()
      RETURNS "pg_catalog"."trigger" AS $BODY$
        DECLARE
            rec record;
                    ewith record;
        BEGIN
            IF (TG_OP = 'DELETE') THEN
                --插入的GPS都是4326的经纬度,我们将在3857的谷歌底图上显示数据,发送转换后的3857出去
                --select TG_OP TG_OP,OLD.id,ST_AsGeojson(ST_AsText(ST_Transform(OLD.geom,3857))) geom,gid as null into rec; 
                --perform pg_notify('gps',row_to_json(rec)::text);
                            
                            select TG_OP TG_OP,OLD.id,ST_AsGeojson(ST_AsText(OLD.geom)) geom into rec;
                perform pg_notify('gps',row_to_json(rec)::text);
                            
     
                            --SELECT gid,ST_AsGeojson(ST_AsText(s.geom)) as epg,OLD.id,ST_AsGeojson(ST_AsText(NEW.geom)) as gps FROM eploygon s where st_within( OLD.geom , s.geom) into ewith;
                            --raise notice 'data:%',row_to_json(ewith)::text;
                            --perform pg_notify('gpswith',row_to_json(ewith)::text);
                         
                            
                RETURN OLD;
            ELSIF (TG_OP = 'UPDATE') THEN 
                    
                    
                         SELECT gid,ST_AsGeojson(ST_AsText(s.geom)) as epg,NEW.id,ST_AsGeojson(ST_AsText(NEW.geom)) as gps FROM eploygon s where st_within( NEW.geom , s.geom) into ewith;
                         --raise notice 'data:%',row_to_json(ewith)::text;
                         --perform pg_notify('gpswith',row_to_json(ewith)::text);
                         
                         
               select TG_OP TG_OP,NEW.id,ST_AsGeojson(ST_AsText(NEW.geom)) geom,null as gid into rec;
                         rec.gid = ewith.gid;
                         raise notice 'data:%',row_to_json(rec)::text;
               perform pg_notify('gps',row_to_json(rec)::text);  
                            
                RETURN NEW;
            ELSIF (TG_OP = 'INSERT') THEN
                    
                         SELECT gid,ST_AsGeojson(ST_AsText(s.geom)) as epg,NEW.id,ST_AsGeojson(ST_AsText(NEW.geom)) as gps FROM eploygon s where st_within( NEW.geom , s.geom) into ewith;
                         --raise notice 'data:%',row_to_json(ewith)::text;
                         --raise notice 'data:%',ewith.gid;
                         --perform pg_notify('gpswith',row_to_json(ewith)::text);
                         
                select TG_OP TG_OP,NEW.id,ST_AsGeojson(ST_AsText(NEW.geom)) geom ,null as gid into rec;
                            rec.gid = ewith.gid;
                            raise notice 'data:%',row_to_json(rec)::text;
                perform pg_notify('gps',row_to_json(rec)::text);
                             
                RETURN NEW;
            END IF;
            RETURN NULL;
        END;
    $BODY$
      LANGUAGE plpgsql VOLATILE
      COST 100

    参考来源:https://www.jianshu.com/p/4c075a69ca13?mType=Group

     备注:pg触发的事件名称需要小写,否则不会发送,如:perform pg_notify('gps',row_to_json(rec)::text);  

    博客地址: http://www.cnblogs.com/defineconst/
    博客版权: 本文以学习、研究和分享为主,欢迎转载和各类爬虫,但必须在文章页面明显位置给出原文链接。 如果文中有不妥或者错误的地方还望高手的您指出,以免误人子弟。如果您有更好的建议,不如留言一起讨论,共同进步! 再次感谢您耐心的读完本篇文章。
  • 相关阅读:
    【笑话】程序员和青蛙公主
    C#获取实体类属性名和值 | 遍历类对象
    VS2010 C# 使用DirectSound
    Serializing CTreeCtrl to / from a text file
    DirectX编程:[初级]C# 中利用 DirectSound 录音
    Mixed mode assembly is built against version 'v1.1.4322' of the runtime and...问题——C# DirectXSound
    DirectX编程:[初级]C#中利用DirectSound播放WAV格式声音[最少只要4句话]
    C#中使用DirectSound录音
    官网下载Google Chrome离线安装包
    设计模式读书笔记[1]:策略模式(Strategy)
  • 原文地址:https://www.cnblogs.com/defineconst/p/15056647.html
Copyright © 2020-2023  润新知