Documentation Home
MySQL 5.5 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 26.8Mb
PDF (A4) - 26.9Mb
PDF (RPM) - 25.2Mb
HTML Download (TGZ) - 6.3Mb
HTML Download (Zip) - 6.3Mb
HTML Download (RPM) - 5.3Mb
Man Pages (TGZ) - 157.6Kb
Man Pages (Zip) - 260.8Kb
Info (Gzip) - 2.6Mb
Info (Zip) - 2.6Mb
Excerpts from this Manual

MySQL 5.5 Reference Manual  /  ...  /  Polygon and MultiPolygon Property Functions

12.15.7.4 Polygon and MultiPolygon Property Functions

Functions in this section return properties of Polygon or MultiPolygon values.

  • Area({poly|mpoly})

    Returns a double-precision number indicating the area of the Polygon or MultiPolygon argument, as measured in its spatial reference system. For arguments of dimension 0 or 1, the result is 0. If the argument is an empty geometry the return value is 0. If the argument is NULL the return value is NULL.

    mysql> SET @poly =
           'Polygon((0 0,0 3,3 0,0 0),(1 1,1 2,2 1,1 1))';
    mysql> SELECT Area(GeomFromText(@poly));
    +---------------------------+
    | Area(GeomFromText(@poly)) |
    +---------------------------+
    |                         4 |
    +---------------------------+
    
    mysql> SET @mpoly =
        -> 'MultiPolygon(((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1)))';
    mysql> SELECT Area(GeomFromText(@mpoly));
    +----------------------------+
    | Area(GeomFromText(@mpoly)) |
    +----------------------------+
    |                          8 |
    +----------------------------+
  • Centroid({poly|mpoly})

    Returns the mathematical centroid for the Polygon or MultiPolygon argument as a Point. The result is not guaranteed to be on the argument. If the argument is NULL or an empty geometry, the return value is NULL.

    mysql> SET @poly =
        -> GeomFromText('POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7,5 5))');
    mysql> SELECT GeometryType(@poly),AsText(Centroid(@poly));
    +---------------------+--------------------------------------------+
    | GeometryType(@poly) | AsText(Centroid(@poly))                    |
    +---------------------+--------------------------------------------+
    | POLYGON             | POINT(4.958333333333333 4.958333333333333) |
    +---------------------+--------------------------------------------+
  • ExteriorRing(poly)

    Returns the exterior ring of the Polygon value poly as a LineString. If the argument is NULL or an empty geometry, the return value is NULL.

    mysql> SET @poly =
        -> 'Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))';
    mysql> SELECT AsText(ExteriorRing(GeomFromText(@poly)));
    +-------------------------------------------+
    | AsText(ExteriorRing(GeomFromText(@poly))) |
    +-------------------------------------------+
    | LINESTRING(0 0,0 3,3 3,3 0,0 0)           |
    +-------------------------------------------+
  • InteriorRingN(poly, N)

    Returns the N-th interior ring for the Polygon value poly as a LineString. Rings are numbered beginning with 1. If the argument is NULL or an empty geometry, the return value is NULL.

    mysql> SET @poly =
        -> 'Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))';
    mysql> SELECT AsText(InteriorRingN(GeomFromText(@poly),1));
    +----------------------------------------------+
    | AsText(InteriorRingN(GeomFromText(@poly),1)) |
    +----------------------------------------------+
    | LINESTRING(1 1,1 2,2 2,2 1,1 1)              |
    +----------------------------------------------+
  • NumInteriorRings(poly)

    Returns the number of interior rings in the Polygon value poly. If the argument is NULL or an empty geometry, the return value is NULL.

    mysql> SET @poly =
        -> 'Polygon((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))';
    mysql> SELECT NumInteriorRings(GeomFromText(@poly));
    +---------------------------------------+
    | NumInteriorRings(GeomFromText(@poly)) |
    +---------------------------------------+
    |                                     1 |
    +---------------------------------------+

User Comments
User comments in this section are, as the name implies, provided by MySQL users. The MySQL documentation team is not responsible for, nor do they endorse, any of the information provided here.
Sign Up Login You must be logged in to post a comment.