Oracle spatial 將Geometry轉換為gml字串

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.