Features

Core. Features

Source:
Feature object validation functions used within Core.

Methods

(static) feature(featureObject, geometryTypeopt) → {boolean}

Source:
See:
Verifies an object is a valid GeoJSON Feature. This object requires a "type" member that must equal 'Feature', a "geometry" member that contains either one of the seven valid GeoJSON geometry objects or an empty array, and a "properties" member that is either an object of any composition or null. Foreign members are allowed with the exceptions thrown below. If present, bounding boxes must be valid.
Example
const testFeature = {
    "type": "Feature",
    "bbox": [-10.0, -10.0, 10.0, 10.0],
    "geometry": {
        "type": "Polygon",
        "coordinates": [
            [
                [-10.0, -10.0],
                [10.0, -10.0],
                [10.0, 10.0],
                [-10.0, -10.0]
            ]
        ]
    },
    "properties": {
        "prop0": "value0",
        "prop1": {
            "this": "that"
        }
    }
}
const multiPoint = {
    type: "MultiPoint",
    coordinates: [
        [101.0, 0.0],
        [102.0, 1.0]
    ]
}

const goodExample1 = feature(testFeature)) // true
const goodExample2 = feature(testFeature, 'Polygon')) // true

const badExample1 = feature(multiPoint)) // throws error
const badExample2 = feature(testFeature, 'LineString')) // throws error
const badExample3 = feature(testFeature.geometry, 'Polygon')) // throws error
Parameters:
Name Type Attributes Description
featureObject object a GeoJSON LineString Geometry object
geometryType string <optional>
Specific type of geometry to search for
Throws:
  • Argument not an object
    Type
    Error
  • Must have a type property with value 'Feature'
    Type
    Error
  • Forbidden from having a property 'coordinates', 'geometries', 'properties', or 'features'
    Type
    Error
  • Bounding box must be valid (if present)
    Type
    Error
  • ID must be either a number or string (if present)
    Type
    Error
Returns:
True if a valid GeoJSON Feature. If invalid, it will throw an error.
Type
boolean

(static) hasID(featureObject, SearchIDopt) → {boolean}

Source:
See:
Checks if a GeoJSON Feature has an ID. Providing an optional SearchID argument will check for that exact ID or array of possible ID values.
Examples
const testFeature = {
    type: 'Feature',
    id: 'f1',
    geometry: {...},
    properties: {...}
}

// All of these return true
const goodExample1 = hasID(testFeature)
const goodExample2 = hasID(testFeature, 'f1')
const goodExample3 = hasID(testFeature, [1, 'F', 'F12', /[a-z]+[0-9]+/])

// Both of these return false
const badExample1 = hasID(testFeature, 'f12')
const badExample2 = hasID(testFeature, [1, 'F', 'F12', /SomeID/])
const testFeature = {
    type: 'Feature',
    geometry: {...},
    properties: {...}
}

const example = hasID(testFeature) // false
Parameters:
Name Type Attributes Description
featureObject object a GeoJSON Feature object
SearchID string | number | RegExp | Array.<string> | Array.<number> | Array.<RegExp> <optional>
Specific value or array of possible values to search for.
Throws:
  • Argument must be a GeoJSON Feature object
    Type
    Error
  • Feature object must have an "id" member
    Type
    Error
  • Optional SearchID must be either a number, string, RegExp, or array of any of these values
    Type
    Error
Returns:
True if the Feature object has any ID (no argument provided), or if the ID exactly matches the optional argument (single string, number, or RegExp provided), or any value within an array of any combination of strings, numbers, or RegExp. If the object has an ID that does not match SearchID, it returns false.
Type
boolean