Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Geometry

These functions operate on a GeoJSON Geometry.

bounding_box

Find the bounding box of a GeoJSON geometry, returning a Polygon.

Example

Given:

{
  "type": "Polygon",
  "coordinates": [
    [
      [0, 1],
      [1, 0],
      [2, 2],
      [0, 1]
    ]
  ]
}

bounding_box returns

{
  "type": "Polygon",
  "coordinates": [
    [
      [2, 0],
      [2, 2],
      [0, 2],
      [0, 0],
      [2, 0]
    ]
  ]
}

Try in the gq Playground

buffer

Add a buffer around any Geometry (eg. buffer(1)) where the default unit is kilometers.

A second, optional parameter is supported which takes values like so:

{
    unit: "kilometers" | "meters" | "miles",
    line_join: "round" | "miter" | "bevel",
    line_cap: "butt" | "round" | "square"
}

The default values are:

{
    unit: "kilometers",
    line_join: "round",
    line_cap: "round"
}

As an example:

buffer(1000, {unit: "meters"})

is equivalent to:

buffer(1, {unit: "kilometers"})

or simply:

buffer(1)

centroid

Find the centroid of a GeoJSON geometry, returning a Point.

Example

Given:

{
  "type": "Polygon",
  "coordinates": [
    [
      [0, 0],
      [2, 0],
      [2, 2],
      [0, 2],
      [0, 0]
    ]
  ]
}

centroid returns

{
  "type": "Point",
  "coordinates": [1, 1]
}

Try in the gq Playground

concave_hull

Find the concave hull of a GeoJSON geometry (LineString, MultiLineString, MultiPoint, MultiPolygon, or Polygon), returning a Polygon.

Example

Given:

{
  "type": "MultiPoint",
  "coordinates": [
    [0.0, 0.0],
    [3.0, 0.0],
    [1.0, 2.0],
    [0.0, 4.0]
  ]
}

concave_hull returns

{
  "type": "Polygon",
  "coordinates": [
    [
      [3, 0],
      [1, 2],
      [0, 4],
      [0, 0],
      [3, 0]
    ]
  ]
}

Try in the gq Playground

contains

Whether the input geometry contains the argument value (returns a boolean).

Example

Given:

{
  "type": "Polygon",
  "coordinates": [
    [
      [2, 0],
      [2, 2],
      [0, 2],
      [0, 0],
      [2, 0]
    ]
  ]
}

the program

contains({"type": "Point", "coordinates": [1, 1]})

returns true.

Try in the gq Playground

contained_by

Like contains, except the arguments are reversed.

convex_hull

Find the convex hull of a GeoJSON geometry, returning a Polygon.

Example

Given:

{
  "type": "Polygon",
  "coordinates": [
    [
      [0.0, 0.0],
      [4.0, 0.0],
      [4.0, 1.0],
      [1.0, 1.0],
      [1.0, 4.0],
      [0.0, 4.0],
      [0.0, 0.0]
    ]
  ]
}

convex_hull returns

{
  "type": "Polygon",
  "coordinates": [
    [
      [4, 0],
      [4, 1],
      [1, 4],
      [0, 4],
      [0, 0],
      [4, 0]
    ]
  ]
}

Try in the gq Playground

feature

Wrap a geometry in a Feature.

Example

Given:

{
  "type": "Point",
  "coordinates": [0, 0]
}

feature returns

{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [0, 0]
  },
  "properties": null
}

Try in the gq Playground

simplify

Simplify a geometry (Polygon, MultiPolygon, LineString, MultiLineString) given an epsilon value (eg. simplify(1.0)).