Examples of how spatial functions operate
This information provides an overview of spatial functions and examples of how you can use them.
IBM® Spatial Support for Db2 for z/OS® provides
functions that perform various operations on spatial data. Generally
speaking, these functions can be categorized according to the type
of operation that they perform. Table 1 lists
these categories, along with examples. The text following Table 1 shows coding for these examples.
| Category of function | Example of operation |
|---|---|
| Returns information about specific geometries. | Return the extent, in square miles, of the sales area of Store 10. |
| Makes comparisons. | Determine whether the location of a customer's home lies within the sales area of Store 10. |
| Derives new geometries from existing ones. | Derive the sales area of a store from its location. |
Example 1: Returns information about specific geometries
In this example, the ST_Area function returns a numeric value that represents the sales area of store 10. The function will return the area in the same units as the units of the coordinate system that is being used to define the area's location.
SELECT db2gse.ST_Area(sales_area)
FROM stores
WHERE id = 10
Example 2: Makes comparisons
In this example,
the ST_Within function compares the coordinates of the geometry representing
a customer's residence with the coordinates of a geometry representing
the sales area of store 10. The function's output will signify whether
the residence lies within the sales area.
SELECT c.first_name, c.last_name, db2gse.ST_Within(c.location, s.sales_area)
FROM customers as c. stores AS s
WHERE s.id = 10
Example 3: Derives new geometries from existing ones
In this example, the ST_Buffer function derives a geometry
representing a store's sales area from a geometry representing the
store's location. The data type is ST_Geometry for both the store's
sales area and location.
UPDATE stores
SET sales_area = db2gse.ST_Polygon(db2gse.ST_Buffer(location, 10, 'KILOMETERS'))
WHERE id = 10