从中心和半径创建SDO_GEOMETRY多边形圆

时间:2015-06-26 15:03:08

标签: oracle oracle-spatial

我有中心坐标和以米为单位的半径。 如何创建SDO_GEOMETRY类型的圆,因为它至少需要圆的三个点,如本例所示?

INSERT INTO cola_markets VALUES(
  4,
  'cola_d',
  SDO_GEOMETRY(
    2003,  -- two-dimensional polygon
    NULL,
    NULL,
    SDO_ELEM_INFO_ARRAY(1,1003,4), -- one circle
    SDO_ORDINATE_ARRAY(8,7, 10,9, 8,11)
  )
);

2 个答案:

答案 0 :(得分:1)

如果给出了中心(x,y)和半径r,那么您可以按如下方式简单地形成3个点:(x-r,y),(x,y+r),(x+r,y)并在SDO_ORDINATE_ARRAY中使用它们。在oracle文档中,它提到它们需要3个非共线点,它们位于圆周上。上面提到的要点,给出这样的观点。

答案 1 :(得分:0)

只有在投影数据时才可以使用三个点来表示圆。如果您的数据是大地测量的(即您的中心位于经度/纬度),那么表示圆圈的唯一方法就是将其加密。您可以使用SDO_UTIL.CIRCLE_POLYGON()功能执行此操作。

例如:

SQL> select sdo_util.circle_polygon (sdo_geometry(2001, 4326, sdo_point_type(-74.064962, 40.7113, null), null, null),500,1) from dual;

SDO_UTIL.CIRCLE_POLYGON(SDO_GEOMETRY(2001,4326,SDO_POINT_TYPE(-74.064962,40.711
-------------------------------------------------------------------------------
SDO_GEOMETRY(2003, 4326, NULL, SDO_ELEM_INFO_ARRAY(1, 1003, 1), SDO_ORDINATE_ARRAY(-74.064962, 40.7067975, -74.06422, 40.706833, -74.063491, 40.7069389, -74.062784, 40.7071136, -74.062112, 40.7073544, -74.061484, 40.7076573, -74.060912, 40.7080177, -74.060403, 40.7084299, -74.059966, 40.7088873, -74.059608, 40.7093828, -74.059335, 40.7099085, -74.05915, 40.7104562, -74.059057, 40.7110171, -74.059057, 40.7115826, -74.05915, 40.7121435, -74.059334, 40.7126912, -74.059608, 40.713217, -74.059966, 40.7137125, -74.060403, 40.7141699, -74.060911, 40.7145821, -74.061484, 40.7149426, -74.062111, 40.7152456, -74.062784, 40.7154863, -74.06349, 40.7156611, -74.06422, 40.715767, -74.064962, 40.7158025, -74.065704, 40.715767, -74.066434, 40.7156611, -74.06714, 40.7154863, -74.067813, 40.7152456, -74.06844, 40.7149426, -74.069013, 40.7145821, -74.069521, 40.7141699, -74.069958, 40.7137125, -74.070316, 40.713217, -74.07059, 40.7126912, -74.070774, 40.7121435, -74.070867, 40.7115826, -74.070867, 40.7110171, -74.070774, 40.7104562, -74.070589, 40.7099085, -74.070316, 40.7093828, -74.069958, 40.7088873, -74.069521, 40.7084299, -74.069012, 40.7080177, -74.06844, 40.7076573, -74.067812, 40.7073544, -74.06714, 40.7071136, -74.066433, 40.7069389, -74.065704, 40.706833, -74.064962, 40.7067975))

1 row selected. 

如果您的数据已投射,请使用以下函数生成3点圆圈:

create or replace function circle (
  center sdo_geometry,
  radius number
)
return sdo_geometry
is
  x number;
  y number;
begin
  x := center.sdo_point.x;
  y := center.sdo_point.y;
  return sdo_geometry (
     2003, center.sdo_srid, null,
     sdo_elem_info_array(1, 1003, 4),
     sdo_ordinate_array (
       x-radius, y,
       x, y+radius,
       x+radius, y
    )
  );
end;
/

例如:

SQL> select circle (sdo_geometry(2001, 3857, sdo_point_type(-8244873.9, 4969851.29, null), null, null), 500) from dual;

CIRCLE(SDO_GEOMETRY(2001,3857,SDO_POINT_TYPE(-8244873.9,4969851.29,NULL),NULL,N
-------------------------------------------------------------------------------
SDO_GEOMETRY(2003, 3857, NULL, SDO_ELEM_INFO_ARRAY(1,1003, 4), SDO_ORDINATE_ARRAY(-8245373.9, 4969851.29, -8244873.9, 4970351.29, -8244373.9, 4969851.29))

选择了1行。