Ban*_*our 5 oracle latitude-longitude oracle-spatial
我怎样才能从oracle中获得拉特和长点?
像这样:
MDSYS.SDO_GEOMETRY(2001,4326,NULL,
MDSYS.SDO_ELEM_INFO_ARRAY(1,1,1),
MDSYS.SDO_ORDINATE_ARRAY(51.702814,32.624736))
Run Code Online (Sandbox Code Playgroud)
Alb*_*ind 14
您显示的符号不是表示单个2D或3D点的最佳符号.编码这些点的常用且最有效的方法是:
SDO_GEOMETRY(2001,4326,SDO_POINT_TYPE(51.702814,32.624736,NULL),NULL,NULL)
Run Code Online (Sandbox Code Playgroud)
我见过的所有GIS工具都使用这种表示法.你展示的那个也是有效的 - 它只是使用更多的存储空间.但这两个符号在功能上完全相同.
使用紧凑符号,获得单个坐标是微不足道的.例如,考虑到US_CITIES在上面的紧凑符号中包含点:
select c.city, c.location.sdo_point.x longitude, c.location.sdo_point.y latitude
from us_cities c where state_abrv='CO';
CITY LONGITUDE LATITUDE
------------------------------------------ ---------- ----------
Aurora -104.72977 39.712267
Lakewood -105.11356 39.6952
Denver -104.87266 39.768035
Colorado Springs -104.7599 38.8632
4 rows selected.
Run Code Online (Sandbox Code Playgroud)
从您使用的更复杂的基于数组的表示法中获得相同的结果会更复杂.您可以使用SDO_UTIL.GETVERTICES方法.例如,假设US_CITIES_A包含相同的点,但在基于数组的表示法中:
select city, t.x longitude, t.y latitude
from us_cities_a, table (sdo_util.getvertices(location)) t
where state_abrv = 'CO';
CITY LONGITUDE LATITUDE
------------------------------------------ ---------- ----------
Aurora -104.72977 39.712267
Lakewood -105.11356 39.6952
Denver -104.87266 39.768035
Colorado Springs -104.7599 38.8632
4 rows selected.
Run Code Online (Sandbox Code Playgroud)
我实际上发现更简单的另一种方法是只定义几个简单的函数来从数组中提取值:
create or replace function get_x (g sdo_geometry) return number is
begin
return g.sdo_ordinates(1);
end;
/
Run Code Online (Sandbox Code Playgroud)
和
create or replace function get_y (g sdo_geometry) return number is
begin
return g.sdo_ordinates(2);
end;
/
Run Code Online (Sandbox Code Playgroud)
然后使用这些函数可以实现更简单的语法:
select city, get_x(location) longitude, get_y(location) latitude
from us_cities_a
where state_abrv = 'CO';
CITY LONGITUDE LATITUDE
------------------------------------------ ---------- ----------
Aurora -104.72977 39.712267
Lakewood -105.11356 39.6952
Denver -104.87266 39.768035
Colorado Springs -104.7599 38.8632
4 rows selected.
Run Code Online (Sandbox Code Playgroud)
您可以使用sdo_util.getvertices.文档中的示例
SELECT c.mkt_id, c.name, t.X, t.Y, t.id
FROM cola_markets c,
TABLE(SDO_UTIL.GETVERTICES(c.shape)) t
ORDER BY c.mkt_id, t.id;
Run Code Online (Sandbox Code Playgroud)