2.2 Distance-Based Weights

Distance-based weights are constructed using distance measures between all pairs of observations. The neighbor relation can be determined by a given distance band, so every other observation that falls within the distance band is considered as neighbors of one observation. Another way to determine neighbor relation is to find K nearest neighbors (KNN) for each observation.

For more information, please read: https://geodacenter.github.io/workbook/4b_dist_weights/lab4b.html

CONTENTS

  1. min_distthreshold()

  2. distance_weights()

  3. knn_weights()

1. min_distthreshold()

In order to avoid isolates (islands) that would result from too stringent a critical distance, the distance must be chosen such that each location has at least one neighbor. Such a distance conforms to a max-min criterion, i.e., it is the largest of the nearest neighbor distances.

Synopsis

Short version

float min_distthreshold(integer gid, geometry the_geom)

Full version

float min_distthreshold(integer gid, geometry the_geom,
    boolean is_arc, boolean is_mile)

Arguments

Input Arguments

Type

Description

gid

integer

the feature id of geometry: e.g. gid, fid, ogc_fid, cartodb_id

the_geom

geometry

the geometry (only points and polygons are supported)

is_arc

boolean

if compute arc distance between two observations. Default: FALSE.

is_mile

boolean

if convert distance unit from mile to kilometer(KM). Default: TRUE.

Return

Value

Description

float

the minimum distance that makes sure each observation has at least one neighbor

Examples

2. distance_weights()

With the distance band, one can create a distance-based spatial weights using WINDOW function distance_weights()

Synopsis

Short version:

Full Version:

Arguments:

Input Arguments

Type

Description

gid

integer

the feature id of geometry: e.g. gid, fid, ogcfid, cartodb_id

the_geom

geometry

the geometry (only points and polygons are supported)

dist_band

float

the distance band/threshold that makes sure each observation has at least one neighbor

power

float

the power/exponent corresponds to the number of times the base (dist_band) is used as a factor. Default: 1.

is_inverse

boolean

if apply inverse on distance value. Default: False.

is_arc

boolean

if compute arc distance between two observations. Default: FALSE.

is_mile

boolean

if convert distance unit from mile to kilometer(KM). Default: TRUE.

Return

Value

Description

bytea

the weights structure for each observation in binary format, which is defined in table 2.1.

Examples

3. knn_weights()

Synopsis

Short version:

Full Version:

Arguments:

Input Arguments

Type

Description

gid

integer

the feature id of geometry: e.g. gid, fid, ogcfid, cartodb_id

geom

geometry

the geometry (only points and polygons are supported)

k

integer

the k nearest neighbors

power

float

the power/exponent corresponds to the number of times the base (dist_band) is used as a factor. Default: 1.

is_inverse

boolean

if apply inverse on distance value. Default: False.

is_arc

boolean

if compute arc distance between two observations. Default: FALSE.

is_mile

boolean

if convert distance unit from mile to kilometer(KM). Default: TRUE.

Return

Value

Description

bytea

the weights structure for each observation in binary format, which is defined in table 2.1.

Examples

Last updated

Was this helpful?