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/
    博客版权: 本文以学习、研究和分享为主,欢迎转载和各类爬虫,但必须在文章页面明显位置给出原文链接。 如果文中有不妥或者错误的地方还望高手的您指出,以免误人子弟。如果您有更好的建议,不如留言一起讨论,共同进步! 再次感谢您耐心的读完本篇文章。
  • 相关阅读:
    Oracle 18c新特性一览
    iOS xcode缓存问题
    预编译头文件
    iOS 限制UITextField输入字符
    网络通信之 字节序转换原理与网络字节序、大端和小端模式
    iOS 库文件制作
    iOS 全屏布局
    内存问题 动态加载地址和运行时地址
    申请工作居住证政策解答
    phpsession配置
  • 原文地址:https://www.cnblogs.com/defineconst/p/15527405.html
Copyright © 2011-2022 走看看