Oracle spatial 将Geometry转换为gml字符串

oracle spatial有个函数  将geometry转换为gml.函数名称为SDO_UTIL.TO_GMLGEOMETRY(geo)。这个geo就是SDO.Geometry类型 可是这个函数的返回值是Clob类型的Geometry。当然我们可以使用TO_CHAR函数 将其转为字符串类型。下面是一个测试的sql:

select t.objectid,TO_CHAR(sdo_util.TO_GMLGEOMETRY(t.shape)) AS GML,t.comp_type,t.datatype,t.comp_name,t.health_lic,t.shape.SDO_POINT.X as x,t.shape.SDO_POINT.Y as y,t.reg_addr,t.bus_addr from t_publicplaces t where 1=1 and substr(t.comp_type,0,2)=’01’ and sdo_within_distance(t.SHAPE,SDO_GEOMETRY(2001,8307,SDO_POINT_TYPE(116.4,39.9,NULL),NULL,NULL),’distance=1500.0 unit=m’)=’TRUE’

查询的gml字符串为:

<gml:Point srsName=”SDO:8307″ xmlns:gml=”http://www.opengis.net/gml”><gml:coordinates decimal=”.” cs=”,” ts=” “>116.4,39.9 </gml:coordinates></gml:Point>。

由于我们前端使用openlayers作为客户端  openlayers常接收gml、wkt、geojson等字符串数据。至于wkt oralce spatial是内置支持的,这个函数名称叫get_wkt(),它是geometry直接的方法。那么将上面的函数换一下就是:

select t.objectid,TO_CHAR(t.shape.get_wkt()) AS wkt,t.comp_type,t.datatype,t.comp_name,t.health_lic,t.shape.SDO_POINT.X as x,t.shape.SDO_POINT.Y as y,t.reg_addr,t.bus_addr from t_publicplaces t where 1=1 and substr(t.comp_type,0,2)=’01’ and sdo_within_distance(t.SHAPE,SDO_GEOMETRY(2001,8307,SDO_POINT_TYPE(116.4,39.9,NULL),NULL,NULL),’distance=1500.0 unit=m’)=’TRUE’

查询wkt字符串:POINT (116.4 39.9)。

如果将它专为geojson,目前无解,只能自己使用程序拼写geojson字符串(规则见其官网:http://geojson.org/

转载自:https://blog.csdn.net/weixin_33802505/article/details/85521974

You may also like...