用Oracle的函数,判断点是否在多边形内

转自:http://blog.csdn.net/familyshizhouna/article/details/68944683

参考:http://blog.csdn.net/qwlovedzm/article/details/5337662

投影坐标系(PCS):http://support.supermap.com.cn/DataWarehouse/WebDocHelp/iServer/Appendix/CoordSystem/PCS_Code.htm

ps:sql语句中注释掉的32774是坐标系代码.而sql语句中默认使用的坐标系是null

--create table
create table t5(
    id number,
    location sdo_geometry --
);

--插入空间元数据
insert into user_sdo_geom_metadata
(table_name,column_name,srid,diminfo)
values
(
 't5',
 'location',
  NULL,--32774,
 sdo_dim_array
 (
   sdo_dim_element
   (
  'longitude',
  -180,
  180,
  0.1
  ),
   sdo_dim_element
  (
   'latitude',
   -90,
   90,
   0.1
   )
 )
);

--建立空间索引
create index test5_index on t5(location)
 indextype is mdsys.spatial_index;

--插入数据1
insert into t5 values(
    1, --id
    sdo_geometry
    (
        2001,
        --32774,
        NULL,
        SDO_POINT_TYPE(-33,40,NULL),
        NULL,
        NULL
    )
);

--查询表T5中的点是否在给定的多边形中
select * from T5 where
sdo_inside("LOCATION", SDO_GEOMETRY(
    2003,  -- two-dimensional polygon
    NULL,--32774,
    NULL,
    sdo_elem_info_array (1,2003,2),
    SDO_ORDINATE_ARRAY(-122.526398,40.708813, -122.526398,40.822802, 40.822802,-122.373962, -122.373962,40.708813, -122.526398,40.708813) --多边形
  ))='TRUE';


select * from T5 where
sdo_relate("LOCATION", SDO_GEOMETRY(
    2003,  -- two-dimensional polygon
    NULL ,--32774,
    NULL,
    sdo_elem_info_array (1,2003,2),
  SDO_ORDINATE_ARRAY(-122.526398,40.708813, -122.526398,40.822802, 40.822802,-122.373962, -122.373962,40.708813, -122.526398,40.708813) --多边形
  )
,'MASK=INSIDE')='TRUE';

 

posted on 2018-01-12 15:43  lpx15312  阅读(2066)  评论(0编辑  收藏  举报

导航