compute_spatial_weights

Format

compute_spatial_weights(table, weights_def, save_weights_as, 
    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.
weights_def Defines 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 the API Reference documentation.

The following lists the supported types and parameters:

  • KNN: [k]
  • Kernel: [bandwidth, fixed, k, function]
  • DistanceBand: [threshold, p, alpha, binary]
  • Queen
  • Rook
save_weights_as Specifies how the object is 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 code calculates the spatial weights of the dataset from the table specified in the table parameter, using the strategy defined in the weights_def parameter. This example uses the K-nearest neighbor approach with K=4. The result is saved into the spatial data store with the object name la_bg_knn4.

select *
    from table( 
        pyqEval(
            par_lst => '{  
                "oml_connect": true, 
                "table": "oml_user.la_block_groups", 
                "weights_def": {"type": "KNN", "k": 4},
                "save_weights_as": {"ds_name": "spatial", "obj_name": "la_bg_knn4", "append": true, "overwrite_obj": true}
            }',
            out_fmt => 'XML',
            scr_name =>  'compute_spatial_weights'
        )
    );