Oracle 关于WKT构造SDO_GEOMETRY的问题。

由于系统前端使用OpenLayers框架,后台数据库使用oracle spatial。大家知道Oracle spatial的SDO_GEOMETRY十分复杂,如果使用期java api ,那就坑爹了,要处理相当多的逻辑和数据类型。今天我有这么一个需求,从前进行多边形查询,我想到了一个好办法,由openlayers构造一个wkt空间串,然后调用SDO_UTIL.FROM_WKTGEOMETRY函数将wkt转为SDO_GEOMETRY,然后再调用SDO_ANYINTERACT进行空间查询,这种方法貌似木有问题,sql如下:select *
  from TBSVRC_RESPUBLISHITEMS t
 where SDO_ANYINTERACT(F_SPATIALEXTENT,SDO_UTIL.from_wktgeometry('POLYGON((80.83422302246095
                                                          20.518481140136714,
                                                          120.4135076904297
                                                          20.518481140136714,
                                                          120.4135076904297
                                                          50.314989929199214,
                                                          80.83422302246095
                                                          50.314989929199214,
                                                          80.83422302246095
                                                          20.518481140136714))') )='TRUE'

将sql在数据库中运行,结果报错:传入的sdo_geometry和数据库表sdo_geometry的srid不同,不能进行空间查询。忽然想起WKT可以表达空间数据信息,但是木有SRID信息。一下傻眼了,那怎么办呢?看看SDO_UTIL包的函数,也都木有将SDO_GEOMETRY设置SRID的函数。于是在网上搜索半天,也无解,搜搜oracle spatial官方文档,也是半天无解。我于是想还是好好分析SDO_GEOMETRY吧。嘿,忽然发现桃花源,SDO_GEOMETRY是一个类型,本身也是一个函数。再仔细看看还有构造参数,喔,问题解决了,sql如下:

select *
  from TBSVRC_RESPUBLISHITEMS t
 where SDO_ANYINTERACT(F_SPATIALEXTENT,sdo_geometry('POLYGON((80.83422302246095
                                                          20.518481140136714,
                                                          120.4135076904297
                                                          20.518481140136714,
                                                          120.4135076904297
                                                          50.314989929199214,
                                                          80.83422302246095
                                                          50.314989929199214,
                                                          80.83422302246095
                                                          20.518481140136714))',8307))='TRUE'

oracle spatial 爱死你了!

你可能感兴趣的:(oracle)