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/)