A set of matchers related to validating coordinates and coordinate
properties.
Methods
(static) isValid2DCoordinate(coordinateArray)
- Source:
- See:
Verifies a two element coordinate meets WGS-84 and GeoJSON validity
requirements.
Examples
test('Object is valid GeoJSON', () => {
expect([22, 45.733]).isValid2DCoordinate()
expect([180, 90]).isValid2DCoordinate()
})
test('Object is NOT valid GeoJSON', () => {
expect([22, 100.56]).not.isValid2DCoordinate() // Latitude out of range
expect([22, 45.733, 0]).not.isValid2DCoordinate() //3D coordinate
// Nested Arrays
expect([[22, 45.733, 0]]).not.isValid2DCoordinate()
expect([[22, 45.733], [180, 90]]).not.isValid2DCoordinate()
})
Parameters:
Name | Type | Description |
---|---|---|
coordinateArray |
Array.<number> | A two element array of numbers in format [longitude, latitude]. Longitude must be between -180 to 180. Latitude must be between -90 to 90. |
(static) isValid3DCoordinate(coordinateArray)
- Source:
- See:
Verifies a three element coordinate meets WGS-84 and GeoJSON validity
requirements.
Examples
test('Object is valid GeoJSON', () => {
expect([22, 45.733, 20]).isValid3DCoordinate()
expect([180, 90, -10000]).isValid3DCoordinate()
})
test('Object is NOT valid GeoJSON', () => {
expect([22, 100.56, 0]).not.isValid3DCoordinate() // Latitude out of range
expect([22, 45.733]).isValid3DCoordinate() // 2D coordinate
expect([22, 45.733, '0']).not.isValid3DCoordinate() // Non-numeric altitude
// Nested Arrays
expect([[22, 45.733, 0]]).not.isValid3DCoordinate()
expect([[22, 45.733, 0], [180, 90, 0]]).not.isValid3DCoordinate()
})
Parameters:
Name | Type | Description |
---|---|---|
coordinateArray |
Array.<number> | A three element array of numbers in format [longitude, latitude, altitude]. Longitude must be between -180 to 180. Latitude must be between -90 to 90. Altitude must be a number between -Infinity to Infinity. The standard does not specify units altitude represents (i.e. meters, feet, etc.). |
(static) isValidCoordinate(coordinateArray)
- Source:
- See:
Verifies a two or three element coordinate meets WGS-84 and GeoJSON validity
requirements.
Examples
test('Object is valid GeoJSON', () => {
expect([22, 45.733]).isValidCoordinate()
expect([180, 90]).isValidCoordinate()
expect([22, 45.733, 20]).isValidCoordinate()
expect([180, 90, -10000]).isValidCoordinate()
})
test('Object is NOT valid GeoJSON', () => {
expect([220, 56]).not.isValidCoordinate() // Longitude out of range
expect([22, 45.733, '0']).not.isValidCoordinate()
// Nested Arrays
expect([[22, 45.733, 0]]).not.isValidCoordinate()
expect([[22, 45.733, 0], [180, 90, 0]]).not.isValidCoordinate()
})
Parameters:
Name | Type | Description |
---|---|---|
coordinateArray |
Array.<number> | A two or three element array of numbers in format [longitude, latitude] or [longitude, latitude, altitude]. Longitude must be between -180 to 180. Latitude must be between -90 to 90. Altitude must be a number between -Infinity to Infinity. The standard does not specify units altitude represents (i.e. meters, feet, etc.). |