zoukankan      html  css  js  c++  java
  • 【Postgres】空间计算

    select * from eploygon;
    
    select * from geometry_columns where f_table_name='eploygon';
    
    
    
    -------------------------------------------------------------------------------------------------------------------------------------------------------
    
    SELECT ST_GeomFromText('polygon ((117.812658 38.926816,117.813196 38.926622,117.812679 38.925415,117.812065 38.925792,117.812658 38.926816))', 4326 );
     
    
    SELECT
    ST_AsText(
        ST_GeomFromText('polygon ((117.812658 38.926816,117.813196 38.926622,117.812679 38.925415,117.812065 38.925792,117.812658 38.926816))', 4326 )
    )
     
    
    SELECT gid,geom FROM public.eploygon s where ST_Intersects( ST_GeomFromText('polygon ((117.812658 38.926816,117.813196 38.926622,117.812679 38.925415,117.812065 38.925792,117.812658 38.926816))', 4326 ) , s.geom) ;
    
    
    SELECT  ST_GeomFromGeoJSON('{"type":"LineString","coordinates":[[0,0],[1,1],[1,1],[2,2]]}'); 
    
    
    
    select ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON('{"type":"LineString","coordinates":[[117.8136920928955,38.92978618569792],[117.81523704528809,38.926781511834875],[117.81620264053345,38.92432760043733],[117.81620264053345,38.92247459068792],[117.81620264053345,38.921489637879205],[117.81624555587769,38.92105558653837]]}')),4326);
    
    -------------------------------------------------------------------------------------------------------------------------------------------------------
    --相交切割计算
     SELECT ST_Intersection(  ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON('{"type":"LineString","coordinates":[[117.8136920928955,38.92978618569792],[117.81523704528809,38.926781511834875],[117.81620264053345,38.92432760043733],[117.81620264053345,38.92247459068792],[117.81620264053345,38.921489637879205],[117.81624555587769,38.92105558653837]]}')),4326) , s.geom) 
      FROM public.eploygon s where ST_Intersects(  ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON('{"type":"LineString","coordinates":[[117.8136920928955,38.92978618569792],[117.81523704528809,38.926781511834875],[117.81620264053345,38.92432760043733],[117.81620264053345,38.92247459068792],[117.81620264053345,38.921489637879205],[117.81624555587769,38.92105558653837]]}')),4326) , s.geom) ;
        
          SELECT  ST_Intersection(  ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":[[[117.812658,38.926816],[117.813196,38.926622],[117.812679, 38.925415],[117.812065,38.925792],[117.812658,38.926816]]]}')),4326) , s.geom)  FROM public.eploygon s where ST_Intersects(  ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":[[[117.812658,38.926816],[117.813196,38.926622],[117.812679, 38.925415],[117.812065,38.925792],[117.812658,38.926816]]]}')),4326) , s.geom) ;
            
            
      SELECT  ST_AsText(ST_Intersection(  ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON('{"type":"Point","coordinates":[117.812658,38.926816]}')),4326) , s.geom)) as a FROM public.eploygon s;
    
      SELECT  ST_Intersection(  ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON('{"type":"Point","coordinates":[117.812658,38.926816]}')),4326) , s.geom) FROM public.eploygon s
        where ST_Intersects(  ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON('{"type":"Point","coordinates":[117.812658,38.926816]}')),4326) , s.geom);
    
    
    -------------------------------------------------------------------------------------------------------------------------------------------------------
     --相交计算
     SELECT gid,geom FROM public.eploygon s where ST_Intersects(  ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON('{"type":"LineString","coordinates":[[117.8136920928955,38.92978618569792],[117.81523704528809,38.926781511834875],[117.81620264053345,38.92432760043733],[117.81620264053345,38.92247459068792],[117.81620264053345,38.921489637879205],[117.81624555587769,38.92105558653837]]}')),4326) , s.geom) ;
     
     
      SELECT gid,geom FROM public.eploygon s where ST_Intersects(  ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":[[[117.812658,38.926816],[117.813196,38.926622],[117.812679, 38.925415],[117.812065,38.925792],[117.812658,38.926816]]]}')),4326) , s.geom) ;
    
    
      SELECT gid,geom FROM public.eploygon s where ST_Intersects(  ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON('{"type":"Point","coordinates":[117.812658,38.926816]}')),4326) , s.geom)  ;
    
    -------------------------------------------------------------------------------------------------------------------------------------------------------
    --相交计算测试输出
     SELECT gid,geom FROM public.eploygon s where ST_Intersects(  ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON('{"type":"LineString","coordinates":[[117.8136920928955,38.92978618569792],[117.81523704528809,38.926781511834875],[117.81620264053345,38.92432760043733],[117.81620264053345,38.92247459068792],[117.81620264053345,38.921489637879205],[117.81624555587769,38.92105558653837]]}')),4326) , s.geom) 
     union
     select 111111 as gid,ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON('{"type":"LineString","coordinates":[[117.8136920928955,38.92978618569792],[117.81523704528809,38.926781511834875],[117.81620264053345,38.92432760043733],[117.81620264053345,38.92247459068792],[117.81620264053345,38.921489637879205],[117.81624555587769,38.92105558653837]]}')),4326);  
     
     
      SELECT gid,geom FROM public.eploygon s where ST_Intersects(  ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":[[[117.812658,38.926816],[117.813196,38.926622],[117.812679, 38.925415],[117.812065,38.925792],[117.812658,38.926816]]]}')),4326) , s.geom) 
        union
        select 111111 as gid,ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON('{"type":"Polygon","coordinates":[[[117.812658,38.926816],[117.813196,38.926622],[117.812679, 38.925415],[117.812065,38.925792],[117.812658,38.926816]]]}')),4326) ; 
    
    
      SELECT gid,geom FROM public.eploygon s where ST_Intersects(  ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON('{"type":"Point","coordinates":[117.812658,38.926816]}')),4326) , s.geom) 
        union
        select 111111 as gid,ST_GeomFromText(ST_AsText(ST_GeomFromGeoJSON('{"type":"Point","coordinates":[117.812658,38.926816]}')),4326);
    博客地址: http://www.cnblogs.com/defineconst/
    博客版权: 本文以学习、研究和分享为主,欢迎转载和各类爬虫,但必须在文章页面明显位置给出原文链接。 如果文中有不妥或者错误的地方还望高手的您指出,以免误人子弟。如果您有更好的建议,不如留言一起讨论,共同进步! 再次感谢您耐心的读完本篇文章。
  • 相关阅读:
    5G 需要换 SIM 卡吗?
    多线程设计模式
    4G LTE/EPC UE 的附着与去附着
    4G EPS 的网络协议栈
    MYSQL远程登录权限设置 ,可以让Navicat远程连接服务器的数据库
    MYSQL远程登录权限设置 ,可以让Navicat远程连接服务器的数据库
    MYSQL远程登录权限设置 ,可以让Navicat远程连接服务器的数据库
    2018年要学习的10大Python Web框架
    2018年要学习的10大Python Web框架
    2018年要学习的10大Python Web框架
  • 原文地址:https://www.cnblogs.com/defineconst/p/15527405.html
Copyright © 2011-2022 走看看