Class: Geohashes

Geohashes()

A collection of adjacent geohashes, potentially at mixed precision levels.

Constructor

new Geohashes()

Since:
  • 2.25.0
Source:

Extends

  • Backbone.Collection

Members

model :Geohash

The model class for this collection
Type:
Source:

type :string

The name of this type of collection
Type:
  • string
Source:

Methods

addGeohashesByBounds(bounds, consolidateopt, maxGeohashesopt, overwriteopt, minPrecisionopt, maxPrecisionopt)

Add geohashes to the collection based on a bounding box.
Parameters:
Name Type Attributes Default Description
bounds GeoBoundingBox Bounding box with north, south, east, and west properties.
consolidate boolean <optional>
false Whether to consolidate the geohashes into the smallest set of geohashes that cover the same area. This will be performed before creating the new models in order to improve performance.
maxGeohashes number <optional>
Infinity The maximum number of geohashes to add to the collection. This will limit the precision of the geohashes for larger bounding boxes. Depending on constraints such as the min and max precision, and the size of the bounding box, the actual number of geohashes added may sometimes exceed this number.
overwrite boolean <optional>
false Whether to overwrite the current collection.
minPrecision number <optional>
The minimum precision of the geohashes to add to the collection, defaults to the min precision level set on the collection.
maxPrecision number <optional>
The maximum precision of the geohashes to add to the collection, defaults to the max precision level set on the collection.
Source:

addGeohashesByHashString(hashStrings, overwriteopt)

Add geohashes to the collection based on an array of geohash hashStrings.
Parameters:
Name Type Attributes Default Description
hashStrings Array.<string> Array of geohash hashStrings.
overwrite boolean <optional>
false Whether to overwrite the current collection.
Source:

comparator(model) → {number}

Add a comparator to sort the geohashes by length.
Parameters:
Name Type Description
model Geohash Geohash model to compare.
Source:
Returns:
Length of the geohash.
Type
number

consolidate()

Consolidate this collection: Merge complete groups of geohashes into a single, lower precision "parent" geohash. Groups are complete if all 32 "child" geohashes that make up the "parent" geohash are in the collection. Add and remove events will not be triggered during consolidation.
Source:

coversEarth() → {boolean}

Returns true if the geohashes in this model cover the entire earth.
Source:
Returns:
True if the geohashes cover the entire earth.
Type
boolean

getAllHashStrings(precision) → {Array.<string>}

Returns a list of hashStrings in this collection. Optionally provide a precision to only return hashes of that length.
Parameters:
Name Type Description
precision Number Geohash precision level.
Source:
Returns:
Array of geohash hashStrings.
Type
Array.<string>

getAttr(attr)

Get an array of all the values for a given property in the geohash models in this collection.
Parameters:
Name Type Description
attr string The key of the property in the properties object in each geohash model.
Source:

getCompleteGroups() → {Object}

Get the geohash groups in this collection that are complete, i.e. have 32 child geohashes.
Source:
Returns:
Object with groupIDs as keys and arrays of Geohash models as values.
Type
Object

getContainingGeohash(hashString) → {Geohash}

Find the geohash from this collection that contains the provided geohash hashString. If the hashString is already in the collection, return that geohash. Otherwise, find the geohash that contains the hashString.
Parameters:
Name Type Description
hashString string Geohash hashString.
Source:
Returns:
Parent geohash.
Type
Geohash

getFewestHashStringsForBounds(bounds, minPrecisionopt, maxPrecisionopt, maxGeohashesopt) → {Array.<string>}

Get the fewest number of geohashes that can be used to cover a given bounding box. This will return the optimal set of potentially mixed-precision geohashes that cover the bounding box at the highest precision possible without exceeding the maximum number of geohashes.
Parameters:
Name Type Attributes Default Description
bounds GeoBoundingBox Bounding box with north, south, east, and west properties.
minPrecision Number <optional>
The minimum precision level to consider when calculating the optimal set of geohashes. Defaults to the min precision level set on the collection.
maxPrecision Number <optional>
The maximum precision level to consider when calculating the optimal set of geohashes. Defaults to the max precision level set on the collection.
maxGeohashes Number <optional>
Infinity The maximum number of geohashes to add to the collection. This will limit the precision of the geohashes for larger bounding boxes. Depending on constraints such as the min and max precision, and the size of the bounding box, the actual number of geohashes added may sometimes exceed this number.
Source:
Returns:
Array of geohash hashStrings.
Type
Array.<string>

getGeohashArea(precision) → {number}

Get the area in degrees squared of a geohash "tile" for a given precision level. The area is considered the product of the geohash's latitude and longitude error margins.
Parameters:
Name Type Description
precision number The precision level to get the area for.
Source:
Returns:
The area in degrees squared.
Type
number

getGeohashAreas(minPrecision, maxPrecision) → {Object}

For a range of precisions levels, get the area in degrees squared for geohash "tiles" at each precision level. See getGeohashArea.
Parameters:
Name Type Description
minPrecision Number The minimum precision level for which to calculate the area, defaults to the min precision level set on the collection.
maxPrecision Number The maximum precision level for which to calculate the area, defaults to the max precision level set on the collection.
Source:
Returns:
An object with the precision level as the key and the area in degrees as the value.
Type
Object

getGroups(levelopt) → {Object}

Group the geohashes in the collection by their groupID. Their groupID is the hashString of the parent geohash, i.e. the hashString of the geohash with the last character removed.
Parameters:
Name Type Attributes Default Description
level number <optional>
1 The level of the parent geohash to use to group the geohashes. Defaults to 1, i.e. the parent geohash is one level up.
Source:
Returns:
Object with groupIDs as keys and arrays of Geohash models as values.
Type
Object

getHashStringsForBounds(bounds, precision) → {Array.<string>}

Creates hashStrings for geohashes that are within the provided bounding boxes at the given precision. The returned hashStrings are not necessarily in the collection.
Parameters:
Name Type Description
bounds GeoBoundingBox Bounding box with north, south, east, and west properties.
precision number Geohash precision level.
Source:
Returns:
Array of geohash hashStrings.
Type
Array.<string>

getMaxPrecision(area, maxGeohashes, absMinopt, absMaxopt) → {Number}

Given a bounding box, estimate the maximum geohash precision that can be used to cover the area without exceeding a specified number of geohashes. The goal is to find the smallest and most precise geohashes possible without surpassing the maximum allowed number of geohashes.
Parameters:
Name Type Attributes Description
area Number The area of the bounding box in degrees squared.
maxGeohashes Number The maximum number of geohashes that can be used to cover the area.
absMin Number <optional>
The absolute minimum precision level to consider. Defaults to the min set on the collection).
absMax Number <optional>
The absolute maximum precision level to consider. Defaults to the max set on the collection.
Source:
Returns:
The maximum precision level that can be used to cover the area without surpassing the given number of geohashes.
Type
Number

getMinPrecision(area, absMin, absMax) → {Number}

Calculate the smallest possible geohash precision level that has geohash "tiles" larger than a given area.
Parameters:
Name Type Description
area Number The area of the bounding box in degrees squared.
absMin Number The absolute minimum precision level to consider. Defaults to the min set on the collection.
absMax Number The absolute maximum precision level to consider. Defaults to the max set on the collection.
Source:
Returns:
The minimum precision level that can be used to cover the area with a single geohash.
Type
Number

getOptimalPrecisionRange(bounds, maxGeohashes, absMin, absMax) → {Array}

Get the optimal range of precision levels to consider using for a given bounding box. See getMaxPrecision and getMinPrecision.
Parameters:
Name Type Description
bounds GeoBoundingBox Bounding box with north, south, east, and west properties.
maxGeohashes Number The maximum number of geohashes that can be used to cover the area.
absMin Number The absolute minimum precision level to consider. Defaults to the min set on the collection.
absMax Number The absolute maximum precision level to consider. Defaults to the max set on the collection.
Source:
Returns:
An array with the min and max precision levels to consider.
Type
Array

getPrecisions()

Get the unique geohash precision levels present in the collection.
Source:

getSubsetByBounds(bounds) → {Geohashes}

Get a subset of geohashes from this collection that are within the provided bounding box.
Parameters:
Name Type Description
bounds GeoBoundingBox Bounding box with north, south, east, and west properties.
Source:
Returns:
Subset of geohashes.
Type
Geohashes

includes(target) → {boolean}

Check if a geohash is in the collection. This will only consider geohash hashStrings, not properties or any other attributes on the Geohash models.
Parameters:
Name Type Description
target Geohash Geohash model or geohash hashString.
Source:
Returns:
Whether the target is part of this collection.
Type
boolean

initialize(models, options)

Initialize the collection and set the min and max precision levels.
Parameters:
Name Type Description
models Array.<Geohash> Array of Geohash models.
options Object Options to pass to the collection.
Properties
Name Type Attributes Default Description
maxPrecision number <optional>
9 The maximum precision level to use when adding geohashes to the collection.
minPrecision number <optional>
1 The minimum precision level to use when adding geohashes to the collection.
Source:

isCompleteRootLevel() → {boolean}

Returns true if the set of geohashes in this model collection are the 32 geohashes at precision 1, i.e. [0-9a-v]
Source:
Returns:
True if there are 32 geohashes with one character each.
Type
boolean

isEmpty() → {boolean}

Checks if the geohashes in this model are empty or if there are no models
Source:
Returns:
True if this collection is empty.
Type
boolean

toCZML(labelopt) → {Array}

Return the geohashes as a CZML document, where each geohash is represented as a CZML Polygon (rectangle) and a CZML Label.
Parameters:
Name Type Attributes Description
label string <optional>
The key for the property that should be displayed with a label for each geohash, e.g. "count"
Source:
Returns:
CZML document.
Type
Array

toGeoJSON() → {Object}

Return the geohashes as a GeoJSON FeatureCollection, where each geohash is represented as a GeoJSON Polygon (rectangle).
Source:
Returns:
GeoJSON FeatureCollection.
Type
Object

toGeoJSONPoints() → {Object}

Return the geohashes as a GeoJSON FeatureCollection, where each geohash is represented as a GeoJSON Point.
Source:
Returns:
GeoJSON FeatureCollection.
Type
Object

validatePrecision(precision, fixopt) → {number|Array.<number>}

Ensure that a precision or list of precisions is valid. A valid precision is a positive number in the range of the MIN_PRECISION and MAX_PRECISION set on the collection.
Parameters:
Name Type Attributes Default Description
precision number | Array.<number> Precision level or array of precision levels.
fix boolean <optional>
true Whether to fix the precision by setting it to the min or max precision if it is out of range. If false, then the function will throw an error if the precision is invalid.
Source:
Returns:
The precision level or array of precision levels, corrected if needed and if fix is true.
Type
number | Array.<number>