How the PointOnSurface() function works in Mariadb?

The PointOnSurface() function is a built-in function in Mariadb that returns a point geometry that is guaranteed to lie on the surface of a given geometry.

Posted on

The PointOnSurface() function is a built-in function in Mariadb that returns a point geometry that is guaranteed to lie on the surface of a given geometry. The function is useful for finding a representative point of a geometry, such as a centroid, a label point, or a point of intersection. The function is also known as ST_PointOnSurface().

Syntax

The syntax of the PointOnSurface() function is as follows:

PointOnSurface(geometry)

Where geometry is a geometry value that represents any type of spatial feature, such as a point, a linestring, a polygon, or a geometry collection. If geometry is NULL or empty, the function returns NULL.

Examples

Example 1: Getting a point on the surface of a polygon with the PointOnSurface() function

The following example shows how to use the PointOnSurface() function to get a point on the surface of a polygon with the coordinates (10, 10), (10, 20), (20, 20), (20, 10), and (10, 10):

SELECT PointOnSurface(Polygon(Point(10, 10), Point(10, 20), Point(20, 20), Point(20, 10), Point(10, 10))) AS Point;

The function returns a point geometry that is encoded in a binary format. The function uses the Well-Known Binary (WKB) format to represent the point geometry. The point has the coordinates (10, 10), which is one of the vertices of the polygon.

Example 2: Getting a point on the surface of a linestring with the PointOnSurface() function

The following example shows how to use the PointOnSurface() function to get a point on the surface of a linestring with the coordinates (10, 10), (20, 20), and (30, 30):

SELECT PointOnSurface(LineString(Point(10, 10), Point(20, 20), Point(30, 30))) AS Point;

The function returns a point geometry that is encoded in a binary format. The function uses the Well-Known Binary (WKB) format to represent the point geometry. The point has the coordinates (10, 10), which is the first point of the linestring.

Example 3: Getting a point on the surface of a geometry collection with the PointOnSurface() function

The following example shows how to use the PointOnSurface() function to get a point on the surface of a geometry collection that contains a point, a linestring, and a polygon:

SELECT PointOnSurface(GeometryCollection(Point(10, 10), LineString(Point(20, 20), Point(30, 30)), Polygon(Point(40, 40), Point(40, 50), Point(50, 50), Point(50, 40), Point(40, 40)))) AS Point;

The function returns a point geometry that is encoded in a binary format. The function uses the Well-Known Binary (WKB) format to represent the point geometry. The point has the coordinates (10, 10), which is the point of the geometry collection.

There are some other functions in Mariadb that are related to the PointOnSurface() function. They are:

  • Centroid(): This function returns a point geometry that is the centroid or the center of mass of a given geometry. The function is useful for finding the average or the balance point of a geometry. The function is also known as ST_Centroid().
  • Intersection(): This function returns a geometry that is the intersection or the common area of two given geometries. The function is useful for finding the overlap or the shared part of two geometries. The function is also known as ST_Intersection().

Conclusion

The PointOnSurface() function is a useful function in Mariadb that allows you to return a point geometry that is guaranteed to lie on the surface of a given geometry. The function is helpful for finding a representative point of a geometry, such as a centroid, a label point, or a point of intersection. The function uses the Well-Known Binary (WKB) format to represent the point geometry. You can also use other functions like Centroid(), InteriorPoint(), and Intersection() to perform other operations on the geometry. I hope this article helped you understand how the PointOnSurface() function works in Mariadb.