Global

Methods

coords2geo()

From now on, use featurecollection

Deprecated:
  • Yes
Source:

properties/add()

From now on, use derive

Deprecated:
  • Yes
Source:

properties/head()

From now on, use head

Deprecated:
  • Yes
Source:

properties/keep()

From now on, use columns

Deprecated:
  • Yes
Source:

properties/remove()

From now on, use columns

Deprecated:
  • Yes
Source:

properties/remove()

From now on, use directly geojson.features.map(d => d.properties)

Deprecated:
  • Yes
Source:

properties/select()

From now on, use filter

Deprecated:
  • Yes
Source:

properties/subset()

From now on, use filter

Deprecated:
  • Yes
Source:

properties/tail()

From now on, use tail

Deprecated:
  • Yes
Source:

aggregate(data, options) → {object|array}

Aggregate geometries (based on topojson). The aggregate() function allows to merge all geometries of a geoJSON based on their topology. The id parameter allows to aggregate based on a specific field.

Based on topojson.merge.

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

options object

Optional parameters

Properties
Name Type Attributes Default Description
id string <optional>
null

The id of the features to aggregate

Source:
Returns:
  • A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry (it depends on what you've set as data).
Type
object | array
Example
geotoolbox.aggregate(*a geojson*)

autotype(data, options) → {object|array}

The function detects common data types such as numbers, dates and booleans, and convert properties values to the corresponding JavaScript type. Besed on d3.autoType().

Based on d3.autoType.

Parameters:
Name Type Description
data object | Array

A GeoJSON FeatureCollection or an array of objects

options object

Optional parameters

Properties
Name Type Attributes Default Description
mutate boolean <optional>
false

Use true to update the input data. With false, you create a new object, but the input object remains the same.

Source:
Returns:
  • A GeoJSON FeatureCollection or an array of objects. (it depends on what you've set as data).
Type
object | array
Example
geotoolbox.autotype(*a geojson or an array of objects*)

bbox(data) → {object|array}

Compute a geographic bounding box.

based on Jacob Rus code. See https://observablehq.com/@jrus/sphere-resample

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

Source:
Returns:
  • A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry (it depends on what you've set as data).
Type
object | array
Example
geotoolbox.bbox(*a geojson*)

border(data, options) → {object|array}

Extract boundaries from a GeoJSON FeatureCollection

Based on topojson.mesh() and topojson.neighbors()

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

options object

Optional parameters.

Properties
Name Type Attributes Default Description
id boolean <optional>
false

If you don't provide an id field (default), then the function returns a geoJSON with a single geometry. If you choose an id field, the function returns a geoJSON with multiple geometries and associated codes (two ids for each geometry).

Source:
Returns:
  • A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry (it depends on what you've set as data).
Type
object | array
Example
geotoolbox.border(*a geojson*, {id: "ISO3"})

(async) buffer(data, options) → {object|array}

Create a buffer

Based on geos.GEOSBuffer().

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

options object

Optional parameters

Properties
Name Type Attributes Default Description
dist number | string | function <optional>
0

The distance to expand the geometry (or contract if the value is negative). If the geometry is unprojected, then the unit is in kilometers. If the geometry is projected, it's in map units. You can use a numer, or a function like d => d.properties.pop/100000 or a string like "pop/100000"

each booleann <optional>
false

Compute a buffur for each features

isProjected boolean <optional>
false

Use false (default) if you are using geometries that are not projected in latitude-longitude. Use true if your base map is already projected.

quadsegs number <optional>
8

The number of segments per quadrant to generate. More segments provides a more "precise" buffer at the expense of size.

Source:
Returns:
  • A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry (it depends on what you've set as data).
Type
object | array
Example
// A global buffer
await geotoolbox.buffer(*a geojson*, {dist: 50})
// A buffer by feature
await Promise.all(*a geojson*.features.map((d) => geo.buffer(d, { dist: 50 })));
// A buffer by feature based on a field
await Promise.all(*a geojson*.features.map((d) => geo.buffer(d, { dist: d.properties["pop"] / 1000000 })))

centroid(data, options) → {object|array}

Calculates the centroids of geometries.

Based on d3.geoArea() and d3.geoCentroid()

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

options object

Optional parameters.

Properties
Name Type Attributes Default Description
larget boolean <optional>
true

If true, set the point at the centre of the largest polygon.

geo boolean <optional>
true

Use true to consider the centroid from world coordinates on the globe. If you use false, then you are considering the coordinates within the svg document.

Source:
Returns:
  • A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry (it depends on what you've set as data)
Type
object | array
Example
geotoolbox.centroid(*a geojson*, {largest: true})

(async) clip(data, options) → {object|array}

Clip a geometry with another

Based on geos.GEOSIntersection() and geos.GEOSDifference().

Parameters:
Name Type Description
data object | array

data to be clipped. A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

options object

Optional parameters

Properties
Name Type Attributes Default Description
clip object | array <optional>

Clip. A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

reverse boolean <optional>
fase

Use true to use geos.GEOSDifference() operator instead of geos.GEOSIntersection().

Source:
Returns:
  • A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry (it depends on what you've set as data).
Type
object | array
Example
await geotoolbox.clip(*a geojson*, { clip: *another geojson* })

(async) clipbyrect(data, options) → {object|array}

Intersection optimized for a rectangular clipping polygon. By default, the function cuts off anything that exceeds the Earth's bbox.

Based on geos.GEOSClipByRect().

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

options object

Optional parameters

Properties
Name Type Attributes Default Description
bbox array <optional>
[90, 180, -90, -180]

Coordinates of the bbox [top, right, bottom, left].

Source:
Returns:
  • A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry (it depends on what you've set as data).
Type
object | array
Example
await geotoolbox.clipbyrect(*a geojson*, {bbox:[50, 50, -50, -50]})

columns(data, options) → {object|array}

Select, rename and reorder properties

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection or an array of objects

options object

Optional parameters

Properties
Name Type Attributes Default Description
keys array <optional>

Properties to keep

rename array <optional>

Properties to rename

mutate boolean <optional>
false

Use true to update the input data. With false, you create a new object, but the input object remains the same.

Source:
Returns:
  • A GeoJSON FeatureCollection or an array of objects. (it depends on what you've set as data).
Type
object | array
Example
geotoolbox.columns(*a geojson or an array of objects*, {keys: ["ISO3","Population"]", rename:["id","pop"]})

combine(data, options) → {object|array}

Get the first n Features. The function sort data and returns the nb first elements. If a field is selected, then the function returns the top values. If the entries are strings, then the alphabetic order is applied.

Parameters:
Name Type Description
data object | array

An array containig several of GeoJSONs or arrays of objects

options object

Optional parameters

Properties
Name Type Attributes Default Description
fillkeys boolean <optional>
true

Use true to ensure that all features have all properties.

Source:
Returns:
  • A GeoJSON FeatureCollection or an array of objects. (it depends on what you've set as data).
Type
object | array
Example
geotoolbox.head(*a geojson or an array of objects*)

(async) concavehull(data, options) → {object|array}

Returns a "concave hull" of a geometry. A concave hull is a polygon which contains all the points of the input, but is a better approximation than the convex hull to the area occupied by the input. Frequently used to convert a multi-point into a polygonal area. that contains all the points in the input Geometry.

Based on geos.GEOSConcaveHull().

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

options object

Optional parameters.

Properties
Name Type Attributes Default Description
ratio boolean <optional>
0

The edge length ratio value, between 0 and 1.

holes boolean <optional>
true

When non-zero, the polygonal output may contain holes.

Source:
Returns:
  • A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry (it depends on what you've set as data).
Type
object | array
Example
await geotoolbox.concavehull(*a geojson*, {ratio: 0.5})

contains(g1, g2) → {boolean}

Tests if geometry g2 is completely within g1, but not wholly contained in the boundary of g1.

Based on geos.GEOSContains()

Parameters:
Name Type Description
g1 object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

g2 object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

Source:
Returns:
  • A boolean value
Type
boolean
Example
geotoolbox.contains(*a geojson*, *another geojson*)

(async) convexhull(data) → {object|array}

Returns a "convex hull" of a geometry. The smallest convex Geometry that contains all the points in the input Geometry

Based on geos.GEOSConvexHull().

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

Source:
Returns:
  • A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry (it depends on what you've set as data)
Type
object | array
Example
await geotoolbox.convexehull(*a geojson*)

copy(data) → {object|array|object|array}

Deep copy

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection or an array of objects

Source:
Returns:
    • A GeoJSON FeatureCollection or an array of objects. (it depends on what you've set as data).
    Type
    object | array
    • A GeoJSON FeatureCollection or an array of objects. (it depends on what you've set as data).
    Type
    object | array
Example
geotoolbox.copy(*a geojson or an array of objects*)

coveredby(g1, g2) → {boolean}

GEOSCoveredBy. Tests if geometry g1 is covered by g2, which is the case if every point of g1 lies in g2.

Based on geos.GEOSCoveredBy()

Parameters:
Name Type Description
g1 object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

g2 object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

Source:
Returns:
  • A boolean value
Type
boolean
Example
geotoolbox.coveredby(*a geojson*, *another geojson*)

covers(g1, g2) → {boolean}

GEOSCovers. Tests if geometry g1 covers g2, which is the case if every point of g2 lies in g1.

Based on geos.GEOSCovers()

Parameters:
Name Type Description
g1 object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

g2 object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

Source:
Returns:
  • A boolean value
Type
boolean
Example
geotoolbox.covers(*a geojson*, *another geojson*)

crosses(g1, g2) → {boolean}

GEOSCrosses. Tests if two geometries interiors intersect but their boundaries do not. Most useful for finding line crosses cases.

Based on geos.GEOSCrosses()

Parameters:
Name Type Description
g1 object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

g2 object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

Source:
Returns:
  • A boolean value
Type
boolean
Example
geotoolbox.crosses(*a geojson*, *another geojson*)

dedupe(data, options) → {object|array}

Deletes duplicates. Keeps the first element.

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection or an array of objects

options object

Optional parameters

Properties
Name Type Attributes Default Description
key number <optional>

id to consider

mutate boolean <optional>
false

Use true to update the input data. With false, you create a new object, but the input object remains the same.

Source:
Returns:
  • A GeoJSON FeatureCollection or an array of objects. (it depends on what you've set as data).
Type
object | array
Example
geotoolbox.dedupe(*a geojson or an array of objects*, {key: "ISO3"})

(async) densify(data, options) → {object|array}

Densifies a geometry using a given distance tolerance

Based on geos.GEOSDensify()

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

options object

Optional parameters

Properties
Name Type Attributes Default Description
dist number <optional>
1

The minimal distance between nodes

Source:
Returns:
  • A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry (it depends on what you've set as data).
Type
object | array
Example
await geotoolbox.densify(*a geojson*, { dist:0.5 })

derive(data, options) → {object|array}

Add a field to a dataset. The function allows to add a new property

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection or an array of objects

options object

Optional parameters

Properties
Name Type Attributes Default Description
key string <optional>
"_newkey"

Name of the property

value number | string | function <optional>

You can set a simple number or string. You can also specify a function like d=> d.properties.gdp/d.properties.pop * 1000. With the *, +, - and / operators, you can also directly write “gdp/pop*100”.

mutate boolean <optional>
false

Use true to update the input data. With false, you create a new object, but the input object remains the same.

Source:
Returns:
  • A GeoJSON FeatureCollection or an array of objects. (it depends on what you've set as data).
Type
object | array
Example
geotoolbox.derive(*a geojson or an array of objects*, {key: "gdppc", value:"gdp/pop"})

disjoint(g1, g2) → {boolean}

GEOSDisjoint. Tests if two geometries have no point in common.

Based on geos.GEOSDisjoint()

Parameters:
Name Type Description
g1 object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

g2 object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

Source:
Returns:
  • A boolean value
Type
boolean
Example
geotoolbox.disjoint(*a geojson*, *another geojson*)

dissolve(data) → {object|array}

Multi part to single part geometries. The disolve() function allows to convert "MultiPoint", "MultiLineString" or "MultiPolygon" to single "Point", "LineString" or "Polygon". In addition, a __share field is calculated, representing the surface share of each part.

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geome

Source:
Returns:
  • A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry (it depends on what you've set as data)
Type
object | array
Example
geotoolbox.dissolve(*a geojson*)

(async) envelope(data) → {object|array}

Returns a "concave hull" of a geometry. A concave hull is a polygon which contains all the points of the input, but is a better approximation than the convex hull to the area occupied by the input. Frequently used to convert a multi-point into a polygonal area. that contains all the points in the input Geometry.

Based on geos.GEOSConcaveHull().

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

Source:
Returns:
  • A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry (it depends on what you've set as data)
Type
object | array
Example
await geotoolbox.envelope(*a geojson*)

equals(g1, g2) → {boolean}

GEOSEquals. Tests if two geometries contain the same set of points in the plane.

Based on geos.GEOSEquals()

Parameters:
Name Type Description
g1 object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

g2 object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

Source:
Returns:
  • A boolean value
Type
boolean
Example
geotoolbox.equals(*a geojson*, *another geojson*)

filter(data, options) → {object|array}

Filter a dataset. The functions allows to subset a geoJSON or an array of objects

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection or an array of objects

options object

Optional parameters

Properties
Name Type Attributes Default Description
func string | function <optional>

A function to filter the datset. But you can aslo use un string like "ISO3 = FRA" ou "pop > 1000"

mutate boolean <optional>
false

Use true to update the input data. With false, you create a new object, but the input object remains the same.

Source:
Returns:
  • A GeoJSON FeatureCollection or an array of objects. (it depends on what you've set as data).
Type
object | array
Example
geotoolbox.filter(*a geojson or an array of objects*, {filter: "gdp >= 1000000" })

geolines()

Returns a GeoJSON FeatureCollection with the equator, tropics & polar circles.

Source:
Example
geotoolbox.geolines(*a geojson*)

groupby(data, options) → {object|array}

This function allows you to group objects according to an identifier. If the input dataset is a geoJSON, then the geometries are grouped using the aggregate function.

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection or an array of objects

options object

Optional parameters

Properties
Name Type Attributes Default Description
keys array <optional>

Properties to be retained after regrouping. By default, all properties are kept.

operators array <optional>

Functions to be applied to each variable. You can enter any function to be applied to an array. You can also enter operators directly: "all" (to retrieve all values), "count", "sum", "min", "max", "median", "mode", "mean", "first", "last", "variance" and "deviation".

mutate boolean <optional>
false

Use true to update the input data. With false, you create a new object, but the input object remains the same.

Source:
Returns:
  • A GeoJSON FeatureCollection or an array of objects. (it depends on what you've set as data).
Type
object | array
Example
geotoolbox.groupby(*a geojson or an array of objects*, {keys: ["pop", "gdp", "gdppc"], operators:["sum", "sum", "mean"]})

Get the first n Features. The function sort data and returns the nb first elements. If a field is selected, then the function returns the top values. If the entries are strings, then the alphabetic order is applied.

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection or an array of objects

options object

Optional parameters

Properties
Name Type Attributes Default Description
nb number <optional>
6

Number of features to return

key boolean <optional>
true

Field to sort

mutate boolean <optional>
false

Use true to update the input data. With false, you create a new object, but the input object remains the same.

Source:
Returns:
  • A GeoJSON FeatureCollection or an array of objects. (it depends on what you've set as data).
Type
object | array
Example
geotoolbox.head(*a geojson or an array of objects*)

htmltable(data, options) → {HTMLElement}

View a data table.

Parameters:
Name Type Description
data object | array

a GeoJSON FeatureCollection or an array of features

options object

Optional parameters

Properties
Name Type Attributes Description
maxrows number <optional>

Number max of lines

Source:
Returns:
  • A html sortable table.
Type
HTMLElement
Example
geottolbox.htmltable(*a geojson*)

(async) info(data)

GeoJSON information. The function gives some informations about a geoJSON (size, number of nodes, type of features, etc)

Parameters:
Name Type Description
data object

A GeoJSON FeatureCollection

Source:
Example
geottolbox.info(*a geojson*)

intersects(g1, g2) → {boolean}

GEOSIntersects. Tests if two geometries intersect.

Based on geos.GEOSIntersects()

Parameters:
Name Type Description
g1 object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

g2 object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

Source:
Returns:
  • A boolean value
Type
boolean
Example
geotoolbox.intersects(*a geojson*, *another geojson*)

(async) isvalid(data)

Check validity of a geoJSON.

Based on geos.GEOSisValid().

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

Source:
Example
await geotoolbox.isvalid(*a geojson*)

(async) iterate(data, options) → {object|array}

Iterate and apply a function

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection or an array of objects

options object

Optional parameters

Properties
Name Type Attributes Default Description
func function <optional>
d => d

A function to apply to each feature.

mutate boolean <optional>
false

Use true to update the input data. With false, you create a new object, but the input object remains the same.

Source:
Returns:
  • A GeoJSON FeatureCollection or an array of objects. (it depends on what you've set as data).
Type
object | array
Example
// A simple example. Rename and select fields.
await geo.iterate(*a geojson*, {
  func: (d) => ({
    ...d
    properties: { id: d.properties.ISO3, pop: d.properties.population },
  })
})
// Another example with a geojson and an async function
await geo.iterate(*a geojson*, {
  func: async (d) => ({
    ...d,
    geometry: await geo.buffer(d.geometry, { dist: d.properties.size })
  })

join(data, options) → {object|array}

Join datasets using a common identifier.

Parameters:
Name Type Description
data array

An array of datsats and/or geoJSONs. The join operation is basend on the first item.

options object

Options

Properties
Name Type Attributes Default Description
ids array | string <optional>

An array of code of the same size. You can use a single string if all the ids have the same code. If the ids are not filled in, then the datasets are combined without a join.

merge boolean <optional>
false

Use true to merge fields with the same name

all boolean <optional>
true

Use true to keep all elements.

emptygeom boolean <optional>
true

Use false to keep only data with geometries (if one ore more of your input data is a geoJSON).

fillkeys boolean <optional>
true

Use true to ensure that all features have all properties.

Source:
Returns:
  • A GeoJSON FeatureCollection or an array of objects. (it depends on what you've set as data).
Type
object | array
Example
geotoolbox.join([*a geojson*, *a dataset*], {ids:["ISO3", "id"], all: false)

largestemptycircle(data, options)

Constructs the "largest empty circle" (LEC) for a set of obstacle geometries and within a polygonal boundary, with accuracy to to a specified distance tolerance. The obstacles may be any collection of points, lines and polygons.

Based on geos.GEOSLargestEmptyCircle().

Parameters:
Name Type Description
data object

A GeoJSON FeatureCollection.

options object

Optional parameters.

Properties
Name Type Attributes Default Description
boundary GeoJSON <optional>
null

The area to contain the LEC center (may be null or empty)

tolerance number <optional>

Stop the algorithm when the search area is smaller than this toleranc

mutate boolean <optional>
false

Use true to update the input data. With false, you create a new object, but the input object remains the same.

Source:
Example
geotoolbox.largestemptycircle()

(async) makevalid(data) → {object|array}

The makevalid() function repair an invalid geometry. It returns a repaired geometry.

Based on geos.GEOSisValid().

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

Source:
Returns:
  • A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry (it depends on what you've set as data)
Type
object | array
Example
await geotoolbox.makevalid(*a geojson*)

nodes(data) → {object|array}

Retrieve geometry nodes

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

Source:
Returns:
  • A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry (it depends on what you've set as data).
Type
object | array
Example
geotoolbox.nodes(*a geojson*)

overlaps(g1, g2) → {boolean}

GEOSOverlaps. Tests if two geometries share interiors but are neither within nor contained.

Based on geos.GEOSOverlaps()

Parameters:
Name Type Description
g1 object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

g2 object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

Source:
Returns:
  • A boolean value
Type
boolean
Example
geotoolbox.overlaps(*a geojson*, *another geojson*)

removeemptygeom(data) → {object|array}

The function remove all features with undefined geometries.

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

Source:
Returns:
  • A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry (it depends on what you've set as data).
Type
object | array
Example
geotoolbox.removeemptygeom(*a geojson*)

replace(data, options) → {object|array}

Replace substrings. the function allows a string to be replaced by another string in the entire dataset

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection or an array of objects

options object

Optional parameters

Properties
Name Type Attributes Default Description
search string <optional>

string to search for

replacement string <optional>

substitute character string

keys array <optional>

an array of keys to limit replacement to certain fields

mutate boolean <optional>
false

Use true to update the input data. With false, you create a new object, but the input object remains the same.

Source:
Returns:
  • A GeoJSON FeatureCollection or an array of objects. (it depends on what you've set as data).
Type
object | array
Example
geotoolbox.replace(*a geojson or an array of objects*, {search: ",", replacement: " " })

resolveemptygeom(data, options) → {object|array}

The function replace all features with undefined geometries by a valid geometry, but without coordinates

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

options object

Optional parameters

Properties
Name Type Attributes Default Description
defaultype string <optional>
"Point"

type of geometry to use for undefined features if this cannot be determined

Source:
Returns:
  • A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry (it depends on what you've set as data).
Type
object | array
Example
geotoolbox.resolveemptygeom(*a geojson*)

(async) reverse(data, options) → {object|array}

For geometries with coordinate sequences, reverses the order of the sequences. Converts CCW rings to CW. Reverses direction of LineStrings.

Based on geos.GEOSReverse()

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

options object

Optional parameters

Source:
Returns:
  • A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry (it depends on what you've set as data).
Type
object | array
Example
await geotoolbox.geosreverse(*a geojson*)

rewind(data, options) → {object|array}

Rewind a geoJSON (fil recipe). The function allows to rewind the winding order of a GeoJSON object. The winding order of a polygon is the order in which the vertices are visited by the path that defines the polygon. The winding order of a polygon is significant because it determines the interior of the polygon. The winding order of a polygon is typically either clockwise or counterclockwise.

Based on https://observablehq.com/@fil/rewind

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

options object

Optional parameters

Properties
Name Type Attributes Default Description
simple number <optional>
true

Rewind simple polygons larger than a hemisphere

Source:
Returns:
  • A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry (it depends on what you've set as data)
Type
object | array
Example
geotoolbox.rewind(*a geojson*)

rewind2(data) → {object|array}

Rewind a geoJSON (Mapbox). The function allows to rewind the winding order of a GeoJSON object. The winding order of a polygon is the order in which the vertices are visited by the path that defines the polygon. The winding order of a polygon is significant because it determines the interior of the polygon. The winding order of a polygon is typically either clockwise or counterclockwise.

Adapted from MapBox geojson-rewind code (https://github.com/mapbox/grojson-rewind) under ISC license.

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

Properties:
Name Type Attributes Default Description
options.outer boolean <optional>
false

rewind Rings Outer

Source:
Returns:
  • A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry (it depends on what you've set as data)
Type
object | array
Example
geotoolbox.rewind2(*a geojson*)

roundcoordinates(data, options) → {object|array}

Round coordinates. The round() function allows to round coordinates. This reduces file size and speeds up display.

Based on geojson-precision.

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

options object

Optional parameters

Properties
Name Type Attributes Default Description
precision number <optional>
2

The minimal distance between nodes

Source:
Returns:
  • A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry (it depends on what you've set as data).
Type
object | array
Example
geotoolbox.roundcoordinates(*a geojson*, {precision: 2})

simplify(data, options) → {object|array}

Simplify geometries. The simplify() function allows to simplify a geometry using topojson-simplify library. The parameter k difine the The quantile of the simplification. By default, the generalization level is calculated automatically to ensure smooth map display.

Based on topojson.simplify.

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

options object

Optional parameters

Properties
Name Type Attributes Default Description
k number <optional>

quantile of the simplification (from 0 to 1). If not defened, the generalization level is calculated automatically to ensure smooth map display.

quantize number <optional>

A smaller quantizeAmount produces a smaller file. Typical values are between 1e4 and 1e6, although it depends on the resolution you want in the output file.

arcs number <optional>
15000

Instead of the k parameter, you can determine the level of generalization by targeting a specific number of arcs. The result will be an approximation.

Source:
Returns:
  • A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry (it depends on what you've set as data).
Type
object | array
Example
geotoolbox.simplify(*a geojson*, {k: 0.1})

sort(data, options) → {object|array}

Sorting data according to a field

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection or an array of objects

options object

Optional parameters

Properties
Name Type Attributes Default Description
key array <optional>

Field on which sorting is performed

ascending array <optional>
false

To change the sort order

mutate boolean <optional>
false

Use true to update the input data. With false, you create a new object, but the input object remains the same.

Source:
Returns:
  • A GeoJSON FeatureCollection or an array of objects. (it depends on what you've set as data).
Type
object | array
Example
geotoolbox.sort(*a geojson or an array of objects*, {key: "ISO3", ascending: true})

stitch(data) → {object|array}

The stitch() function returns a shallow copy of the specified GeoJSON object, removing antimeridian and polar cuts, and replacing straight Cartesian line segments with geodesic segments. The input object must have coordinates in longitude and latitude in decimal degrees per RFC 7946. Antimeridian cutting, if needed, can then be re-applied after rotating to the desired projection aspect.

Based on d3.geoStitch().

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

Source:
Returns:
  • A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry (it depends on what you've set as data)
Type
object | array
Example
geotoolbox.stitch(*a geojson*)

table(data, options) → {array}

Retrieves the dataset's attribute table (properties). By default, a deep copy is returned.

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection or an array of objects

options object

Optional parameters

Properties
Name Type Attributes Default Description
mutate boolean <optional>
false

Use true to update the input data. With false, you create a new object, but the input object remains the same.

Source:
Returns:
  • An array of objects.
Type
array
Example
geotoolbox.table(*a geojson or an array of objects*)

tail(data, options) → {object|array}

Get the last n Features. The function sort data and returns the nb first elements. If a field is selected, then the function returns the top values. If the entries are strings, then the alphabetic order is applied.

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection or an array of objects

options object

Optional parameters

Properties
Name Type Attributes Default Description
nb number <optional>
6

Number of features to return

key boolean <optional>
true

Field to sort

mutate boolean <optional>
false

Use true to update the input data. With false, you create a new object, but the input object remains the same.

Source:
Returns:
  • A GeoJSON FeatureCollection or an array of objects. (it depends on what you've set as data).
Type
object | array
Example
geotoolbox.tail(*a geojson or an array of objects*)

tissot(stepopt)

Generate Tissot's indicatrix.

Parameters:
Name Type Attributes Default Description
step number <optional>
20

The distance between each circle

Source:
Example
geotoolbox.tissot(*a geojson*)

togeojson(data, options)

Retrieve a FeatureCollection. The featurecollection() function allows to retrieve a FeatureCollection from a

  • a topoJSON ✅
  • an array of features ✅
  • a single feature ✅
  • an array of geometries ✅
  • a single geometry ✅
  • an array of objects with coordinates (points) ✅
  • an array coordinates (points) ✅
  • a couple of coordinates (points) ✅

Parameters:
Name Type Description
data object

A GeoJSON FeatureCollection

options object

Optional parameters

Properties
Name Type Attributes Default Description
lat string <optional>

Field containing latitude coordinates. lat, Lat, LAT, Latitude, latitude are set by default.

latitude string <optional>

Field containing latitude coordinates. lat, Lat, LAT, Latitude, latitude are set by default.

lon string <optional>

Field containing longitude coordinates. lon, Lon, LON, lng, Lng, LNG, Longitude, longitude are set by default.

longitude string <optional>

Field containing longitude coordinates. lon, Lon, LON, lng, Lng, LNG, Longitude, longitude are set by default.

coords string <optional>

If the coordinates are in a single column, this also works. The fields coords, coord, Coords, Coordinates, coordinates, Coordinate, coordinate are set by default but, as previsously, you can specify in option with coordinates or coords.

coordinates string <optional>

If the coordinates are in a single column, this also works. The fields coords, coord, Coords, Coordinates, coordinates, Coordinate, coordinate are set by default but, as previsously, you can specify in option with coordinates or coords.

reperse boolean <optional>
false

If the latitude and longitude coordinates are inverted, you can use the reverse = true.

properties Array <optional>

With the properties option, you can choose which fields you'd like to keep.

rename Array <optional>

With the rename option, you can even rename them.

filter function <optional>

with filter, you can filter data.

mutate boolean <optional>
false

Use true to update the input data. With false, you create a new object, but the input object remains the same.

Source:
Example
// Array of coordinates
geoclean.togeojson([
  [32.33, 45.66],
  [10, 10]
])

// A geometry  
geoclean.togeojson({
  type: "Polygon",
  coordinates: [
    [
      [100.0, 0.0],
      [101.0, 0.0],
      [101.0, 1.0],
      [100.0, 1.0],
      [100.0, 0.0]
    ]
  ]
})

// An array of objects containing coordinates
geoclean.togeojson(*a JSON*, {lat: "lat", lon: "lon"})

// Data handling
geoclean.togeojson(*a geoJSON*, {
      filter: (d) => d.properties.pop2018 >= 200,
      properties: ["id", "capital", "pop2018"],
      rename: ["code", "name", "pop"
  })  
 

touches(g1, g2) → {boolean}

GEOSTouches. Tests if two geometries share boundaries at one or more points, but do not have interior points in common.

Based on geos.GEOSTouches()

Parameters:
Name Type Description
g1 object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

g2 object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

Source:
Returns:
  • A boolean value
Type
boolean
Example
geotoolbox.touches(*a geojson*, *another geojson*)

type(x) → {object}

Return the geometry type contained in a GeoJSON FeatureCollection

.

Return the geometry type contained in a GeoJSON FeatureCollection

Parameters:
Name Type Description
x object

The GeoJSON FeatureCollection

Source:
Returns:
  • The number of dimensions of the geometries (1 for punctual, 2 for lineal, 3 for zonal and -1 for composite) and the types of the geometries ("Point", "LineString", "Polygon", "MultiPoint", "MultiLineString", "MultiPolygon")
Type
object

(async) union(data, options) → {object|array}

Merge geometries

Based on geos.GEOSUnaryUnion().

Parameters:
Name Type Description
data object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

options object

Optional parameters

Properties
Name Type Attributes Description
id number <optional>

An id to merge by id

Source:
Returns:
  • A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry (it depends on what you've set as data).
Type
object | array
Example
await geotoolbox.union(*a geojson*)

within(g1, g2) → {boolean}

GEOSWithin. Tests if geometry g1 is completely within g2, but not wholly contained in the boundary of g2.

Based on geos.GEOSWithin()

Parameters:
Name Type Description
g1 object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

g2 object | array

A GeoJSON FeatureCollection, an array of features, an array of geometries, a single feature or a single geometry.

Source:
Returns:
  • A boolean value
Type
boolean
Example
geotoolbox.within(*a geojson*, *another geojson*)