Predefined Spatial Functions Available from OML Embedded Python Execution
Spatial AI provides some pre-defined spatial functions. You can call the
register_sai_scripts
function (in oraclesai.oml
) to
register the pre-defined spatial functions for embedded execution.
The following code registers the pre-defined spatial functions for embedded
execution into the script repository and lists them using the
oml.script.dir
function.
import oml
from oraclesai.oml import register_sai_scripts
# register for all the users and overwrite if already registered
register_sai_scripts(is_global=True, overwrite=True)
# list registered scripts
oml.script.dir(sctype='all')[['name']]
Note the errorModelPredict
function (defined in Store a Function for Embedded Execution) in the list of registered functions along with the other pre-defined functions.
name
0 clustering
1 compute_global_spatial_autocorrelation
2 compute_local_spatial_autocorrelation
3 compute_spatial_weights
4 create_spatial_lag
5 errorModelPredict
The following table lists the parameters that are required for all the pre-defined spatial functions.
Parameter | Description |
---|---|
oml_connect |
This parameter must always be true since all the
pre-defined spatial functions require a connection to the
database.
|
table |
The name of a database table. |
The rest of the parameters may vary depending on the spatial function.
The following table describes each one of the pre-defined spatial functions for embedded execution.
Spatial Functions | Description |
---|---|
compute_spatial_weights | This function computes the spatial weights for the given spatial
table and stores a SpatialWeights object in the data
store according to the save_weights_as
parameter.
|
compute_global_spatial_autocorrelation | Computes the Moran’s I statistic for the given spatial table and column. The function returns the value of the Moran’s I statistic, its z-value, and its p-value. |
compute_local_spatial_autocorrelation | Calculates the Local Moran’s I statistic of all the observations from the given spatial table. The function returns a table containing the Local Moran’s I statistic for each row, along with the z-value and p-value. |
create_spatial_lag | Computes the spatial lag for the given column of the provided spatial table. The function returns a table with the calculated spatial lag for each row from the input table. |
clustering | Executes a clustering algorithm with the data from the
given spatial table, using only the specified columns or all the columns
if the columns parameter is not provided. Available
clustering methods are DBSCAN ,
AGGLOMERATIVE , and KMEANS .
|
All the predefined spatial functions support computing the spatial weights and storing them in a datastore for later use. The goal of these functions is to execute common tasks involving spatial information. You can always add more functions for specific purposes as described in Store a Function for Embedded Execution.