Utilities

Core. Utilities

Source:
Various helper functions used within Core.

Methods

(static) commonGeometryValidation(geometryObject) → {boolean}

Source:
This tests an object to see if it meets common required criteria between all GeoJSON geometry objects.
Parameters:
Name Type Description
geometryObject object A GeoJSON geometry object to test for common validity requirements
Throws:
  • Argument must be a GeoJSON Geometry object.
    Type
    Error
  • Must have a type property with value 'Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon', or 'GeometryCollection'.
    Type
    Error
  • GeoJSON Geometry objects are forbidden from having a property 'geometry'.
    Type
    Error
  • GeoJSON Geometry objects are forbidden from having a property 'properties'.
    Type
    Error
  • GeoJSON Geometry objects are forbidden from having a property 'features'.
    Type
    Error
  • GeoJSON Geometry objects (except GeometryCollection) must contain a 'coordinates' property.
    Type
    Error
  • Coordinates property must be an array (appropriately structured by geometry type) with valid GeoJSON coordinates.
    Type
    Error
Returns:
True if all common validations passed. Will throw a specific error if it encounters a problem.
Type
boolean

(static) validGeoJSON(geoObject) → {boolean}

Source:
See:
This tests an object to see if it meets validation criteria for any of the seven GeoJSON Geometry types, Features, or FeatureCollections.
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]
        ]
    ]
}
feature = {
    "type": "Feature",
    "geometry": {
        "type": "Point",
        "coordinates": [102.0, 0.5]
    }
}
geometryCollection = {
    "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]
    }]
}

// All of these will return true:

validGeoJSON(point)
validGeoJSON(lineString)
validGeoJSON(polygon)
validGeoJSON(feature)
validGeoJSON(feature.geometry)
validGeoJSON(geometryCollection)
validGeoJSON(geometryCollection.geometries[1])
// All of these throw errors:

validGeoJSON(polygon.coordinates)
validGeoJSON(geometryCollection.geometries)
validGeoJSON([322, -34.549, 0])
validGeoJSON({coordinates: [22, -34.549, 22]})
Parameters:
Name Type Description
geoObject object Any GeoJSON Geometry, Feature, or FeatureCollection object
Throws:
Argument must be a GeoJSON Geometry, Feature, or FeatureCollection object.
Type
Error
Returns:
True if a valid GeoJSON object. Will throw a specific error if it encounters a problem.
Type
boolean