ArcGIS Server Banner

ST_Centroid

ST_Centroid

Release 9.3 E-mail This TopicPrintable VersionGive Us feedback

Definition

ST_Centroid takes a polygon or multipolygon and returns the point that is in the center of the geometry's envelope. That means that the centroid point is halfway between the geometry's minimum and maximum X and Y extents.

Syntax

Oracle

sde.st_centroid (pl1 sde.st_geometry)
sde.st_centroid (mpl1 sde.st_geometry)

PostgreSQL

st_centroid (pl1 st_geometry)
st_centroid (mpl1 st_geometry)

Return type

ST_Point

Example

The city GIS technician wants to display the building footprint multipolygons as single points in a building density graphic. The building footprints are stored in the bfp table that was created and populated with the following statements.

Oracle

CREATE TABLE bfp (
building_id integer,
footprint sde.st_geometry);

INSERT INTO bfp VALUES (
1,
sde.st_polygon ('polygon ((0 0, 0 10, 10 10, 10 0, 0 0))', 0)
);

INSERT INTO bfp VALUES (
2,
sde.st_polygon ('polygon ((20 0, 30 20, 40 0, 20 0))', 0)
);

INSERT INTO bfp VALUES (
3,
sde.st_polygon ('polygon ((20 30, 25 35, 30 30, 20 30))', 0)
);

PostgreSQL

CREATE TABLE bfp (
building_id integer,
footprint st_geometry);

INSERT INTO bfp VALUES (
1,
st_polygon ('polygon ((0 0, 0 10, 10 10, 10 0, 0 0))', 0)
);

INSERT INTO bfp VALUES (
2,
st_polygon ('polygon ((20 0, 30 20, 40 0, 20 0))', 0)
);

INSERT INTO bfp VALUES (
3,
st_polygon ('polygon ((20 30, 25 35, 30 30, 20 30))', 0)
);

The ST_Centroid function returns the centroid of each building footprint multipolygon. The ST_AsText function converts each centroid point into a text representation recognized by the application.

Oracle

SELECT building_id,
sde.st_astext (sde.st_centroid (footprint)) Centroid
FROM bfp;

BUILDING_ID                   Centroid

   1                     POINT  (5.00000000 5.00000000)
   2                     POINT  (30.00000000 10.00000000)
   3                     POINT  (25.00000000 32.50000000)

PostgreSQL

SELECT building_id,
st_astext (st_centroid (footprint)) AS centroid
FROM bfp;

building_id                  centroid

   1                     POINT  (5 5)
   2                     POINT  (30 10)
   3                     POINT  (25 33)

See Also

  • An overview of SQL functions used with ST_Geometry types