- Source:
Geometry object validation functions used within Core.
Methods
(static) anyGeometry(geometryObject) → {boolean}
- Source:
- See:
Verifies an object meets validity requirements for one of the six basic
GeoJSON geometry types: Point, MultiPoint, LineString, MultiLineString,
Polygon, MultiPolygon, GeometryCollection
Example
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]
]
]
}
feature = {
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [102.0, 0.5]
}
}
const goodExample1 = anyGeometry(point)) // true
const goodExample2 = anyGeometry(lineString)) // true
const goodExample3 = anyGeometry(polygon)) // true
const badExample = anyGeometry(feature)) // throws error
Parameters:
Name | Type | Description |
---|---|---|
geometryObject |
object | A WGS-84 array of [longitude, latitude] or [longitude, latitude, alititude] |
Throws:
-
Input must be either a valid Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon, or GeometryCollection
- Type
- Error
Returns:
True if a valid GeoJSON geometry object. If invalid, it will throw an error.
- Type
- boolean
(static) geometryCollection(geometryObject) → {boolean}
- 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 exceptions thrown below. If
present, bounding boxes must be valid.
Example
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]
}]
}
const goodExample = geometryCollection(collection) // true
const badExample1 = geometryCollection(collection.geometries) // throws error
const badExample2 = geometryCollection(collection.geometries[1]) // throws error
Parameters:
Name | Type | Description |
---|---|---|
geometryObject |
object | a GeoJSON Geometry object |
Throws:
-
-
Argument not an object
- Type
- Error
-
-
-
Must have a type property with value 'GeometryCollection'
- Type
- Error
-
-
-
Forbidden from having a property 'geometry', 'properties', or 'features'
- Type
- Error
-
Returns:
True if a valid GeoJSON GeometryCollection Geometry. If invalid, it will
throw an error.
- Type
- boolean
(static) lineStringGeometry(geometryObject) → {boolean}
- 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
coordinates. The coordinates may be an empty array, but may not be an array
of empty arrays. Foreign members are allowed with the exceptions thrown
below. If present, bounding boxes must be valid.
Example
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]
]
]
}
const point = {
type: 'Point',
coordinates: [100.0, 0.0]
}
const goodExample = lineStringGeometry(linestring) // true
const badExample = lineStringGeometry(point)) / throws error
Parameters:
Name | Type | Description |
---|---|---|
geometryObject |
object | a GeoJSON LineString Geometry object |
Throws:
-
-
Argument not an object
- Type
- Error
-
-
-
Must have a type property with value 'LineString'
- Type
- Error
-
-
-
Forbidden from having a property 'geometry', 'properties', or 'features'
- Type
- Error
-
Returns:
True if a valid GeoJSON LineString Geometry. If invalid, it will throw an
error.
- Type
- boolean
(static) multiLineStringGeometry(geometryObject) → {boolean}
- 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 exceptions thrown
below. If present, bounding boxes must be valid.
Example
const multiLineString = {
type: 'MultiLineString',
coordinates: [
[
[100.0, 0.0],
[101.0, 1.0]
],
[
[102.0, 2.0],
[103.0, 3.0]
]
]
}
const multiLineStringOneCoordinate = {
type: 'MultiLineString',
coordinates: [
[
[100.0, 0.0]
]
]
}
const point = {
type: 'Point',
coordinates: [100.0, 0.0]
}
const goodExample = multiLineStringGeometry(multiLineString) // true
const badExample1 = multiLineStringGeometry(point) // throws error
const badExample2 = multiLineStringGeometry(multiLineStringOneCoordinate) // throws error
Parameters:
Name | Type | Description |
---|---|---|
geometryObject |
object | a GeoJSON MultiLineString Geometry object |
Throws:
-
-
Argument not an object
- Type
- Error
-
-
-
Must have a type property with value 'MultiLineString'
- Type
- Error
-
-
-
Coordinates array must contain two or more valid GeoJSON coordinates
- Type
- Error
-
-
-
Forbidden from having a property 'geometry', 'properties', or 'features'
- Type
- Error
-
Returns:
True if a valid GeoJSON MultiLineString Geometry. If invalid, it will throw
an error.
- Type
- boolean
(static) multiPointGeometry(geometryObject) → {boolean}
- 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 a single coordinate or an array of valid WGS-84
GeoJSON coordinates. The coordinates may be an empty array. Foreign members
are allowed with the exceptions thrown below. If present, bounding boxes
must be valid.
Example
const testMultiPoint1 = {
type: 'MultiPoint',
id: null,
coordinates: [[25, 90], [-180, 0]]
}
const testMultiPoint2 = {
type: 'Point',
coordinates: [25, 90]
}
const goodExample = console.log(multiPointGeometry(testMultiPoint1) // true
const badExample = console.log(multiPointGeometry(testMultiPoint2) // throws error
Parameters:
Name | Type | Description |
---|---|---|
geometryObject |
object | a GeoJSON MultiPoint Geometry object |
Throws:
-
-
Argument not an object
- Type
- Error
-
-
-
Must have a type property with value 'MultiPoint'
- Type
- Error
-
-
-
Forbidden from having a property 'geometry', 'properties', or 'features'
- Type
- Error
-
Returns:
True if a valid GeoJSON MultiPoint Geometry. If invalid, it will throw an
error.
- Type
- boolean
(static) multiPolygonGeometry(geometryObject) → {boolean}
- 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 exceptions thrown below. If present, bounding
boxes must be valid.
Example
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]
]
]
]
}
const point = {
type: 'Point',
coordinates: [100.0, 0.0]
}
const goodExample1 = multiPolygonGeometry(multiPolygon) // true
const goodExample2 = multiPolygonGeometry(multiPolygonWithSingleElement) // true
const badExample = multiPolygonGeometry(point) // throws error
Parameters:
Name | Type | Description |
---|---|---|
geometryObject |
object | a GeoJSON Polygon Geometry object |
Throws:
-
-
Argument not an object
- Type
- Error
-
-
-
Must have a type property with value 'MultiPolygon'
- Type
- Error
-
-
-
Coordinates array must contain four or more valid GeoJSON coordinates
- Type
- Error
-
-
-
Final coordinate must match first coordinate
- Type
- Error
-
-
-
Forbidden from having a property 'geometry', 'properties', or 'features'
- Type
- Error
-
Returns:
True if a valid GeoJSON MultiPolygon Geometry. If invalid, it will throw an
error.
- Type
- boolean
(static) pointGeometry(geometryObject) → {boolean}
- 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 exceptions thrown below.
If present, bounding boxes must be valid.
Example
const testPoint = {
type: 'Point',
coordinates: [25, 10.2]
}
const testPoint1 = {
coordinates: [25, 10.2]
}
const testPoint2 = {
type: 'MultiPoint',
coordinates: [[25, 10.2], [120, 45]}
}
const goodExample = pointGeometry(testPoint) // true
const badExample1 = pointGeometry(testPoint1) // throws error for missing type
const badExample2 = pointGeometry(testPoint2) // throws error for being MultiPoint
Parameters:
Name | Type | Description |
---|---|---|
geometryObject |
object | a GeoJSON Point Geometry object |
Throws:
-
-
Argument not an object
- Type
- Error
-
-
-
Must have a type property with value 'Point'
- Type
- Error
-
-
-
Forbidden from having a property 'geometry', 'properties', or 'features'
- Type
- Error
-
Returns:
True if a valid GeoJSON Point Geometry. If invalid, it will throw an error.
- Type
- boolean
(static) polygonGeometry(geometryObject) → {boolean}
- 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
exceptions thrown below. If present, bounding boxes must be valid.
Example
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]
]
]
}
const polygonEndDoesNotEqualStart = {
type: 'Polygon',
coordinates: [
[
[100.0, 0.0],
[101.0, 0.0],
[101.0, 1.0],
[100.0, 1.0]
]
]
}
const point = {
type: 'Point',
coordinates: [100.0, 0.0]
}
const goodExample = polygonGeometry(polygon) // true
const badExample1 = console.log(polygonGeometry(point) // throws error
const badExample2 = console.log(polygonGeometry(polygonEndDoesNotEqualStart) // throws error
Parameters:
Name | Type | Description |
---|---|---|
geometryObject |
object | a GeoJSON Polygon Geometry object |
Throws:
-
-
Argument not an object
- Type
- Error
-
-
-
Must have a type property with value 'Polygon'
- Type
- Error
-
-
-
Coordinates array must contain four or more valid GeoJSON coordinates
- Type
- Error
-
-
-
Final coordinate must match first coordinate
- Type
- Error
-
-
-
Forbidden from having a property 'geometry', 'properties', or 'features'
- Type
- Error
-
Returns:
True if a valid GeoJSON Polygon Geometry. If invalid, it will throw an
error.
- Type
- boolean