Create SDO_GEOMETRY polygon circle from center and radius

5.6k views Asked by At

I have the coordinates of the center and radius in meters. How can I create an SDO_GEOMETRY type circle, because it need at least three points of the circle, as in this example?

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

There are 2 answers

3
Albert Godfrind On

Using three points for representing a circle is only possible if the data is projected. If your data is geodetic (i.e. your center is in longitude/latitude) then the only way to represent a circle is by densifying it. You can do that using the SDO_UTIL.CIRCLE_POLYGON() function.

For example:

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. 

If your data is projected, then use the following function to generate a 3-point circle:

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

For example:

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 row selected.

0
vini On

If the center (x,y) and the radius r are given, then you can simply form 3 points as follows: (x-r,y),(x,y+r),(x+r,y) and use them in SDO_ORDINATE_ARRAY. In the oracle documentation, its mentioned that they require 3 non-collinear points, which lie on the circumference of the circle. Above mentioned points, give such points.