A set of matchers related to validating the seven geometry objects.
Methods
(static) toBeAnyGeometry(geometryObject)
- Source:
- See:
Verifies an object meets validity requirements for one of the six basic
GeoJSON geometry types: Point, MultiPoint, LineString, MultiLineString,
Polygon, MultiPolygon, GeometryCollection.
Examples
point = {
"type": "Point",
"coordinates": [100.0, 0.0]
}
lineString = {
"type": "LineString",
"coordinates": [
[
[180.0, 40.0],
[180.0, 50.0],
[170.0, 50.0],
[170.0, 40.0],
[180.0, 40.0]
]
]
}
polygon = {
"type": "Polygon",
"coordinates": [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
]
]
}
test('Object is valid GeoJSON Geometry Object', () => {
expect(point).toBeAnyGeometry()
expect(lineString).toBeAnyGeometry()
expect(polygon).toBeAnyGeometry()
})
feature = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [102.0, 0.5]
}
}
test('Object is NOT valid GeoJSON Geometry Object', () => {
expect(feature).not.toBeAnyGeometry()
expect([322, -34.549, 0]).not.toBeAnyGeometry()
expect({coordinates: [22, -34.549, 22]}).not.toBeAnyGeometry()
})
Parameters:
Name | Type | Description |
---|---|---|
geometryObject |
object | any GeoJSON Geometry object |
(static) toBeGeometryCollection(geometryObject)
- Source:
- See:
Verifies an object is a valid GeoJSON GeometryCollection. This object
requires a 'type' property that must equal "GeometryCollection", and a
'geometries' property that contains an array of GeoJSON Geometry objects
(Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon). The
geometries may be an empty array, but may not be an array of empty arrays or
objects. Foreign members are allowed with the exception of 'geometry',
'properties', or 'features'. If present, bounding boxes must be valid.
Examples
const collection = {
type: 'GeometryCollection',
geometries: [{
"type": 'Point',
"coordinates": [100.0, 0.0]
}, {
type: 'LineString',
coordinates: [
[101.0, 0.0],
[102.0, 1.0]
]
}, {
type: 'Polygon',
coordinates: [
[
[102.0, 2.0],
[103.0, 2.0],
[103.0, 3.0],
[102.0, 3.0],
[102.0, 2.0]
]
]
}, {
type: 'Point',
coordinates: [150.0, 73.0]
}]
}
test('Object is valid GeoJSON GeometryCollection Object', () => {
expect(collection).toBeGeometryCollection()
})
const lineString = {
type: 'LineString',
coordinates: [
[101.0, 0.0],
[102.0, 1.0]
]
}
test('Object is NOT valid GeoJSON GeometryCollection Object', () => {
expect(collection.geometries).not.toBeGeometryCollection()
expect(lineString).not.toBeGeometryCollection()
})
Parameters:
Name | Type | Description |
---|---|---|
geometryObject |
object | any GeoJSON Geometry object |
(static) toBeLineStringGeometry(geometryObject)
- Source:
- See:
Verifies an object is a valid GeoJSON LineString Geometry. This geometry
requires a 'type' property that must equal "LineString", and a 'coordinates'
property that contains an array of two or more valid WGS-84 GeoJSON
coordinate(s). The coordinates may be an empty array, but may not be an
array of empty arrays. Foreign members are allowed with the exception of
'geometry', 'properties', or 'features'. If present, bounding boxes must be
valid.
Examples
const linestring = {
"type": "LineString",
"coordinates": [
[
[180.0, 40.0], [180.0, 50.0], [170.0, 50.0],
[170.0, 40.0], [180.0, 40.0]
]
]
}
test('Object is valid GeoJSON LineString Object', () => {
expect(linestring).toBeLineStringGeometry()
})
const point = {
type: "Point",
coordinates: [100.0, 0.0]
}
test('Object is NOT valid GeoJSON LineString Object', () => {
expect(point).not.toBeLineStringGeometry()
})
Parameters:
Name | Type | Description |
---|---|---|
geometryObject |
object | a GeoJSON LineString Geometry object |
(static) toBeMultiLineStringGeometry(geometryObject)
- Source:
- See:
Verifies an object is a valid GeoJSON MultiLineString Geometry. This
geometry requires a 'type' property that must equal "MultiLineString", and a
'coordinates' property that contains an array of linestring arrays (i.e.
each linestring array containing at least two or more valid WGS-84 GeoJSON
coordinates). The coordinates may be an empty array, but may not be an array
of empty arrays. Foreign members are allowed with the exception of
'geometry', 'properties', or 'features'. If present, bounding boxes must be
valid.
Examples
const multiLineString = {
"type": "MultiLineString",
"coordinates": [
[
[100.0, 0.0],
[101.0, 1.0]
],
[
[102.0, 2.0],
[103.0, 3.0]
]
]
}
test('Object is valid GeoJSON MultiLineString Object', () => {
expect(multiLineString).toBeMultiLineStringGeometry()
})
const point = {
type: "Point",
coordinates: [100.0, 0.0]
}
const multiLineStringOneCoordinate = {
"type": "MultiLineString",
"coordinates": [
[
[100.0, 0.0]
]
]
}
test('Object is NOT valid GeoJSON MultiLineString Object', () => {
expect(point).not.toBeMultiLineStringGeometry()
expect(multiLineStringOneCoordinate).not.toBeMultiLineStringGeometry()
})
Parameters:
Name | Type | Description |
---|---|---|
geometryObject |
object | a GeoJSON MultiLineString Geometry object |
(static) toBeMultiPointGeometry(geometryObject)
- Source:
- See:
Verifies an object is a valid GeoJSON MultiPoint Geometry. This geometry
requires a 'type' property that must equal "MultiPoint", and a 'coordinates'
property that contains an array of valid WGS-84 GeoJSON coordinate(s). The
coordinates may be an empty array. Foreign members are allowed with the
exception of 'geometry', 'properties', or 'features'. If present, bounding
boxes must be valid.
Examples
const multiPoint1 = {
type: "MultiPoint",
coordinates: [
[25, 90],
[-180, 0]
]
}
const multiPoint2 = {
type: "MultiPoint",
coordinates: [[100.0, 0.0, 2000]]
}
test('Object is valid GeoJSON MultiPoint Geometry', () => {
expect(multiPoint1).toBeMultiPointGeometry()
expect(multiPoint2).toBeMultiPointGeometry()
})
const lineString = {
type: "LineString",
coordinates: [
[101.0, 0.0],
[102.0, 1.0]
]
}
test('Object is NOT valid GeoJSON MultiPoint Geometry', () => {
expect(lineString).not.toBeMultiPointGeometry()
expect([[22, -34.549, 22]]).not.toBeMultiPointGeometry()
expect({coordinates: [[100.0, 0.0]]}).not.toBeMultiPointGeometry()
})
Parameters:
Name | Type | Description |
---|---|---|
geometryObject |
object | a GeoJSON MultiPoint Geometry object |
(static) toBeMultiPolygonGeometry(geometryObject)
- Source:
- See:
Verifies an object is a valid GeoJSON MultiPolygon Geometry. This geometry
requires a 'type' property that must equal "MultiPolygon", and a
'coordinates' property that contains an array of polygon coordinate arrays.
Each coordinate array must contain at least four valid WGS-84 GeoJSON
coordinates, and the final coordinate must equal the first. The coordinates
may be an empty array, but may not be an array of empty arrays. Foreign
members are allowed with the exception of 'geometry', 'properties', or
'features'. If present, bounding boxes must be valid.
Examples
const multiPolygon = {
"type": "MultiPolygon",
"coordinates": [
[
[
[102.0, 2.0],
[103.0, 2.0],
[103.0, 3.0],
[102.0, 3.0],
[102.0, 2.0]
]
],
[
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
],
[
[100.2, 0.2],
[100.2, 0.8],
[100.8, 0.8],
[100.8, 0.2],
[100.2, 0.2]
]
]
]
}
const multiPolygonWithSingleElement = {
"type": "MultiPolygon",
"coordinates": [
[
[
[102.0, 2.0],
[103.0, 2.0],
[103.0, 3.0],
[102.0, 3.0],
[102.0, 2.0]
]
]
]
}
test('Object is valid GeoJSON MultiPolygon Geometry', () => {
expect(multiPolygon).toBeMultiPolygonGeometry()
expect(multiPolygonWithSingleElement).toBeMultiPolygonGeometry()
})
const point = {
type: "Point",
coordinates: [100.0, 0.0]
}
test('Object is NOT valid GeoJSON MultiPolygon Geometry', () => {
expect(point).not.toBeMultiPolygonGeometry()
})
Parameters:
Name | Type | Description |
---|---|---|
geometryObject |
object | a GeoJSON Polygon Geometry object |
(static) toBeMultiPolygonWithHole(geometryObject)
- Source:
- See:
Verifies an object is a valid GeoJSON MultiPolygon Geometry with at least
one polygon having a hole.
Examples
const multiPolygon1 = {
type: 'MultiPolygon',
coordinates: [
[
[
[102.0, 2.0],
[103.0, 2.0],
[103.0, 3.0],
[102.0, 3.0],
[102.0, 2.0]
]
],
[
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
],
[
[100.2, 0.2],
[100.2, 0.8],
[100.8, 0.8],
[100.8, 0.2],
[100.2, 0.2]
]
]
]
}
test('Object is valid MultiPolygon With Hole', () => {
expect(multiPolygon1).toBeMultiPolygonWithHole()
})
const multiPolygon2 = {
type: 'MultiPolygon',
coordinates: [
[
[
[102.0, 2.0],
[103.0, 2.0],
[103.0, 3.0],
[102.0, 3.0],
[102.0, 2.0]
]
]
]
}
const polygon = {
type: 'Polygon',
coordinates: [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
],
[
[100.2, 0.2],
[100.2, 0.8],
[100.8, 0.8],
[100.8, 0.2],
[100.2, 0.2]
]
]
}
test('Not a MultiPolygon, or does not have a hole', () => {
expect(multiPolygon2).not.toBeMultiPolygonWithHole()
expect(multiPolygon1.coordinates[2][1]).not.toBeMultiPolygonWithHole()
expect(polygon).not.toBeMultiPolygonWithHole()
})
Parameters:
Name | Type | Description |
---|---|---|
geometryObject |
object | a GeoJSON Polygon Geometry object |
(static) toBePointGeometry(geometryObject)
- Source:
- See:
Verifies an object is a valid GeoJSON Point Geometry. This geometry requires
a 'type' property that must equal "Point", and a 'coordinates' property that
contains a single valid WGS-84 GeoJSON coordinate. The coordinates may be an
empty array. Foreign members are allowed with the exception of 'geometry',
'properties', or 'features'. If present, bounding boxes must be valid.
Examples
const testPoint = {
type: 'Point',
coordinates: [25, 10.2]
}
test('Object is valid GeoJSON Point Geometry', () => {
expect(testPoint).toBePointGeometry()
})
const multiPoint = {
type: 'MultiPoint',
coordinates: [
[25, 10.2],
[120, 45]
]
}
test('Object is NOT valid GeoJSON Point Geometry', () => {
expect(multiPoint).not.toBePointGeometry()
})
Parameters:
Name | Type | Description |
---|---|---|
geometryObject |
object | a GeoJSON Point Geometry object |
(static) toBePolygonGeometry(geometryObject)
- Source:
- See:
Verifies an object is a valid GeoJSON Polygon Geometry. This geometry
requires a 'type' property that must equal "Polygon", and a 'coordinates'
property that contains an array of linestring arrays. Each point array must
contain at least four valid WGS-84 GeoJSON coordinates, and the final
coordinate must equal the first. The coordinates may be an empty array, but
may not be an array of empty arrays. Foreign members are allowed with the
exception of 'geometry', 'properties', or 'features'. If present, bounding
boxes must be valid.
Examples
const polygon = {
"type": "Polygon",
"coordinates": [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
]
]
}
test('Object is valid GeoJSON', () => {
expect(polygon).toBePolygonGeometry()
})
const point = {
type: "Point",
coordinates: [100.0, 0.0]
}
const polygonEndDoesNotEqualStart = {
"type": "Polygon",
"coordinates": [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0]
]
]
}
test('Object is valid GeoJSON', () => {
expect(point).not.toBePolygonGeometry()
expect(polygonEndDoesNotEqualStart).not.toBePolygonGeometry()
})
Parameters:
Name | Type | Description |
---|---|---|
geometryObject |
object | a GeoJSON Polygon Geometry object |
(static) toBePolygonWithHole(geometryObject)
- Source:
- See:
Verifies an object is a valid GeoJSON Polygon Geometry with a hole.
Examples
const polygon1 = {
"type": "Polygon",
"coordinates": [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
],
[
[100.8, 0.8],
[100.8, 0.2],
[100.2, 0.2],
[100.2, 0.8],
[100.8, 0.8]
]
]
}
test('Object is valid Polygon With Hole', () => {
expect(polygon1).toBePolygonWithHole()
})
const polygon2 = {
type: 'Polygon',
coordinates: [
[
[120.0, 0.0],
[121.0, 0.0],
[121.0, 1.0],
[120.0, 1.0],
[120.0, 0.0]
]
]
}
const point = {
type: 'Polygon',
coordinates: [
[
[120.0, 0.0],
[121.0, 0.0],
[121.0, 1.0],
[120.0, 1.0],
[120.0, 0.0]
]
]
}
test('Not a Polygon, or does not have a hole', () => {
expect(polygon2).not.toBePolygonWithHole()
expect(polygon1.coordinates[1]).not.toBePolygonWithHole()
expect(point).not.toBePolygonWithHole()
})
Parameters:
Name | Type | Description |
---|---|---|
geometryObject |
object | a GeoJSON Polygon Geometry object |
(static) toHaveGeometryCount(geometryObject, Range1opt, Range2opt)
- Source:
- See:
Verifies a valid GeoJSON GeometryCollection has a specific number of
geometries. If omitting both `Range1` and `Range2`, it passes if at least
one geometry object is contained in "geometries". If only Range1 is
specified, it checks that there are exactly that number of geometries. If
Range1 and Range2 are specified, it checks that the geometry count is
between those values. Decimals get truncated on both Range1 and Range2. Will
fail if Range1 or Range2 are not numbers or less than 0, Range2 less than
Range1, or Range2 is defined and Range1 is not. Nested GeometryCollections
are only counted as a single geometry object.
Examples
const testCollection = {
"type": "GeometryCollection",
"geometries": [{
"type": "Point",
"coordinates": [100.0, 0.0]
}, {
"type": "LineString",
"coordinates": [
[101.0, 0.0],
[102.0, 1.0]
]
}, {
"type": "Polygon",
"coordinates": [
[
[102.0, 2.0],
[103.0, 2.0],
[103.0, 3.0],
[102.0, 3.0],
[102.0, 2.0]
]
]
}, {
"type": "Point",
"coordinates": [150.0, 73.0]
}]
}
test('GeometryCollection has specified geometry count', () => {
expect(testCollection).toHaveGeometryCount(1, 8)
expect(testCollection).toHaveGeometryCount(4)
expect(testCollection).toHaveGeometryCount()
})
const emptyCollection = {
"type": "GeometryCollection",
"geometries": []
}
const polygon = {
type: 'Polygon',
coordinates: [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
]
]
}
test('Object is not a GeometryCollection or does not have specified geometry count', () => {
expect(testCollection).not.toHaveGeometryCount(5, 15)
expect(testCollection).not.toHaveGeometryCount(2, 3.99)
expect(emptyCollection).not.toHaveGeometryCount()
expect(polygon).not.toHaveGeometryCount(1)
})
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
geometryObject |
object | A GeoJSON GeometryCollection object | |
Range1 |
number | <optional> |
Minimum geometry object count, or exact count if omitting Range2 |
Range2 |
number | <optional> |
Maximum geometry object count |
(static) toHaveMaxGeometryCount(geometryObject, MaxCountopt)
- Source:
- See:
Verifies a valid GeoJSON GeometryCollection has less than or equal to a
specified number of geometries. If omitting MaxCount, it passes if
"geometries" contains no more than one object. Will fail if MaxCount is not
a number or less than zero. Nested GeometryCollections are only counted as a
single geometry object.
Examples
const testCollection = {
"type": "GeometryCollection",
"geometries": [{
"type": "Point",
"coordinates": [100.0, 0.0]
}, {
"type": "LineString",
"coordinates": [
[101.0, 0.0],
[102.0, 1.0]
]
}, {
"type": "Polygon",
"coordinates": [
[
[102.0, 2.0],
[103.0, 2.0],
[103.0, 3.0],
[102.0, 3.0],
[102.0, 2.0]
]
]
}, {
"type": "Point",
"coordinates": [150.0, 73.0]
}]
}
const emptyCollection = {
"type": "GeometryCollection",
"geometries": []
}
test('GeometryCollection has maximum geometry count', () => {
expect(testCollection).toHaveMaxGeometryCount(4)
expect(testCollection).toHaveMaxGeometryCount(22)
expect(emptyCollection).toHaveMaxGeometryCount()
expect(emptyCollection).toHaveMaxGeometryCount(0)
})
const polygon = {
type: 'Polygon',
coordinates: [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
]
]
}
test('Object is not a GeometryCollection or does not have maximum geometry count', () => {
expect(testCollection).not.toHaveMaxGeometryCount(2)
expect(testCollection).not.toHaveMaxGeometryCount(3.99)
expect(polygon).not.toHaveMaxGeometryCount(1)
})
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
geometryObject |
object | A GeoJSON GeometryCollection object | |
MaxCount |
number | <optional> |
Maximum geometry object count to check for. Omit to assume 1. |
(static) toHaveMinGeometryCount(geometryObject, MinCountopt)
- Source:
- See:
Verifies a valid GeoJSON GeometryCollection has more than or equal to a
specified number of geometries. If omitting MinCount, it passes if at least
one geometry object is contained in "geometries". Will fail if MinCount is
not a number or less than zero. Nested GeometryCollections are only counted
as a single geometry object.
Examples
const testCollection = {
"type": "GeometryCollection",
"geometries": [{
"type": "Point",
"coordinates": [100.0, 0.0]
}, {
"type": "LineString",
"coordinates": [
[101.0, 0.0],
[102.0, 1.0]
]
}, {
"type": "Polygon",
"coordinates": [
[
[102.0, 2.0],
[103.0, 2.0],
[103.0, 3.0],
[102.0, 3.0],
[102.0, 2.0]
]
]
}, {
"type": "Point",
"coordinates": [150.0, 73.0]
}]
}
test('GeometryCollection has minimum geometry count', () => {
expect(testCollection).toHaveMinGeometryCount()
expect(testCollection).toHaveMinGeometryCount(4)
})
const emptyCollection = {
"type": "GeometryCollection",
"geometries": []
}
const polygon = {
type: 'Polygon',
coordinates: [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0],
[100.0, 0.0]
]
]
}
test('Object is not a GeometryCollection or does not have minimum geometry count', () => {
expect(testCollection).not.toHaveMinGeometryCount(5)
expect(emptyCollection).not.toHaveMinGeometryCount()
expect(polygon).not.toHaveMinGeometryCount(1)
})
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
geometryObject |
object | A GeoJSON GeometryCollection object | |
MinCount |
number | <optional> |
Minimum geometry object count to check for. Omit to assume 1. |