Geospatial queries

Split-apply-combine

We provide a geospatial version of the split-apply-combine pattern:

GeoTables.@groupbyMacro
@groupby(geotable, col₁, col₂, ..., colₙ)
@groupby(geotable, [col₁, col₂, ..., colₙ])
@groupby(geotable, (col₁, col₂, ..., colₙ))

Group geospatial geotable by columns col₁, col₂, ..., colₙ.

@groupby(geotable, regex)

Group geospatial geotable by columns that match with regex.

Examples

@groupby(geotable, 1, 3, 5)
@groupby(geotable, [:a, :c, :e])
@groupby(geotable, ("a", "c", "e"))
@groupby(geotable, r"[ace]")
source
GeoTables.@transformMacro
@transform(geotable, :col₁ = expr₁, :col₂ = expr₂, ..., :colₙ = exprₙ)

Returns geospatial geotable with columns col₁, col₂, ..., colₙ computed with expressions expr₁, expr₂, ..., exprₙ.

See also: @groupby.

Examples

@transform(geotable, :z = :x + 2*:y)
@transform(geotable, :w = :x^2 - :y^2)
@transform(geotable, :sinx = sin(:x), :cosy = cos(:y))

groups = @groupby(geotable, :y)
@transform(groups, :logx = log(:x))
@transform(groups, :expz = exp(:z))

@transform(geotable, {"z"} = {"x"} - 2*{"y"})
xnm, ynm, znm = :x, :y, :z
@transform(geotable, {znm} = {xnm} - 2*{ynm})
source
GeoTables.@combineMacro
@combine(geotable, :col₁ = expr₁, :col₂ = expr₂, ..., :colₙ = exprₙ)

Returns geospatial geotable with columns :col₁, :col₂, ..., :colₙ computed with reduction expressions expr₁, expr₂, ..., exprₙ.

If a reduction expression is not defined for the :geometry column, the geometries will be reduced using Multi.

See also: @groupby.

Examples

@combine(geotable, :x_sum = sum(:x))
@combine(geotable, :x_mean = mean(:x))
@combine(geotable, :x_mean = mean(:x), :geometry = centroid(:geometry))

groups = @groupby(geotable, :y)
@combine(groups, :x_prod = prod(:x))
@combine(groups, :x_median = median(:x))
@combine(groups, :x_median = median(:x), :geometry = centroid(:geometry))

@combine(geotable, {"z"} = sum({"x"}) + prod({"y"}))
xnm, ynm, znm = :x, :y, :z
@combine(geotable, {znm} = sum({xnm}) + prod({ynm}))
source

Geospatial join

GeoTables.geojoinFunction
geojoin(geotable₁, geotable₂, var₁ => agg₁, ..., varₙ => aggₙ; kind=:left, pred=intersects, on=nothing)

Joins geotable₁ with geotable₂ using a certain kind of join and predicate function pred that takes two geometries and returns a boolean ((g1, g2) -> g1 ⊆ g2).

Optionally, add a variable value match to join, in addition to geometric match, by passing a single name or list of variable names (strings or symbols) to the on keyword argument. The variable value match use the isequal function.

Whenever two or more matches are encountered, aggregate varᵢ with aggregation function aggᵢ. If no aggregation function is provided for a variable, then the aggregation function will be selected according to the scientific types: mean for continuous and first otherwise.

Kinds

  • :left - Returns all rows of geotable₁ filling entries with missing when there is no match in geotable₂.
  • :inner - Returns the subset of rows of geotable₁ that has a match in geotable₂.

Examples

geojoin(gtb1, gtb2)
geojoin(gtb1, gtb2, 1 => mean)
geojoin(gtb1, gtb2, :a => mean, :b => std)
geojoin(gtb1, gtb2, "a" => mean, pred=issubset)
geojoin(gtb1, gtb2, on=:a)
geojoin(gtb1, gtb2, kind=:inner, on=["a", "b"])

See also tablejoin.

source
GeoTables.tablejoinFunction
tablejoin(geotable, table, var₁ => agg₁, ..., varₙ => aggₙ; kind=:left, on)

Joins geotable with table using the values of the on variables to match rows with a certain kind of join.

on variables can be a single name or list of variable names (strings or symbols). The variable value match use the isequal function.

Whenever two or more matches are encountered, aggregate varᵢ with aggregation function aggᵢ. If no aggregation function is provided for a variable, then the aggregation function will be selected according to the scientific types: mean for continuous and first otherwise.

Kinds

  • :left - Returns all rows of geotable filling entries with missing when there is no match in table.
  • :inner - Returns the subset of rows of geotable that has a match in table.

Examples

tablejoin(gtb, tab, on=:a)
tablejoin(gtb, tab, 1 => mean, on=:a)
tablejoin(gtb, tab, :a => mean, :b => std, on=:a)
tablejoin(gtb, tab, "a" => mean, on=[:a, :b])
tablejoin(gtb, tab, kind=:inner, on=["a", "b"])

See also geojoin.

source