compute_local_spatial_autocorrelation
Format
compute_local_spatial_autocorrelation(table, column, result_table=None, key_column=None,
weights=None, weights_def=None, save_weights_as=None, spatial_col=None, crs=None)
Parameters
The parameters for this pre-defined function are described in the following table.
Parameter | Description |
---|---|
table |
Name of the spatial table. |
column |
The column of interest whose values are used to compute the local autocorrelation index. |
result_table |
If specified, it calls the function
oml.create to store a pandas
DataFrame containing the results of the local
autocorrelation in a table with the specified name.
|
key_column |
If specified, the specified column is added to the
resulting DataFrame . Otherwise, a column with the
DataFrame’s index is attached to the result.
|
weights |
Required when trying to use spatial weights already
stored in the data store. Internally it calls the function
olm.ds.load . The supported parameters are
ds_name and obj_name ,
indicating the data store name and object name,
respectively.
|
weights_def |
Required if the parameter weights
is not specified. Establishes the relationship between neighboring
locations.
This is passed as a json object specifying the type of the weights definition and its parameters. Each parameter is defined in detail in API Reference documentation. The following lists the supported types and parameters:
|
save_weights_as |
Only used if weights_def is
defined. Specifies how the spatial weights are stored in the data
store. The value is a json file that determines the parameters of
oml.ds.save . The supported parameters are:
[ds_name, obj_name, overwrite_ds, append, overwrite_obj,
grantable, compression] . Some parameter names slightly
differ from those in the oml.ds.save function. The
parameter overwrite_obj is used to indicate whether
an already existing object should be replaced with the current
object.
|
spatial_col |
Specifies the column containing the geometries. The column can be specified in the table’s metadata. If not specified, the column name is retrieved from the table. |
crs |
Specifies the Coordinate Reference System. If not specified, it is inferred from the table. |
Example
The following example calculates the local Moran’s I statistic for each
row in a table from a specific column and uses the spatial weights already saved in
a data store. It uses the median_income
column and the spatial
weights from the spatial
data store with the object name
la_bg_knn4
, corresponding to the spatial weights calculated
with the K-nearest neighbors method with K=4.
select *
from table(
pyqEval(
'{
"oml_connect": true,
"table": "oml_user.la_block_groups",
"key_column": "geoid",
"column": "median_income",
"weights": {"ds_name":"spatial", "obj_name": "la_bg_knn4"}
}',
'{ "geoid": "VARCHAR2(50)", "I": "NUMBER", "p_value": "NUMBER", "z_value": "NUMBER", "quadrant": "NUMBER" }',
'compute_local_spatial_autocorrelation'
)
);
For each row in the table, the result contains the following:
- The local Moran’s I statistic.
- The p-value.
- The z-value.
- The belonging quadrant.
- A high value surrounded by high values.
- A low value around high values.
- A low value surrounded by low values.
- A high value around high values.