geojson-validation
Advanced tools
Comparing version 0.1.6 to 0.2.0
1519
index.js
/** | ||
* geoJSON validation according to the GeoJSON spefication Version 1 | ||
* @module geoJSONValidation | ||
* @class Main | ||
* @exports {GJV} | ||
*/ | ||
* geoJSON validation according to the GeoJSON spefication Version 1 | ||
* @module geoJSONValidation | ||
* @class Main | ||
* @exports {GJV} | ||
*/ | ||
(function(exports){ | ||
const definitions = {} | ||
var definitions = {}; | ||
/** | ||
* Test an object to see if it is a function | ||
* @method isFunction | ||
* @param object {Object} | ||
* @return {Boolean} | ||
*/ | ||
function isFunction (object) { | ||
return typeof (object) === 'function' | ||
} | ||
/** | ||
* Test an object to see if it is a function | ||
* @method isFunction | ||
* @param object {Object} | ||
* @return {Boolean} | ||
*/ | ||
function isFunction(object) { | ||
return typeof(object) == 'function'; | ||
} | ||
/** | ||
* A truthy test for objects | ||
* @method isObject | ||
* @param {Object} | ||
* @return {Boolean} | ||
*/ | ||
function isObject(object) { | ||
return object === Object(object); | ||
} | ||
/** | ||
* A truthy test for objects | ||
* @method isObject | ||
* @param {Object} | ||
* @return {Boolean} | ||
*/ | ||
function isObject (object) { | ||
return object === Object(object) | ||
} | ||
/** | ||
* Formats error messages, calls the callback | ||
* @method done | ||
* @private | ||
* @param cb {Function} callback | ||
* @param [message] {Function} callback | ||
* @return {Boolean} is the object valid or not? | ||
*/ | ||
function _done(cb, message){ | ||
var valid = false; | ||
/** | ||
* Formats error messages, calls the callback | ||
* @method done | ||
* @private | ||
* @param cb {Function} callback | ||
* @param [message] {Function} callback | ||
* @return {Boolean} is the object valid or not? | ||
*/ | ||
function _done (cb, message) { | ||
let valid = false | ||
if(typeof message === "string"){ | ||
message = [message]; | ||
if (typeof message === 'string') { | ||
message = [message] | ||
} else if (Object.prototype.toString.call(message) === '[object Array]') { | ||
if (message.length === 0) { | ||
valid = true | ||
} | ||
} else { | ||
valid = true | ||
} | ||
}else if( Object.prototype.toString.call( message ) === '[object Array]' ) { | ||
if(message.length === 0){ | ||
valid = true; | ||
} | ||
}else{ | ||
valid = true; | ||
} | ||
if( isFunction(cb)){ | ||
if(valid){ | ||
cb(valid, []); | ||
}else{ | ||
cb(valid, message); | ||
} | ||
} | ||
return valid; | ||
if (isFunction(cb)) { | ||
if (valid) { | ||
cb(valid, []) | ||
} else { | ||
cb(valid, message) | ||
} | ||
} | ||
/** | ||
* calls a custom definition if one is avalible for the given type | ||
* @method _customDefinitions | ||
* @private | ||
* @param type {"String"} a GeoJSON object type | ||
* @param object {Object} the Object being tested | ||
* @return {Array} an array of errors | ||
*/ | ||
function _customDefinitions(type, object){ | ||
return valid | ||
} | ||
var errors; | ||
/** | ||
* calls a custom definition if one is avalible for the given type | ||
* @method _customDefinitions | ||
* @private | ||
* @param type {'String'} a GeoJSON object type | ||
* @param object {Object} the Object being tested | ||
* @return {Array} an array of errors | ||
*/ | ||
function _customDefinitions (type, object) { | ||
let errors | ||
if(isFunction(definitions[type])){ | ||
try{ | ||
errors = definitions[type](object); | ||
}catch(e){ | ||
errors = ["Problem with custom definition for '" + type + ": " + e]; | ||
} | ||
if(typeof result === "string"){ | ||
errors = [errors]; | ||
} | ||
if(Object.prototype.toString.call( errors ) === '[object Array]'){ | ||
return errors; | ||
} | ||
} | ||
return []; | ||
if (isFunction(definitions[type])) { | ||
try { | ||
errors = definitions[type](object) | ||
} catch (e) { | ||
errors = [`Problem with custom definition for ${type}: ${e}`] | ||
} | ||
if (typeof result === 'string') { | ||
errors = [errors] | ||
} | ||
if (Object.prototype.toString.call(errors) === '[object Array]') { | ||
return errors | ||
} | ||
} | ||
return [] | ||
} | ||
/** | ||
* Define a custom validation function for one of GeoJSON objects | ||
* @method define | ||
* @param type {GeoJSON Type} the type | ||
* @param definition {Function} A validation function | ||
* @return {Boolean} Return true if the function was loaded corectly else false | ||
*/ | ||
exports.define = function(type, definition){ | ||
if((type in all_types) && isFunction(definition)){ | ||
//TODO: check to see if the type is valid | ||
definitions[type] = definition; | ||
return true; | ||
} | ||
return false; | ||
}; | ||
/** | ||
* Define a custom validation function for one of GeoJSON objects | ||
* @method define | ||
* @param type {GeoJSON Type} the type | ||
* @param definition {Function} A validation function | ||
* @return {Boolean} Return true if the function was loaded corectly else false | ||
*/ | ||
exports.define = function (type, definition) { | ||
if ((type in allTypes) && isFunction(definition)) { | ||
// TODO: check to see if the type is valid | ||
definitions[type] = definition | ||
return true | ||
} else { | ||
return false | ||
} | ||
} | ||
/** | ||
* Determines if an object is a position or not | ||
* @method isPosition | ||
* @param position {Array} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isPosition = function(position, cb){ | ||
/** | ||
* Determines if an object is a position or not | ||
* @method isPosition | ||
* @param position {Array} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isPosition = function (position, cb) { | ||
let errors = [] | ||
var errors = []; | ||
// It must be an array | ||
if (Array.isArray(position)) { | ||
// and the array must have more than one element | ||
if (position.length <= 1) { | ||
errors.push('Position must be at least two elements') | ||
} | ||
//It must be an array | ||
if(Array.isArray(position)){ | ||
//and the array must have more than one element | ||
if(position.length <= 1){ | ||
errors.push("Position must be at least two elements"); | ||
} | ||
}else{ | ||
errors.push("Position must be an array"); | ||
} | ||
position.forEach((pos, index) => { | ||
if (typeof pos !== 'number') { | ||
errors.push(`Position must only contain numbers. Item ${pos} at index ${index} is invalid.`) | ||
} | ||
}) | ||
} else { | ||
errors.push('Position must be an array') | ||
} | ||
//run custom checks | ||
errors = errors.concat(_customDefinitions("Position", position)); | ||
// run custom checks | ||
errors = errors.concat(_customDefinitions('Position', position)) | ||
return _done(cb, errors); | ||
}; | ||
return _done(cb, errors) | ||
} | ||
/** | ||
* Determines if an object is a GeoJSON Object or not | ||
* @method isGeoJSONObject|valid | ||
* @param geoJSONObject {Object} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isGeoJSONObject = exports.valid = function(geoJSONObject, cb){ | ||
/** | ||
* Determines if an object is a GeoJSON Object or not | ||
* @method isGeoJSONObject|valid | ||
* @param geoJSONObject {Object} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isGeoJSONObject = exports.valid = function (geoJSONObject, cb) { | ||
if (!isObject(geoJSONObject)) { | ||
return _done(cb, ['must be a JSON Object']) | ||
} else { | ||
let errors = [] | ||
if ('type' in geoJSONObject) { | ||
if (nonGeoTypes[geoJSONObject.type]) { | ||
return nonGeoTypes[geoJSONObject.type](geoJSONObject, cb) | ||
} else if (geoTypes[geoJSONObject.type]) { | ||
return geoTypes[geoJSONObject.type](geoJSONObject, cb) | ||
} else { | ||
errors.push('type must be one of: "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", "GeometryCollection", "Feature", or "FeatureCollection"') | ||
} | ||
} else { | ||
errors.push('must have a member with the name "type"') | ||
} | ||
if(!isObject(geoJSONObject)){ | ||
return _done(cb, ['must be a JSON Object']); | ||
} | ||
// run custom checks | ||
errors = errors.concat(_customDefinitions('GeoJSONObject', geoJSONObject)) | ||
return _done(cb, errors) | ||
} | ||
} | ||
var errors = []; | ||
if('type' in geoJSONObject){ | ||
if(non_geo_types[geoJSONObject.type]){ | ||
return non_geo_types[geoJSONObject.type](geoJSONObject, cb); | ||
}else if(geo_types[geoJSONObject.type]){ | ||
return geo_types[geoJSONObject.type](geoJSONObject, cb); | ||
}else{ | ||
errors.push('type must be one of: "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", "GeometryCollection", "Feature", or "FeatureCollection"'); | ||
} | ||
}else{ | ||
errors.push("must have a member with the name 'type'"); | ||
} | ||
/** | ||
* Determines if an object is a Geometry Object or not | ||
* @method isGeometryObject | ||
* @param geometryObject {Object} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isGeometryObject = function (geometryObject, cb) { | ||
if (!isObject(geometryObject)) { | ||
return _done(cb, ['must be a JSON Object']) | ||
} | ||
//run custom checks | ||
errors = errors.concat(_customDefinitions("GeoJSONObject", geoJSONObject)); | ||
return _done(cb, errors); | ||
}; | ||
let errors = [] | ||
/** | ||
* Determines if an object is a Geometry Object or not | ||
* @method isGeometryObject | ||
* @param geometryObject {Object} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isGeometryObject = function(geometryObject, cb){ | ||
if ('type' in geometryObject) { | ||
if (geoTypes[geometryObject.type]) { | ||
return geoTypes[geometryObject.type](geometryObject, cb) | ||
} else { | ||
errors.push('type must be one of: "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon" or "GeometryCollection"') | ||
} | ||
} else { | ||
errors.push('must have a member with the name "type"') | ||
} | ||
if(!isObject(geometryObject)){ | ||
return _done(cb, ['must be a JSON Object']); | ||
} | ||
// run custom checks | ||
errors = errors.concat(_customDefinitions('GeometryObject', geometryObject)) | ||
return _done(cb, errors) | ||
} | ||
var errors = []; | ||
/** | ||
* Determines if an object is a Point or not | ||
* @method isPoint | ||
* @param point {Object} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isPoint = function (point, cb) { | ||
if (!isObject(point)) { | ||
return _done(cb, ['must be a JSON Object']) | ||
} | ||
if('type' in geometryObject){ | ||
if(geo_types[geometryObject.type]){ | ||
return geo_types[geometryObject.type](geometryObject, cb); | ||
}else{ | ||
errors.push('type must be one of: "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon" or "GeometryCollection"'); | ||
} | ||
}else{ | ||
errors.push("must have a member with the name 'type'"); | ||
} | ||
let errors = [] | ||
//run custom checks | ||
errors = errors.concat(_customDefinitions("GeometryObject", geometryObject)); | ||
return _done(cb, errors); | ||
}; | ||
if ('bbox' in point) { | ||
exports.isBbox(point.bbox, function (valid, err) { | ||
if (!valid) { | ||
errors = errors.concat(err) | ||
} | ||
}) | ||
} | ||
/** | ||
* Determines if an object is a Point or not | ||
* @method isPoint | ||
* @param point {Object} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isPoint = function(point, cb) { | ||
if ('type' in point) { | ||
if (point.type !== 'Point') { | ||
errors.push('type must be "Point"') | ||
} | ||
} else { | ||
errors.push('must have a member with the name "type"') | ||
} | ||
if(!isObject(point)){ | ||
return _done(cb, ['must be a JSON Object']); | ||
} | ||
if ('coordinates' in point) { | ||
exports.isPosition(point.coordinates, function (valid, err) { | ||
if (!valid) { | ||
errors.push('Coordinates must be a single position') | ||
} | ||
}) | ||
} else { | ||
errors.push('must have a member with the name "coordinates"') | ||
} | ||
var errors = []; | ||
// run custom checks | ||
errors = errors.concat(_customDefinitions('Point', point)) | ||
if('bbox' in point){ | ||
exports.isBbox(point.bbox, function(valid, err){ | ||
if(!valid){ | ||
errors = errors.concat(err); | ||
} | ||
}); | ||
} | ||
return _done(cb, errors) | ||
} | ||
if('type' in point){ | ||
if(point.type !== "Point"){ | ||
errors.push("type must be 'Point'"); | ||
} | ||
}else{ | ||
errors.push("must have a member with the name 'type'"); | ||
} | ||
/** | ||
* Determines if an array can be interperted as coordinates for a MultiPoint | ||
* @method isMultiPointCoor | ||
* @param coordinates {Array} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isMultiPointCoor = function (coordinates, cb) { | ||
let errors = [] | ||
if('coordinates' in point){ | ||
exports.isPosition(point.coordinates, function(valid, err){ | ||
if(!valid){ | ||
errors.push('Coordinates must be a single position'); | ||
} | ||
}); | ||
}else{ | ||
errors.push("must have a member with the name 'coordinates'"); | ||
if (Array.isArray(coordinates)) { | ||
coordinates.forEach(function (val, index) { | ||
exports.isPosition(val, function (valid, err) { | ||
if (!valid) { | ||
// modify the err msg from "isPosition" to note the element number | ||
err[0] = 'at ' + index + ': '.concat(err[0]) | ||
// build a list of invalide positions | ||
errors = errors.concat(err) | ||
} | ||
}) | ||
}) | ||
} else { | ||
errors.push('coordinates must be an array') | ||
} | ||
//run custom checks | ||
errors = errors.concat(_customDefinitions("Point", point)); | ||
return _done(cb, errors) | ||
} | ||
/** | ||
* Determines if an object is a MultiPoint or not | ||
* @method isMultiPoint | ||
* @param position {Object} | ||
* @param cb {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isMultiPoint = function (multiPoint, cb) { | ||
if (!isObject(multiPoint)) { | ||
return _done(cb, ['must be a JSON Object']) | ||
} | ||
return _done(cb, errors); | ||
}; | ||
let errors = [] | ||
/** | ||
* Determines if an array can be interperted as coordinates for a MultiPoint | ||
* @method isMultiPointCoor | ||
* @param coordinates {Array} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isMultiPointCoor = function(coordinates, cb) { | ||
if ('bbox' in multiPoint) { | ||
exports.isBbox(multiPoint.bbox, function (valid, err) { | ||
if (!valid) { | ||
errors = errors.concat(err) | ||
} | ||
}) | ||
} | ||
var errors = []; | ||
if ('type' in multiPoint) { | ||
if (multiPoint.type !== 'MultiPoint') { | ||
errors.push('type must be "MultiPoint"') | ||
} | ||
} else { | ||
errors.push('must have a member with the name "type"') | ||
} | ||
if(Array.isArray(coordinates)){ | ||
coordinates.forEach(function(val, index){ | ||
exports.isPosition(val, function(valid, err){ | ||
if(!valid){ | ||
//modify the err msg from "isPosition" to note the element number | ||
err[0] = "at "+ index+ ": ".concat(err[0]); | ||
//build a list of invalide positions | ||
errors = errors.concat(err); | ||
} | ||
}); | ||
}); | ||
}else{ | ||
errors.push("coordinates must be an array"); | ||
} | ||
if ('coordinates' in multiPoint) { | ||
exports.isMultiPointCoor(multiPoint.coordinates, function (valid, err) { | ||
if (!valid) { | ||
errors = errors.concat(err) | ||
} | ||
}) | ||
} else { | ||
errors.push('must have a member with the name "coordinates"') | ||
} | ||
return _done(cb, errors); | ||
}; | ||
/** | ||
* Determines if an object is a MultiPoint or not | ||
* @method isMultiPoint | ||
* @param position {Object} | ||
* @param cb {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isMultiPoint = function(multiPoint, cb) { | ||
// run custom checks | ||
errors = errors.concat(_customDefinitions('MultiPoint', multiPoint)) | ||
if(!isObject(multiPoint)){ | ||
return _done(cb, ['must be a JSON Object']); | ||
} | ||
return _done(cb, errors) | ||
} | ||
var errors = []; | ||
/** | ||
* Determines if an array can be interperted as coordinates for a lineString | ||
* @method isLineStringCoor | ||
* @param coordinates {Array} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isLineStringCoor = function (coordinates, cb) { | ||
let errors = [] | ||
if (Array.isArray(coordinates)) { | ||
if (coordinates.length > 1) { | ||
coordinates.forEach(function (val, index) { | ||
exports.isPosition(val, function (valid, err) { | ||
if (!valid) { | ||
// modify the err msg from 'isPosition' to note the element number | ||
err[0] = 'at ' + index + ': '.concat(err[0]) | ||
// build a list of invalide positions | ||
errors = errors.concat(err) | ||
} | ||
}) | ||
}) | ||
} else { | ||
errors.push('coordinates must have at least two elements') | ||
} | ||
} else { | ||
errors.push('coordinates must be an array') | ||
} | ||
if('bbox' in multiPoint){ | ||
exports.isBbox(multiPoint.bbox, function(valid, err){ | ||
if(!valid){ | ||
errors = errors.concat(err); | ||
} | ||
}); | ||
} | ||
return _done(cb, errors) | ||
} | ||
if('type' in multiPoint){ | ||
if(multiPoint.type !== "MultiPoint"){ | ||
errors.push("type must be 'MultiPoint'"); | ||
} | ||
}else{ | ||
errors.push("must have a member with the name 'type'"); | ||
} | ||
/** | ||
* Determines if an object is a lineString or not | ||
* @method isLineString | ||
* @param lineString {Object} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isLineString = function (lineString, cb) { | ||
if (!isObject(lineString)) { | ||
return _done(cb, ['must be a JSON Object']) | ||
} | ||
if('coordinates' in multiPoint){ | ||
exports.isMultiPointCoor(multiPoint.coordinates, function(valid, err){ | ||
if(!valid){ | ||
errors = errors.concat(err); | ||
} | ||
}); | ||
}else{ | ||
errors.push("must have a member with the name 'coordinates'"); | ||
} | ||
let errors = [] | ||
//run custom checks | ||
errors = errors.concat(_customDefinitions("MultiPoint", multiPoint)); | ||
if ('bbox' in lineString) { | ||
exports.isBbox(lineString.bbox, function (valid, err) { | ||
if (!valid) { | ||
errors = errors.concat(err) | ||
} | ||
}) | ||
} | ||
return _done(cb, errors); | ||
}; | ||
if ('type' in lineString) { | ||
if (lineString.type !== 'LineString') { | ||
errors.push('type must be "LineString"') | ||
} | ||
} else { | ||
errors.push('must have a member with the name "type"') | ||
} | ||
/** | ||
* Determines if an array can be interperted as coordinates for a lineString | ||
* @method isLineStringCoor | ||
* @param coordinates {Array} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isLineStringCoor = function(coordinates, cb) { | ||
if ('coordinates' in lineString) { | ||
exports.isLineStringCoor(lineString.coordinates, function (valid, err) { | ||
if (!valid) { | ||
errors = errors.concat(err) | ||
} | ||
}) | ||
} else { | ||
errors.push('must have a member with the name "coordinates"') | ||
} | ||
var errors = []; | ||
if(Array.isArray(coordinates)){ | ||
if(coordinates.length > 1){ | ||
coordinates.forEach(function(val, index){ | ||
exports.isPosition(val, function(valid, err){ | ||
if(!valid){ | ||
//modify the err msg from "isPosition" to note the element number | ||
err[0] = "at "+ index+ ": ".concat(err[0]); | ||
//build a list of invalide positions | ||
errors = errors.concat(err); | ||
} | ||
}); | ||
}); | ||
}else{ | ||
errors.push("coordinates must have at least two elements"); | ||
} | ||
}else{ | ||
errors.push( "coordinates must be an array"); | ||
} | ||
// run custom checks | ||
errors = errors.concat(_customDefinitions('LineString', lineString)) | ||
return _done(cb, errors); | ||
}; | ||
return _done(cb, errors) | ||
} | ||
/** | ||
* Determines if an object is a lineString or not | ||
* @method isLineString | ||
* @param lineString {Object} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isLineString = function(lineString, cb){ | ||
if(!isObject(lineString)){ | ||
return _done(cb, ['must be a JSON Object']); | ||
/** | ||
* Determines if an array can be interperted as coordinates for a MultiLineString | ||
* @method isMultiLineStringCoor | ||
* @param coordinates {Array} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isMultiLineStringCoor = function (coordinates, cb) { | ||
let errors = [] | ||
if (Array.isArray(coordinates)) { | ||
coordinates.forEach(function (val, index) { | ||
exports.isLineStringCoor(val, function (valid, err) { | ||
if (!valid) { | ||
// modify the err msg from 'isPosition' to note the element number | ||
err[0] = 'at ' + index + ': '.concat(err[0]) | ||
// build a list of invalide positions | ||
errors = errors.concat(err) | ||
} | ||
}) | ||
}) | ||
} else { | ||
errors.push('coordinates must be an array') | ||
} | ||
_done(cb, errors) | ||
} | ||
var errors = []; | ||
/** | ||
* Determines if an object is a MultiLine String or not | ||
* @method isMultiLineString | ||
* @param multilineString {Object} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isMultiLineString = function (multilineString, cb) { | ||
if (!isObject(multilineString)) { | ||
return _done(cb, ['must be a JSON Object']) | ||
} | ||
if('bbox' in lineString){ | ||
exports.isBbox(lineString.bbox, function(valid, err){ | ||
if(!valid){ | ||
errors = errors.concat(err); | ||
} | ||
}); | ||
} | ||
let errors = [] | ||
if('type' in lineString){ | ||
if(lineString.type !== "LineString"){ | ||
errors.push("type must be 'LineString'"); | ||
} | ||
}else{ | ||
errors.push("must have a member with the name 'type'"); | ||
} | ||
if ('bbox' in multilineString) { | ||
exports.isBbox(multilineString.bbox, function (valid, err) { | ||
if (!valid) { | ||
errors = errors.concat(err) | ||
} | ||
}) | ||
} | ||
if('coordinates' in lineString){ | ||
exports.isLineStringCoor(lineString.coordinates, function(valid, err){ | ||
if(!valid){ | ||
errors = errors.concat(err); | ||
} | ||
}); | ||
}else{ | ||
errors.push("must have a member with the name 'coordinates'"); | ||
} | ||
if ('type' in multilineString) { | ||
if (multilineString.type !== 'MultiLineString') { | ||
errors.push('type must be "MultiLineString"') | ||
} | ||
} else { | ||
errors.push('must have a member with the name "type"') | ||
} | ||
//run custom checks | ||
errors = errors.concat(_customDefinitions("LineString", lineString)); | ||
if ('coordinates' in multilineString) { | ||
exports.isMultiLineStringCoor(multilineString.coordinates, function (valid, err) { | ||
if (!valid) { | ||
errors = errors.concat(err) | ||
} | ||
}) | ||
} else { | ||
errors.push('must have a member with the name "coordinates"') | ||
} | ||
return _done(cb, errors); | ||
}; | ||
// run custom checks | ||
errors = errors.concat(_customDefinitions('MultiPoint', multilineString)) | ||
/** | ||
* Determines if an array can be interperted as coordinates for a MultiLineString | ||
* @method isMultiLineStringCoor | ||
* @param coordinates {Array} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isMultiLineStringCoor = function(coordinates, cb) { | ||
var errors = []; | ||
if(Array.isArray(coordinates)){ | ||
coordinates.forEach(function(val, index){ | ||
exports.isLineStringCoor(val, function(valid, err){ | ||
if(!valid){ | ||
//modify the err msg from "isPosition" to note the element number | ||
err[0] = "at "+ index+ ": ".concat(err[0]); | ||
//build a list of invalide positions | ||
errors = errors.concat(err); | ||
} | ||
}); | ||
}); | ||
}else{ | ||
errors.push("coordinates must be an array"); | ||
} | ||
_done(cb, errors); | ||
}; | ||
return _done(cb, errors) | ||
} | ||
/** | ||
* Determines if an object is a MultiLine String or not | ||
* @method isMultiLineString | ||
* @param multilineString {Object} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isMultiLineString = function(multilineString, cb){ | ||
/** | ||
* Determines if an array is a linear Ring String or not | ||
* @method isMultiLineString | ||
* @private | ||
* @param coordinates {Array} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
function _linearRingCoor (coordinates, cb) { | ||
let errors = [] | ||
if (Array.isArray(coordinates)) { | ||
// 4 or more positions | ||
if(!isObject(multilineString)){ | ||
return _done(cb, ['must be a JSON Object']); | ||
coordinates.forEach(function (val, index) { | ||
exports.isPosition(val, function (valid, err) { | ||
if (!valid) { | ||
// modify the err msg from 'isPosition' to note the element number | ||
err[0] = 'at ' + index + ': '.concat(err[0]) | ||
// build a list of invalide positions | ||
errors = errors.concat(err) | ||
} | ||
}) | ||
}) | ||
var errors = []; | ||
// check the first and last positions to see if they are equivalent | ||
// TODO: maybe better checking? | ||
if (coordinates[0].toString() !== coordinates[coordinates.length - 1].toString()) { | ||
errors.push('The first and last positions must be equivalent') | ||
} | ||
if('bbox' in multilineString){ | ||
exports.isBbox(multilineString.bbox, function(valid, err){ | ||
if(!valid){ | ||
errors = errors.concat(err); | ||
} | ||
}); | ||
} | ||
if (coordinates.length < 4) { | ||
errors.push('coordinates must have at least four positions') | ||
} | ||
} else { | ||
errors.push('coordinates must be an array') | ||
} | ||
if('type' in multilineString){ | ||
if(multilineString.type !== "MultiLineString"){ | ||
errors.push("type must be 'MultiLineString'"); | ||
} | ||
}else{ | ||
errors.push("must have a member with the name 'type'"); | ||
} | ||
return _done(cb, errors) | ||
} | ||
if('coordinates' in multilineString){ | ||
exports.isMultiLineStringCoor(multilineString.coordinates, function(valid, err){ | ||
if(!valid){ | ||
errors = errors.concat(err); | ||
} | ||
}); | ||
}else{ | ||
errors.push("must have a member with the name 'coordinates'"); | ||
/** | ||
* Determines if an array is valid Polygon Coordinates or not | ||
* @method _polygonCoor | ||
* @private | ||
* @param coordinates {Array} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isPolygonCoor = function (coordinates, cb) { | ||
let errors = [] | ||
if (Array.isArray(coordinates)) { | ||
coordinates.forEach(function (val, index) { | ||
_linearRingCoor(val, function (valid, err) { | ||
if (!valid) { | ||
// modify the err msg from 'isPosition' to note the element number | ||
err[0] = 'at ' + index + ': '.concat(err[0]) | ||
// build a list of invalid positions | ||
errors = errors.concat(err) | ||
} | ||
}) | ||
}) | ||
} else { | ||
errors.push('coordinates must be an array') | ||
} | ||
//run custom checks | ||
errors = errors.concat(_customDefinitions("MultiPoint", multilineString)); | ||
return _done(cb, errors) | ||
} | ||
return _done(cb, errors); | ||
}; | ||
/** | ||
* Determines if an object is a valid Polygon | ||
* @method isPolygon | ||
* @param polygon {Object} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isPolygon = function (polygon, cb) { | ||
if (!isObject(polygon)) { | ||
return _done(cb, ['must be a JSON Object']) | ||
} | ||
/** | ||
* Determines if an array is a linear Ring String or not | ||
* @method isMultiLineString | ||
* @private | ||
* @param coordinates {Array} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
function _linearRingCoor(coordinates, cb) { | ||
let errors = [] | ||
var errors = []; | ||
if(Array.isArray(coordinates)){ | ||
//4 or more positions | ||
if ('bbox' in polygon) { | ||
exports.isBbox(polygon.bbox, function (valid, err) { | ||
if (!valid) { | ||
errors = errors.concat(err) | ||
} | ||
}) | ||
} | ||
coordinates.forEach(function(val, index){ | ||
exports.isPosition(val, function(valid, err){ | ||
if(!valid){ | ||
//modify the err msg from "isPosition" to note the element number | ||
err[0] = "at "+ index+ ": ".concat(err[0]); | ||
//build a list of invalide positions | ||
errors = errors.concat(err); | ||
} | ||
}); | ||
}); | ||
// check the first and last positions to see if they are equivalent | ||
// TODO: maybe better checking? | ||
if(coordinates[0].toString() !== coordinates[coordinates.length -1 ].toString()){ | ||
errors.push( "The first and last positions must be equivalent"); | ||
} | ||
if(coordinates.length < 4){ | ||
errors.push("coordinates must have at least four positions"); | ||
} | ||
}else{ | ||
errors.push("coordinates must be an array"); | ||
} | ||
return _done(cb, errors); | ||
if ('type' in polygon) { | ||
if (polygon.type !== 'Polygon') { | ||
errors.push('type must be "Polygon"') | ||
} | ||
} else { | ||
errors.push('must have a member with the name "type"') | ||
} | ||
/** | ||
* Determines if an array is valid Polygon Coordinates or not | ||
* @method _polygonCoor | ||
* @private | ||
* @param coordinates {Array} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isPolygonCoor = function (coordinates, cb){ | ||
if ('coordinates' in polygon) { | ||
exports.isPolygonCoor(polygon.coordinates, function (valid, err) { | ||
if (!valid) { | ||
errors = errors.concat(err) | ||
} | ||
}) | ||
} else { | ||
errors.push('must have a member with the name "coordinates"') | ||
} | ||
var errors = []; | ||
if(Array.isArray(coordinates)){ | ||
coordinates.forEach(function(val, index){ | ||
_linearRingCoor(val, function(valid, err){ | ||
if(!valid){ | ||
//modify the err msg from "isPosition" to note the element number | ||
err[0] = "at "+ index+ ": ".concat(err[0]); | ||
//build a list of invalid positions | ||
errors = errors.concat(err); | ||
} | ||
}); | ||
}); | ||
}else{ | ||
errors.push("coordinates must be an array"); | ||
} | ||
// run custom checks | ||
errors = errors.concat(_customDefinitions('Polygon', polygon)) | ||
return _done(cb, errors); | ||
}; | ||
return _done(cb, errors) | ||
} | ||
/** | ||
* Determines if an object is a valid Polygon | ||
* @method isPolygon | ||
* @param polygon {Object} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isPolygon = function(polygon, cb){ | ||
if(!isObject(polygon)){ | ||
return _done(cb, ['must be a JSON Object']); | ||
/** | ||
* Determines if an array can be interperted as coordinates for a MultiPolygon | ||
* @method isMultiPolygonCoor | ||
* @param coordinates {Array} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isMultiPolygonCoor = function (coordinates, cb) { | ||
let errors = [] | ||
if (Array.isArray(coordinates)) { | ||
coordinates.forEach(function (val, index) { | ||
exports.isPolygonCoor(val, function (valid, err) { | ||
if (!valid) { | ||
// modify the err msg from 'isPosition' to note the element number | ||
err[0] = 'at ' + index + ': '.concat(err[0]) | ||
// build a list of invalide positions | ||
errors = errors.concat(err) | ||
} | ||
}) | ||
}) | ||
} else { | ||
errors.push('coordinates must be an array') | ||
} | ||
var errors = []; | ||
_done(cb, errors) | ||
} | ||
if('bbox' in polygon){ | ||
exports.isBbox(polygon.bbox, function(valid, err){ | ||
if(!valid){ | ||
errors = errors.concat(err); | ||
} | ||
}); | ||
} | ||
/** | ||
* Determines if an object is a valid MultiPolygon | ||
* @method isMultiPolygon | ||
* @param multiPolygon {Object} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isMultiPolygon = function (multiPolygon, cb) { | ||
if (!isObject(multiPolygon)) { | ||
return _done(cb, ['must be a JSON Object']) | ||
} | ||
if('type' in polygon){ | ||
if(polygon.type !== "Polygon"){ | ||
errors.push("type must be 'Polygon'"); | ||
} | ||
}else{ | ||
errors.push("must have a member with the name 'type'"); | ||
} | ||
let errors = [] | ||
if('coordinates' in polygon){ | ||
exports.isPolygonCoor(polygon.coordinates, function(valid, err) { | ||
if(!valid){ | ||
errors = errors.concat(err); | ||
} | ||
}); | ||
}else{ | ||
errors.push("must have a member with the name 'coordinates'"); | ||
} | ||
if ('bbox' in multiPolygon) { | ||
exports.isBbox(multiPolygon.bbox, function (valid, err) { | ||
if (!valid) { | ||
errors = errors.concat(err) | ||
} | ||
}) | ||
} | ||
//run custom checks | ||
errors = errors.concat(_customDefinitions("Polygon", polygon)); | ||
if ('type' in multiPolygon) { | ||
if (multiPolygon.type !== 'MultiPolygon') { | ||
errors.push('type must be "MultiPolygon"') | ||
} | ||
} else { | ||
errors.push('must have a member with the name "type"') | ||
} | ||
return _done(cb, errors); | ||
}; | ||
if ('coordinates' in multiPolygon) { | ||
exports.isMultiPolygonCoor(multiPolygon.coordinates, function (valid, err) { | ||
if (!valid) { | ||
errors = errors.concat(err) | ||
} | ||
}) | ||
} else { | ||
errors.push('must have a member with the name "coordinates"') | ||
} | ||
/** | ||
* Determines if an array can be interperted as coordinates for a MultiPolygon | ||
* @method isMultiPolygonCoor | ||
* @param coordinates {Array} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isMultiPolygonCoor = function(coordinates, cb) { | ||
var errors = []; | ||
if(Array.isArray(coordinates)){ | ||
coordinates.forEach(function(val, index){ | ||
exports.isPolygonCoor(val, function(valid, err){ | ||
if(!valid){ | ||
//modify the err msg from "isPosition" to note the element number | ||
err[0] = "at "+ index+ ": ".concat(err[0]); | ||
//build a list of invalide positions | ||
errors = errors.concat(err); | ||
} | ||
}); | ||
}); | ||
}else{ | ||
errors.push("coordinates must be an array"); | ||
} | ||
// run custom checks | ||
errors = errors.concat(_customDefinitions('MultiPolygon', multiPolygon)) | ||
_done(cb, errors); | ||
}; | ||
return _done(cb, errors) | ||
} | ||
/** | ||
* Determines if an object is a valid MultiPolygon | ||
* @method isMultiPolygon | ||
* @param multiPolygon {Object} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isMultiPolygon = function(multiPolygon, cb){ | ||
/** | ||
* Determines if an object is a valid Geometry Collection | ||
* @method isGeometryCollection | ||
* @param geometryCollection {Object} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isGeometryCollection = function (geometryCollection, cb) { | ||
if (!isObject(geometryCollection)) { | ||
return _done(cb, ['must be a JSON Object']) | ||
} | ||
if(!isObject(multiPolygon)){ | ||
return _done(cb, ['must be a JSON Object']); | ||
} | ||
let errors = [] | ||
var errors = []; | ||
if ('bbox' in geometryCollection) { | ||
exports.isBbox(geometryCollection.bbox, function (valid, err) { | ||
if (!valid) { | ||
errors = errors.concat(err) | ||
} | ||
}) | ||
} | ||
if('bbox' in multiPolygon){ | ||
exports.isBbox(multiPolygon.bbox, function(valid, err){ | ||
if(!valid){ | ||
errors = errors.concat(err); | ||
} | ||
}); | ||
} | ||
if ('type' in geometryCollection) { | ||
if (geometryCollection.type !== 'GeometryCollection') { | ||
errors.push('type must be "GeometryCollection"') | ||
} | ||
} else { | ||
errors.push('must have a member with the name "type"') | ||
} | ||
if('type' in multiPolygon){ | ||
if(multiPolygon.type !== "MultiPolygon"){ | ||
errors.push("type must be 'MultiPolygon'"); | ||
} | ||
}else{ | ||
errors.push("must have a member with the name 'type'"); | ||
} | ||
if ('geometries' in geometryCollection) { | ||
if (Array.isArray(geometryCollection.geometries)) { | ||
geometryCollection.geometries.forEach(function (val, index) { | ||
exports.isGeometryObject(val, function (valid, err) { | ||
if (!valid) { | ||
// modify the err msg from 'isPosition' to note the element number | ||
err[0] = 'at ' + index + ': '.concat(err[0]) | ||
// build a list of invalide positions | ||
errors = errors.concat(err) | ||
} | ||
}) | ||
}) | ||
} else { | ||
errors.push('"geometries" must be an array') | ||
} | ||
} else { | ||
errors.push('must have a member with the name "geometries"') | ||
} | ||
if('coordinates' in multiPolygon){ | ||
exports.isMultiPolygonCoor(multiPolygon.coordinates, function(valid, err){ | ||
if(!valid){ | ||
errors = errors.concat(err); | ||
} | ||
}); | ||
}else{ | ||
errors.push("must have a member with the name 'coordinates'"); | ||
} | ||
// run custom checks | ||
errors = errors.concat(_customDefinitions('GeometryCollection', geometryCollection)) | ||
//run custom checks | ||
errors = errors.concat(_customDefinitions("MultiPolygon", multiPolygon)); | ||
return _done(cb, errors) | ||
} | ||
return _done(cb, errors); | ||
}; | ||
/** | ||
* Determines if an object is a valid Feature | ||
* @method isFeature | ||
* @param feature {Object} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isFeature = function (feature, cb) { | ||
if (!isObject(feature)) { | ||
return _done(cb, ['must be a JSON Object']) | ||
} | ||
/** | ||
* Determines if an object is a valid Geometry Collection | ||
* @method isGeometryCollection | ||
* @param geometryCollection {Object} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isGeometryCollection = function(geometryCollection, cb){ | ||
let errors = [] | ||
if(!isObject(geometryCollection)){ | ||
return _done(cb, ['must be a JSON Object']); | ||
} | ||
if ('bbox' in feature) { | ||
exports.isBbox(feature.bbox, function (valid, err) { | ||
if (!valid) { | ||
errors = errors.concat(err) | ||
} | ||
}) | ||
} | ||
var errors = []; | ||
if ('type' in feature) { | ||
if (feature.type !== 'Feature') { | ||
errors.push('type must be "Feature"') | ||
} | ||
} else { | ||
errors.push('must have a member with the name "type"') | ||
} | ||
if('bbox' in geometryCollection){ | ||
exports.isBbox(geometryCollection.bbox, function(valid, err){ | ||
if(!valid){ | ||
errors = errors.concat(err); | ||
} | ||
}); | ||
} | ||
if (!('properties' in feature)) { | ||
errors.push('must have a member with the name "properties"') | ||
} | ||
if('type' in geometryCollection){ | ||
if(geometryCollection.type !== "GeometryCollection"){ | ||
errors.push("type must be 'GeometryCollection'"); | ||
} | ||
}else{ | ||
errors.push("must have a member with the name 'type'"); | ||
if ('geometry' in feature) { | ||
if (feature.geometry !== null) { | ||
exports.isGeometryObject(feature.geometry, function (valid, err) { | ||
if (!valid) { | ||
errors = errors.concat(err) | ||
} | ||
}) | ||
} | ||
} else { | ||
errors.push('must have a member with the name "geometry"') | ||
} | ||
if('geometries' in geometryCollection){ | ||
if(Array.isArray(geometryCollection.geometries)){ | ||
geometryCollection.geometries.forEach(function(val, index){ | ||
exports.isGeometryObject(val, function(valid, err){ | ||
if(!valid){ | ||
//modify the err msg from "isPosition" to note the element number | ||
err[0] = "at "+ index+ ": ".concat(err[0]); | ||
//build a list of invalide positions | ||
errors = errors.concat(err); | ||
} | ||
}); | ||
}); | ||
}else{ | ||
errors.push("'geometries' must be an array"); | ||
} | ||
}else{ | ||
errors.push("must have a member with the name 'geometries'"); | ||
} | ||
// run custom checks | ||
errors = errors.concat(_customDefinitions('Feature', feature)) | ||
//run custom checks | ||
errors = errors.concat(_customDefinitions("GeometryCollection", geometryCollection)); | ||
return _done(cb, errors) | ||
} | ||
return _done( cb, errors); | ||
}; | ||
/** | ||
* Determines if an object is a valid Feature Collection | ||
* @method isFeatureCollection | ||
* @param featureCollection {Object} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isFeatureCollection = function (featureCollection, cb) { | ||
if (!isObject(featureCollection)) { | ||
return _done(cb, ['must be a JSON Object']) | ||
} | ||
/** | ||
* Determines if an object is a valid Feature | ||
* @method isFeature | ||
* @param feature {Object} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isFeature = function(feature, cb){ | ||
let errors = [] | ||
if(!isObject(feature)){ | ||
return _done(cb, ['must be a JSON Object']); | ||
} | ||
if ('bbox' in featureCollection) { | ||
exports.isBbox(featureCollection.bbox, function (valid, err) { | ||
if (!valid) { | ||
errors = errors.concat(err) | ||
} | ||
}) | ||
} | ||
var errors = []; | ||
if ('type' in featureCollection) { | ||
if (featureCollection.type !== 'FeatureCollection') { | ||
errors.push('type must be "FeatureCollection"') | ||
} | ||
} else { | ||
errors.push('must have a member with the name "type"') | ||
} | ||
if('bbox' in feature){ | ||
exports.isBbox(feature.bbox, function(valid, err){ | ||
if(!valid){ | ||
errors = errors.concat(err); | ||
} | ||
}); | ||
} | ||
if ('features' in featureCollection) { | ||
if (Array.isArray(featureCollection.features)) { | ||
featureCollection.features.forEach(function (val, index) { | ||
exports.isFeature(val, function (valid, err) { | ||
if (!valid) { | ||
// modify the err msg from 'isPosition' to note the element number | ||
err[0] = 'at ' + index + ': '.concat(err[0]) | ||
// build a list of invalide positions | ||
errors = errors.concat(err) | ||
} | ||
}) | ||
}) | ||
} else { | ||
errors.push('"Features" must be an array') | ||
} | ||
} else { | ||
errors.push('must have a member with the name "Features"') | ||
} | ||
if('type' in feature){ | ||
if(feature.type !== "Feature"){ | ||
errors.push("type must be 'feature'"); | ||
} | ||
}else{ | ||
errors.push("must have a member with the name 'type'"); | ||
} | ||
// run custom checks | ||
errors = errors.concat(_customDefinitions('FeatureCollection', featureCollection)) | ||
if(!('properties' in feature)){ | ||
errors.push("must have a member with the name 'properties'"); | ||
} | ||
return _done(cb, errors) | ||
} | ||
if('geometry' in feature){ | ||
if(feature.geometry !== null){ | ||
exports.isGeometryObject(feature.geometry, function(valid, err){ | ||
if(!valid){ | ||
errors = errors.concat(err); | ||
} | ||
}); | ||
} | ||
}else{ | ||
errors.push("must have a member with the name 'geometry'"); | ||
} | ||
/** | ||
* Determines if an object is a valid Bounding Box | ||
* @method isBbox | ||
* @param bbox {Object} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isBbox = function (bbox, cb) { | ||
let errors = [] | ||
if (Array.isArray(bbox)) { | ||
if (bbox.length % 2 !== 0) { | ||
errors.push('bbox, must be a 2*n array') | ||
} | ||
} else { | ||
errors.push('bbox must be an array') | ||
} | ||
//run custom checks | ||
errors = errors.concat(_customDefinitions("Feature", feature)); | ||
// run custom checks | ||
errors = errors.concat(_customDefinitions('Bbox', bbox)) | ||
return _done(cb, errors); | ||
}; | ||
_done(cb, errors) | ||
} | ||
/** | ||
* Determines if an object is a valid Feature Collection | ||
* @method isFeatureCollection | ||
* @param featureCollection {Object} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isFeatureCollection = function(featureCollection, cb){ | ||
const nonGeoTypes = { | ||
'Feature': exports.isFeature, | ||
'FeatureCollection': exports.isFeatureCollection | ||
} | ||
if(!isObject(featureCollection)){ | ||
return _done(cb, ['must be a JSON Object']); | ||
} | ||
const geoTypes = { | ||
'Point': exports.isPoint, | ||
'MultiPoint': exports.isMultiPoint, | ||
'LineString': exports.isLineString, | ||
'MultiLineString': exports.isMultiLineString, | ||
'Polygon': exports.isPolygon, | ||
'MultiPolygon': exports.isMultiPolygon, | ||
'GeometryCollection': exports.isGeometryCollection | ||
} | ||
var errors = []; | ||
const allTypes = { | ||
'Feature': exports.isFeature, | ||
'FeatureCollection': exports.isFeatureCollection, | ||
'Point': exports.isPoint, | ||
'MultiPoint': exports.isMultiPoint, | ||
'LineString': exports.isLineString, | ||
'MultiLineString': exports.isMultiLineString, | ||
'Polygon': exports.isPolygon, | ||
'MultiPolygon': exports.isMultiPolygon, | ||
'GeometryCollection': exports.isGeometryCollection, | ||
'Bbox': exports.isBox, | ||
'Position': exports.isPosition, | ||
'GeoJSON': exports.isGeoJSONObject, | ||
'GeometryObject': exports.isGeometryObject | ||
} | ||
if('bbox' in featureCollection){ | ||
exports.isBbox(featureCollection.bbox, function(valid, err){ | ||
if(!valid){ | ||
errors = errors.concat(err); | ||
} | ||
}); | ||
} | ||
if('type' in featureCollection){ | ||
if(featureCollection.type !== "FeatureCollection"){ | ||
errors.push("type must be 'FeatureCollection'"); | ||
} | ||
}else{ | ||
errors.push("must have a member with the name 'type'"); | ||
} | ||
if('features' in featureCollection){ | ||
if(Array.isArray(featureCollection.features)){ | ||
featureCollection.features.forEach(function(val, index){ | ||
exports.isFeature(val, function(valid, err){ | ||
if(!valid){ | ||
//modify the err msg from "isPosition" to note the element number | ||
err[0] = "at "+ index+ ": ".concat(err[0]); | ||
//build a list of invalide positions | ||
errors = errors.concat(err); | ||
} | ||
}); | ||
}); | ||
}else{ | ||
errors.push("'features' must be an array"); | ||
} | ||
}else{ | ||
errors.push("must have a member with the name 'features'"); | ||
} | ||
//run custom checks | ||
errors = errors.concat(_customDefinitions("FeatureCollection", featureCollection)); | ||
return _done(cb, errors); | ||
}; | ||
/** | ||
* Determines if an object is a valid Bounding Box | ||
* @method isBbox | ||
* @param bbox {Object} | ||
* @param [cb] {Function} the callback | ||
* @return {Boolean} | ||
*/ | ||
exports.isBbox = function(bbox, cb){ | ||
var errors = []; | ||
if(Array.isArray(bbox)){ | ||
if(bbox.length % 2 !== 0){ | ||
errors.push("bbox, must be a 2*n array"); | ||
} | ||
}else{ | ||
errors.push("bbox must be an array"); | ||
} | ||
//run custom checks | ||
errors = errors.concat(_customDefinitions("Bbox", bbox)); | ||
_done(cb,errors); | ||
}; | ||
var non_geo_types = { | ||
"Feature": exports.isFeature, | ||
"FeatureCollection": exports.isFeatureCollection | ||
}, | ||
geo_types = { | ||
"Point": exports.isPoint, | ||
"MultiPoint": exports.isMultiPoint, | ||
"LineString": exports.isLineString, | ||
"MultiLineString": exports.isMultiLineString, | ||
"Polygon": exports.isPolygon, | ||
"MultiPolygon": exports.isMultiPolygon, | ||
"GeometryCollection": exports.isGeometryCollection, | ||
}, | ||
all_types = { | ||
"Feature": exports.isFeature, | ||
"FeatureCollection": exports.isFeatureCollection, | ||
"Point": exports.isPoint, | ||
"MultiPoint": exports.isMultiPoint, | ||
"LineString": exports.isLineString, | ||
"MultiLineString": exports.isMultiLineString, | ||
"Polygon": exports.isPolygon, | ||
"MultiPolygon": exports.isMultiPolygon, | ||
"GeometryCollection": exports.isGeometryCollection, | ||
"Bbox": exports.isBox, | ||
"Position": exports.isPosition, | ||
"GeoJSON": exports.isGeoJSONObject, | ||
"GeometryObject": exports.isGeometryObject | ||
}; | ||
exports.all_types = all_types; | ||
})(typeof exports === 'undefined'? this['GJV']={}: exports); | ||
exports.allTypes = allTypes |
{ | ||
"name": "geojson-validation", | ||
"version": "0.1.6", | ||
"version": "0.2.0", | ||
"description": "A GeoJSON Validation Library", | ||
@@ -10,3 +10,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"mocha": "~1.12.0" | ||
"mocha": "^4.0.1" | ||
}, | ||
@@ -13,0 +13,0 @@ "scripts": { |
1523
test/index.js
@@ -1,732 +0,959 @@ | ||
var assert = require("assert"), | ||
GSV = require("../index.js"); | ||
const assert = require('assert') | ||
const GSV = require('../index.js') | ||
describe('Positions', function() { | ||
describe('Positions', function () { | ||
it('must be a valid position object', function() { | ||
assert(GSV.isPosition([2,3])); | ||
}); | ||
it('must be a valid position object', function () { | ||
assert(GSV.isPosition([2, 3])) | ||
}) | ||
it('must be an array', function() { | ||
assert.equal(false, GSV.isPosition("adf")); | ||
}); | ||
it('must be a valid position object', function () { | ||
assert.equal(false, GSV.isPosition([null, null])) | ||
}) | ||
it('must be at least two elements', function() { | ||
assert.equal(false, GSV.isPosition([2])); | ||
}); | ||
}); | ||
it('must be an array', function () { | ||
assert.equal(false, GSV.isPosition("adf")) | ||
}) | ||
describe("GeoJSON Objects", function(){ | ||
it('must have a member with the name "type"', function() { | ||
gj = {"test": "1"}; | ||
assert.equal(false, GSV.isGeoJSONObject(gj)); | ||
}); | ||
it('must be at least two elements', function () { | ||
assert.equal(false, GSV.isPosition([2])) | ||
}) | ||
}) | ||
describe("type member", function(){ | ||
it('must be one of: "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", "GeometryCollection", "Feature", or "FeatureCollection"', function() { | ||
gj = {type: "point"}; | ||
assert.equal(false, GSV.isGeoJSONObject(gj)); | ||
}); | ||
}); | ||
describe("Geometry Objects", function(){ | ||
describe("GeoJSON Objects", function () { | ||
describe("type member", function(){ | ||
it('must be one of "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", or "GeometryCollection"', function() { | ||
gj = {type: "Feature"}; | ||
assert.equal(false, GSV.isGeometryObject(gj)); | ||
}); | ||
}); | ||
it('must have a member with the name "type"', function () { | ||
gj = { | ||
"test": "1" | ||
} | ||
assert.equal(false, GSV.isGeoJSONObject(gj)) | ||
}) | ||
describe("type member", function () { | ||
it('must be one of: "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", "GeometryCollection", "Feature", or "FeatureCollection"', function () { | ||
describe("Point", function(){ | ||
it('must be a valid Point Object', function() { | ||
gj = {type: "Point", coordinates: [2,3]}; | ||
assert(GSV.isPoint(gj)); | ||
}); | ||
gj = { | ||
type: "point" | ||
} | ||
assert.equal(false, GSV.isGeoJSONObject(gj)) | ||
}) | ||
}) | ||
it('member type must be "Point"', function() { | ||
gj = {type: "Polygon", coordinates: [2,3]}; | ||
assert.equal(false, GSV.isPoint(gj)); | ||
}); | ||
describe("Geometry Objects", function () { | ||
it('must have a member with the name "coordinates"', function(){ | ||
gj = {type: "Point", coordinate: [2,3]}; | ||
assert.equal(false, GSV.isPoint(gj)); | ||
}); | ||
describe("type member", function () { | ||
it('must be one of "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", or "GeometryCollection"', function () { | ||
describe("type coordinates", function(){ | ||
it('must be a single position', function() { | ||
gj = {type: "Point", coordinates: [2]}; | ||
assert.equal(false, GSV.isPoint(gj)); | ||
}); | ||
}); | ||
}); | ||
gj = { | ||
type: "Feature" | ||
} | ||
assert.equal(false, GSV.isGeometryObject(gj)) | ||
}) | ||
}) | ||
describe("MultiPoint", function(){ | ||
it('must be a valid MultiPoint Object', function() { | ||
gj = {type: "MultiPoint", coordinates: [[2,3],[5,6]]}; | ||
assert(GSV.isMultiPoint(gj)); | ||
}); | ||
it('member type must be "MultiPoint"', function() { | ||
gj = {type: "Point", coordinates: [[2,3],[5,6]]}; | ||
assert.equal(false, GSV.isMultiPoint(gj)); | ||
}); | ||
describe("Point", function () { | ||
it('must be a valid Point Object', function () { | ||
gj = { | ||
type: "Point", | ||
coordinates: [2, 3] | ||
} | ||
assert(GSV.isPoint(gj)) | ||
}) | ||
it('must have a member with the name "coordinates"', function(){ | ||
gj = {type: "MultiPoint", coordinate: [2,3]}; | ||
assert.equal(false, GSV.isPoint(gj)); | ||
}); | ||
it('member type must be "Point"', function () { | ||
gj = { | ||
type: "Polygon", | ||
coordinates: [2, 3] | ||
} | ||
assert.equal(false, GSV.isPoint(gj)) | ||
}) | ||
describe("type coordinates", function(){ | ||
it('must be an array of positions', function() { | ||
gj = {type: "MultiPoint", coordinates: [[2,3],[5]]}; | ||
assert.equal(false, GSV.isMultiPoint(gj)); | ||
}); | ||
}); | ||
}); | ||
it('must have a member with the name "coordinates"', function () { | ||
gj = { | ||
type: "Point", | ||
coordinate: [2, 3] | ||
} | ||
assert.equal(false, GSV.isPoint(gj)) | ||
}) | ||
describe("Linestring", function(){ | ||
describe("type coordinates", function () { | ||
it('must be a single position', function () { | ||
gj = { | ||
type: "Point", | ||
coordinates: [2] | ||
} | ||
assert.equal(false, GSV.isPoint(gj)) | ||
}) | ||
}) | ||
}) | ||
it('must be a valid LineString Object', function() { | ||
var ValidLineString = { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0] | ||
] | ||
}; | ||
assert(GSV.isLineString(ValidLineString)); | ||
}); | ||
describe("MultiPoint", function () { | ||
it('must be a valid MultiPoint Object', function () { | ||
gj = { | ||
type: "MultiPoint", | ||
coordinates: [ | ||
[2, 3], | ||
[5, 6] | ||
] | ||
} | ||
assert(GSV.isMultiPoint(gj)) | ||
}) | ||
it('member type must be "LineString"', function() { | ||
gj = {type: "lineString", coordinates: [[2,3],[5,6]]}; | ||
assert.equal(false, GSV.isLineString(gj)); | ||
}); | ||
it('member type must be "MultiPoint"', function () { | ||
gj = { | ||
type: "Point", | ||
coordinates: [ | ||
[2, 3], | ||
[5, 6] | ||
] | ||
} | ||
assert.equal(false, GSV.isMultiPoint(gj)) | ||
}) | ||
it('must have a member with the name "coordinates"', function(){ | ||
gj = {type: "LineString", coordinate: [[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]]}; | ||
assert.equal(false, GSV.isLineString(gj)); | ||
}); | ||
it('must have a member with the name "coordinates"', function () { | ||
gj = { | ||
type: "MultiPoint", | ||
coordinate: [2, 3] | ||
} | ||
assert.equal(false, GSV.isPoint(gj)) | ||
}) | ||
describe("type coordinates", function(){ | ||
it('must be an array of positions', function() { | ||
gj = {type: "LineString", coordinate: [[2,3],[5]]}; | ||
assert.equal(false, GSV.isLineString(gj)); | ||
}); | ||
describe("type coordinates", function () { | ||
it('must be an array of positions', function () { | ||
gj = { | ||
type: "MultiPoint", | ||
coordinates: [ | ||
[2, 3], | ||
[5] | ||
] | ||
} | ||
assert.equal(false, GSV.isMultiPoint(gj)) | ||
}) | ||
}) | ||
}) | ||
it('must be at least two elements', function() { | ||
gj = {type: "LineString", coordinates: [[2,3]]}; | ||
assert.equal(false, GSV.isLineString(gj)); | ||
}); | ||
}); | ||
}); | ||
describe("Linestring", function () { | ||
describe("MutliLineString", function(){ | ||
it('must be a valid LineString Object', function () { | ||
var ValidLineString = { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[102.0, 0.0], | ||
[103.0, 1.0], | ||
[104.0, 0.0], | ||
[105.0, 1.0] | ||
] | ||
} | ||
assert(GSV.isLineString(ValidLineString)) | ||
}) | ||
it('must be a valid MutiLineString Object', function() { | ||
var validMutlineString = { | ||
"type": "MultiLineString", | ||
"coordinates": [ | ||
[ [100.0, 0.0], [101.0, 1.0] ], | ||
[ [102.0, 2.0], [103.0, 3.0] ] | ||
] | ||
}; | ||
assert(GSV.isMultiLineString(validMutlineString)); | ||
}); | ||
it('member type must be "LineString"', function () { | ||
gj = { | ||
type: "lineString", | ||
coordinates: [ | ||
[2, 3], | ||
[5, 6] | ||
] | ||
} | ||
assert.equal(false, GSV.isLineString(gj)) | ||
}) | ||
it('member type must be "MutliLineString"', function() { | ||
it('must have a member with the name "coordinates"', function () { | ||
gj = { | ||
type: "LineString", | ||
coordinate: [ | ||
[102.0, 0.0], | ||
[103.0, 1.0], | ||
[104.0, 0.0], | ||
[105.0, 1.0] | ||
] | ||
} | ||
assert.equal(false, GSV.isLineString(gj)) | ||
}) | ||
var invalidMutlineString = { | ||
"type": "multiLineString", | ||
"coordinates": [ | ||
[ [100.0, 0.0], [101.0, 1.0] ], | ||
[ [102.0, 2.0], [103.0, 3.0] ] | ||
] | ||
}; | ||
assert.equal(false, GSV.isMultiLineString(invalidMutlineString)); | ||
}); | ||
describe("type coordinates", function () { | ||
it('must be an array of positions', function () { | ||
gj = { | ||
type: "LineString", | ||
coordinate: [ | ||
[2, 3], | ||
[5] | ||
] | ||
} | ||
assert.equal(false, GSV.isLineString(gj)) | ||
}) | ||
it('must have a member with the name "coordinates"', function(){ | ||
it('must be at least two elements', function () { | ||
gj = { | ||
type: "LineString", | ||
coordinates: [ | ||
[2, 3] | ||
] | ||
} | ||
assert.equal(false, GSV.isLineString(gj)) | ||
}) | ||
}) | ||
}) | ||
var invalidMutlineString = { | ||
"type": "MultiLineString", | ||
"coordinate": [ | ||
[ [100.0, 0.0], [101.0, 1.0] ], | ||
[ [102.0, 2.0], [103.0, 3.0] ] | ||
] | ||
}; | ||
describe("MutliLineString", function () { | ||
assert.equal(false, GSV.isMultiLineString(invalidMutlineString)); | ||
}); | ||
it('must be a valid MutiLineString Object', function () { | ||
var validMutlineString = { | ||
"type": "MultiLineString", | ||
"coordinates": [ | ||
[ | ||
[100.0, 0.0], | ||
[101.0, 1.0] | ||
], | ||
[ | ||
[102.0, 2.0], | ||
[103.0, 3.0] | ||
] | ||
] | ||
} | ||
assert(GSV.isMultiLineString(validMutlineString)) | ||
}) | ||
describe("type coordinates", function(){ | ||
it('must be an array of LineString coordinate arrays', function() { | ||
var invalidMutlineString = { | ||
"type": "MultiLineString", | ||
"coordinate": [ | ||
[ [100.0, 0.0], [101.0] ], | ||
[ [102.0, 2.0], [103.0, 3.0] ] | ||
] | ||
}; | ||
it('member type must be "MutliLineString"', function () { | ||
assert.equal(false, GSV.isMultiLineString(invalidMutlineString)); | ||
}); | ||
}); | ||
}); | ||
var invalidMutlineString = { | ||
"type": "multiLineString", | ||
"coordinates": [ | ||
[ | ||
[100.0, 0.0], | ||
[101.0, 1.0] | ||
], | ||
[ | ||
[102.0, 2.0], | ||
[103.0, 3.0] | ||
] | ||
] | ||
} | ||
assert.equal(false, GSV.isMultiLineString(invalidMutlineString)) | ||
}) | ||
describe('Polygon', function() { | ||
it('must be a valid Polygon Object', function() { | ||
var validPolygon = { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ] | ||
] | ||
}; | ||
assert(GSV.isPolygon(validPolygon)); | ||
}); | ||
it('must have a member with the name "coordinates"', function () { | ||
it('member type must be "Polygon"', function() { | ||
var invalidMutlineString = { | ||
"type": "MultiLineString", | ||
"coordinate": [ | ||
[ | ||
[100.0, 0.0], | ||
[101.0, 1.0] | ||
], | ||
[ | ||
[102.0, 2.0], | ||
[103.0, 3.0] | ||
] | ||
] | ||
} | ||
var invalidPolygon = { | ||
"type": "polygon", | ||
"coordinates": [ | ||
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ] | ||
] | ||
}; | ||
assert.equal(false, GSV.isPolygon(invalidPolygon)); | ||
}); | ||
assert.equal(false, GSV.isMultiLineString(invalidMutlineString)) | ||
}) | ||
it('must have a member with the name "coordinates"', function(){ | ||
var invalidPolygon = { | ||
"type": "Polygon", | ||
"coordinate": [ | ||
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ] | ||
] | ||
}; | ||
assert.equal(false, GSV.isPolygon(invalidPolygon)); | ||
}); | ||
describe("type coordinates", function () { | ||
it('must be an array of LineString coordinate arrays', function () { | ||
describe("type coordinates", function(){ | ||
it('must be an array of LinearRing coordinate arrays', function() { | ||
var invalidPolygon = { | ||
"type": "Polygon", | ||
"coordinates": "test" | ||
}; | ||
assert.equal(false, GSV.isPolygon(invalidPolygon)); | ||
}); | ||
var invalidMutlineString = { | ||
"type": "MultiLineString", | ||
"coordinate": [ | ||
[ | ||
[100.0, 0.0], | ||
[101.0] | ||
], | ||
[ | ||
[102.0, 2.0], | ||
[103.0, 3.0] | ||
] | ||
] | ||
} | ||
describe('LinearRing', function() { | ||
it('must be a LineString with 4 or more positions', function() { | ||
var invalidPolygon = { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ], | ||
[ [100.0, 0.0], [100.0, 1.0], [100.0, 0.0] ] | ||
] | ||
}; | ||
assert.equal(false, GSV.isPolygon(invalidPolygon)); | ||
}); | ||
assert.equal(false, GSV.isMultiLineString(invalidMutlineString)) | ||
}) | ||
}) | ||
}) | ||
it('The first and last positions must be equivalent (represent equivalent points)', function() { | ||
var invalidPolygon = { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ [100.0, 1.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ] | ||
] | ||
}; | ||
assert.equal(false, GSV.isPolygon(invalidPolygon)); | ||
describe('Polygon', function () { | ||
it('must be a valid Polygon Object', function () { | ||
var validPolygon = { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[100.0, 0.0], | ||
[101.0, 0.0], | ||
[101.0, 1.0], | ||
[100.0, 1.0], | ||
[100.0, 0.0] | ||
] | ||
] | ||
} | ||
assert(GSV.isPolygon(validPolygon)) | ||
}) | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('member type must be "Polygon"', function () { | ||
describe('MultiPolygon', function() { | ||
var invalidPolygon = { | ||
"type": "polygon", | ||
"coordinates": [ | ||
[ | ||
[100.0, 0.0], | ||
[101.0, 0.0], | ||
[101.0, 1.0], | ||
[100.0, 1.0], | ||
[100.0, 0.0] | ||
] | ||
] | ||
} | ||
assert.equal(false, GSV.isPolygon(invalidPolygon)) | ||
}) | ||
it('must be a valid MultiPolygon object', function() { | ||
var validMultiPolygon = { | ||
"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.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]] | ||
] | ||
}; | ||
assert(GSV.isMultiPolygon(validMultiPolygon)); | ||
}); | ||
it('must have a member with the name "coordinates"', function () { | ||
var invalidPolygon = { | ||
"type": "Polygon", | ||
"coordinate": [ | ||
[ | ||
[100.0, 0.0], | ||
[101.0, 0.0], | ||
[101.0, 1.0], | ||
[100.0, 1.0], | ||
[100.0, 0.0] | ||
] | ||
] | ||
} | ||
assert.equal(false, GSV.isPolygon(invalidPolygon)) | ||
}) | ||
it('member type must be "MultiPolygon"', function() { | ||
describe("type coordinates", function () { | ||
it('must be an array of LinearRing coordinate arrays', function () { | ||
var invalidPolygon = { | ||
"type": "Polygon", | ||
"coordinates": "test" | ||
} | ||
assert.equal(false, GSV.isPolygon(invalidPolygon)) | ||
}) | ||
var invalidMultiPolygon = { | ||
"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.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]] | ||
] | ||
}; | ||
describe('LinearRing', function () { | ||
it('must be a LineString with 4 or more positions', function () { | ||
var invalidPolygon = { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[100.0, 0.0], | ||
[101.0, 0.0], | ||
[101.0, 1.0], | ||
[100.0, 1.0], | ||
[100.0, 0.0] | ||
], | ||
[ | ||
[100.0, 0.0], | ||
[100.0, 1.0], | ||
[100.0, 0.0] | ||
] | ||
] | ||
} | ||
assert.equal(false, GSV.isPolygon(invalidPolygon)) | ||
}) | ||
assert.equal(false, GSV.isMultiPolygon(invalidMultiPolygon)); | ||
}); | ||
it('The first and last positions must be equivalent (represent equivalent points)', function () { | ||
var invalidPolygon = { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[100.0, 1.0], | ||
[101.0, 0.0], | ||
[101.0, 1.0], | ||
[100.0, 1.0], | ||
[100.0, 0.0] | ||
] | ||
] | ||
} | ||
assert.equal(false, GSV.isPolygon(invalidPolygon)) | ||
it('must have a member with the name "coordinates"', function(){ | ||
}) | ||
}) | ||
}) | ||
}) | ||
var invalidMultiPolygon = { | ||
"type": "MultiPolygon", | ||
"coordinate": [ | ||
[[[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.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]] | ||
] | ||
}; | ||
describe('MultiPolygon', function () { | ||
assert.equal(false, GSV.isMultiPolygon(invalidMultiPolygon)); | ||
}); | ||
it('must be a valid MultiPolygon object', function () { | ||
var validMultiPolygon = { | ||
"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.8, 0.2], | ||
[100.8, 0.8], | ||
[100.2, 0.8], | ||
[100.2, 0.2] | ||
] | ||
] | ||
] | ||
} | ||
assert(GSV.isMultiPolygon(validMultiPolygon)) | ||
}) | ||
describe("type coordinates", function(){ | ||
it('must be an array of Polygon coordinate arrays', function() { | ||
it('member type must be "MultiPolygon"', function () { | ||
var invalidMultiPolygon = { | ||
"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], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0]], | ||
[[100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2]]] | ||
] | ||
}; | ||
var invalidMultiPolygon = { | ||
"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.8, 0.2], | ||
[100.8, 0.8], | ||
[100.2, 0.8], | ||
[100.2, 0.2] | ||
] | ||
] | ||
] | ||
} | ||
assert.equal(false, GSV.isMultiPolygon(invalidMultiPolygon)); | ||
}); | ||
}); | ||
}); | ||
assert.equal(false, GSV.isMultiPolygon(invalidMultiPolygon)) | ||
}) | ||
describe('Geometry Collection', function() { | ||
it('must have a member with the name "coordinates"', function () { | ||
it('must be a valid Geometry Collection Object', function() { | ||
var validGeoCollection = { | ||
"type": "GeometryCollection", | ||
"geometries": [ | ||
{ | ||
"type": "Point", | ||
"coordinates": [100.0, 0.0] | ||
}, | ||
{ | ||
"type": "LineString", | ||
"coordinates": [ [101.0, 0.0], [102.0, 1.0] ] | ||
} | ||
] | ||
}; | ||
assert(GSV.isGeometryCollection(validGeoCollection)); | ||
}); | ||
var invalidMultiPolygon = { | ||
"type": "MultiPolygon", | ||
"coordinate": [ | ||
[ | ||
[ | ||
[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.8, 0.2], | ||
[100.8, 0.8], | ||
[100.2, 0.8], | ||
[100.2, 0.2] | ||
] | ||
] | ||
] | ||
} | ||
it('member type must be "GeometryCollection"', function() { | ||
var invalidGeoCollection = { | ||
"type": "geometryCollection", | ||
"geometries": [ | ||
{ | ||
"type": "Point", | ||
"coordinates": [100.0, 0.0] | ||
}, | ||
{ | ||
"type": "LineString", | ||
"coordinates": [ [101.0, 0.0], [102.0, 1.0] ] | ||
} | ||
] | ||
}; | ||
assert.equal(false, GSV.isGeometryCollection(invalidGeoCollection)); | ||
}); | ||
assert.equal(false, GSV.isMultiPolygon(invalidMultiPolygon)) | ||
}) | ||
it('must have a member with the name "geometries"', function() { | ||
var invalidGeoCollection = { | ||
"type": "GeometryCollection", | ||
"geometrie": [ | ||
{ | ||
"type": "Point", | ||
"coordinates": [100.0, 0.0] | ||
}, | ||
{ | ||
"type": "LineString", | ||
"coordinates": [ [101.0, 0.0], [102.0, 1.0] ] | ||
} | ||
] | ||
}; | ||
assert.equal(false, GSV.isGeometryCollection(invalidGeoCollection)); | ||
}); | ||
describe("type coordinates", function () { | ||
it('must be an array of Polygon coordinate arrays', function () { | ||
describe('geometries', function() { | ||
it('must be an array of GeoJSON geometry object', function() { | ||
var invalidGeoCollection = { | ||
"type": "GeometryCollection", | ||
"geometries": [ | ||
{ | ||
"type": "Point", | ||
"coordinates": [100.0, 0.0] | ||
}, | ||
{ | ||
"type": "LineString", | ||
"coordinates": [ [101.0], [102.0, 1.0] ] | ||
} | ||
] | ||
}; | ||
var invalidMultiPolygon = { | ||
"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], | ||
[101.0, 1.0], | ||
[100.0, 1.0], | ||
[100.0, 0.0] | ||
], | ||
[ | ||
[100.2, 0.2], | ||
[100.8, 0.2], | ||
[100.8, 0.8], | ||
[100.2, 0.8], | ||
[100.2, 0.2] | ||
] | ||
] | ||
] | ||
} | ||
assert.equal(false, GSV.isGeometryCollection(invalidGeoCollection)); | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('Feature Objects', function() { | ||
assert.equal(false, GSV.isMultiPolygon(invalidMultiPolygon)) | ||
}) | ||
}) | ||
}) | ||
describe('Geometry Collection', function () { | ||
it('must be a valid Feature Object', function() { | ||
var validFeature = { | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": 0.0 | ||
} | ||
}; | ||
it('must be a valid Geometry Collection Object', function () { | ||
var validGeoCollection = { | ||
"type": "GeometryCollection", | ||
"geometries": [{ | ||
"type": "Point", | ||
"coordinates": [100.0, 0.0] | ||
}, { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[101.0, 0.0], | ||
[102.0, 1.0] | ||
] | ||
}] | ||
} | ||
assert(GSV.isGeometryCollection(validGeoCollection)) | ||
}) | ||
assert(GSV.isFeature(validFeature)); | ||
}); | ||
it('member type must be "GeometryCollection"', function () { | ||
var invalidGeoCollection = { | ||
"type": "geometryCollection", | ||
"geometries": [{ | ||
"type": "Point", | ||
"coordinates": [100.0, 0.0] | ||
}, { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[101.0, 0.0], | ||
[102.0, 1.0] | ||
] | ||
}] | ||
} | ||
assert.equal(false, GSV.isGeometryCollection(invalidGeoCollection)) | ||
}) | ||
it('member type must be "Feature"', function() { | ||
it('must have a member with the name "geometries"', function () { | ||
var invalidGeoCollection = { | ||
"type": "GeometryCollection", | ||
"geometrie": [{ | ||
"type": "Point", | ||
"coordinates": [100.0, 0.0] | ||
}, { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[101.0, 0.0], | ||
[102.0, 1.0] | ||
] | ||
}] | ||
} | ||
assert.equal(false, GSV.isGeometryCollection(invalidGeoCollection)) | ||
}) | ||
var invalidFeature = { | ||
"type": "feature", | ||
"geometry": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": 0.0 | ||
} | ||
}; | ||
assert.equal(false, GSV.isFeature(invalidFeature)); | ||
}); | ||
describe('geometries', function () { | ||
it('must be an array of GeoJSON geometry object', function () { | ||
it('must have a member with the name "geometry"', function() { | ||
var invalidFeature = { | ||
"type": "Feature", | ||
"geometr": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": 0.0 | ||
} | ||
}; | ||
assert.equal(false, GSV.isFeature(invalidFeature)); | ||
}); | ||
var invalidGeoCollection = { | ||
"type": "GeometryCollection", | ||
"geometries": [{ | ||
"type": "Point", | ||
"coordinates": [100.0, 0.0] | ||
}, { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[101.0], | ||
[102.0, 1.0] | ||
] | ||
}] | ||
} | ||
describe('geometry member', function() { | ||
it('must be a geometry object or a JSON null value', function() { | ||
var invalidFeature = { | ||
"type": "Feature", | ||
"geometr": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[102.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": 0.0 | ||
} | ||
}; | ||
assert.equal(false, GSV.isFeature(invalidFeature)) | ||
}); | ||
}); | ||
assert.equal(false, GSV.isGeometryCollection(invalidGeoCollection)) | ||
}) | ||
}) | ||
}) | ||
}) | ||
it('must have a member "properties"', function() { | ||
var invalidFeature = { | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0] | ||
] | ||
}, | ||
"propertie": { | ||
"prop0": "value0", | ||
"prop1": 0.0 | ||
} | ||
}; | ||
assert.equal(false, GSV.isFeature(invalidFeature)); | ||
}); | ||
}); | ||
describe('Feature Objects', function () { | ||
describe('Feature Collection Objects', function() { | ||
it('must be a valid Feature Collection Object', function() { | ||
var validFeatureCollection = { | ||
"type": "FeatureCollection", | ||
"features": [ | ||
{ | ||
"type": "Feature", | ||
"geometry": {"type": "Point", "coordinates": [102.0, 0.5]}, | ||
"properties": {"prop0": "value0"} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": 0.0 | ||
} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], | ||
[100.0, 1.0], [100.0, 0.0] ] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": {"this": "that"} | ||
} | ||
} | ||
] | ||
}; | ||
assert(GSV.isFeatureCollection(validFeatureCollection)); | ||
}); | ||
it('member type must be "FeatureCollection"', function() { | ||
var invalidFeatureCollection = { | ||
"type": "featureCollection", | ||
"features": [ | ||
{ | ||
"type": "Feature", | ||
"geometry": {"type": "Point", "coordinates": [102.0, 0.5]}, | ||
"properties": {"prop0": "value0"} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": 0.0 | ||
} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], | ||
[100.0, 1.0], [100.0, 0.0] ] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": {"this": "that"} | ||
} | ||
} | ||
] | ||
}; | ||
assert.equal(false, GSV.isFeatureCollection(invalidFeatureCollection)); | ||
}); | ||
it('must be a valid Feature Object', function () { | ||
var validFeature = { | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[102.0, 0.0], | ||
[103.0, 1.0], | ||
[104.0, 0.0], | ||
[105.0, 1.0] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": 0.0 | ||
} | ||
} | ||
it('must have a member with the name "features"', function() { | ||
var invalidFeatureCollection = { | ||
"type": "FeatureCollection", | ||
"feature": [ | ||
{ | ||
"type": "Feature", | ||
"geometry": {"type": "Point", "coordinates": [102.0, 0.5]}, | ||
"properties": {"prop0": "value0"} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": 0.0 | ||
} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], | ||
[100.0, 1.0], [100.0, 0.0] ] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": {"this": "that"} | ||
} | ||
} | ||
] | ||
}; | ||
assert.equal(false, GSV.isFeatureCollection(invalidFeatureCollection)); | ||
}); | ||
assert(GSV.isFeature(validFeature)) | ||
}) | ||
describe('member features', function() { | ||
it('must have an array of feature objects', function() { | ||
var invalidFeatureCollection = { | ||
"type": "FeatureCollection", | ||
"features": [ | ||
{ | ||
"type": "Feature", | ||
"geometry": {"type": "Point", "coordinates": [102.0, 0.5]}, | ||
"properties": {"prop0": "value0"} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[102.0, 0.0], [103.0, 1.0], [ 0.0], [105.0, 1.0] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": 0.0 | ||
} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], | ||
[100.0, 1.0], [100.0, 0.0] ] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": {"this": "that"} | ||
} | ||
} | ||
] | ||
}; | ||
assert.equal(false, GSV.isFeatureCollection(invalidFeatureCollection)); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('member type must be "Feature"', function () { | ||
/* | ||
describe('Coordinate Reference System Objects', function() { | ||
it('must be a member named "crs"', function() { | ||
}); | ||
var invalidFeature = { | ||
"type": "feature", | ||
"geometry": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[102.0, 0.0], | ||
[103.0, 1.0], | ||
[104.0, 0.0], | ||
[105.0, 1.0] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": 0.0 | ||
} | ||
} | ||
assert.equal(false, GSV.isFeature(invalidFeature)) | ||
}) | ||
describe('Named CRS', function() { | ||
it('member type must be "name"', function() { | ||
}); | ||
it('must have a member with the name "geometry"', function () { | ||
var invalidFeature = { | ||
"type": "Feature", | ||
"geometr": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[102.0, 0.0], | ||
[103.0, 1.0], | ||
[104.0, 0.0], | ||
[105.0, 1.0] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": 0.0 | ||
} | ||
} | ||
assert.equal(false, GSV.isFeature(invalidFeature)) | ||
}) | ||
it('member properties must be an object containing a "name" member', function() { | ||
}); | ||
describe('geometry member', function () { | ||
it('must be a geometry object or a JSON null value', function () { | ||
var invalidFeature = { | ||
"type": "Feature", | ||
"geometr": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[102.0], | ||
[103.0, 1.0], | ||
[104.0, 0.0], | ||
[105.0, 1.0] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": 0.0 | ||
} | ||
} | ||
assert.equal(false, GSV.isFeature(invalidFeature)) | ||
}) | ||
}) | ||
describe('member properties', function() { | ||
it('memeber "name" must be a string', function() { | ||
}); | ||
}); | ||
}); | ||
it('must have a member "properties"', function () { | ||
var invalidFeature = { | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[102.0, 0.0], | ||
[103.0, 1.0], | ||
[104.0, 0.0], | ||
[105.0, 1.0] | ||
] | ||
}, | ||
"propertie": { | ||
"prop0": "value0", | ||
"prop1": 0.0 | ||
} | ||
} | ||
assert.equal(false, GSV.isFeature(invalidFeature)) | ||
}) | ||
}) | ||
describe('Linked CRS', function() { | ||
describe('Feature Collection Objects', function () { | ||
it('member type must be "link"', function() { | ||
}); | ||
it('must be a valid Feature Collection Object', function () { | ||
var validFeatureCollection = { | ||
"type": "FeatureCollection", | ||
"features": [{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [102.0, 0.5] | ||
}, | ||
"properties": { | ||
"prop0": "value0" | ||
} | ||
}, { | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[102.0, 0.0], | ||
[103.0, 1.0], | ||
[104.0, 0.0], | ||
[105.0, 1.0] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": 0.0 | ||
} | ||
}, { | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[100.0, 0.0], | ||
[101.0, 0.0], | ||
[101.0, 1.0], | ||
[100.0, 1.0], | ||
[100.0, 0.0] | ||
] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": { | ||
"this": "that" | ||
} | ||
} | ||
}] | ||
} | ||
assert(GSV.isFeatureCollection(validFeatureCollection)) | ||
}) | ||
it('member properties must be a Link objec', function() { | ||
}); | ||
it('member type must be "FeatureCollection"', function () { | ||
describe('Link Objects', function() { | ||
it('member "href" must be a dereferenceable URI.', function() { | ||
}); | ||
describe('member type', function() { | ||
var invalidFeatureCollection = { | ||
"type": "featureCollection", | ||
"features": [{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [102.0, 0.5] | ||
}, | ||
"properties": { | ||
"prop0": "value0" | ||
} | ||
}, { | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[102.0, 0.0], | ||
[103.0, 1.0], | ||
[104.0, 0.0], | ||
[105.0, 1.0] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": 0.0 | ||
} | ||
}, { | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[100.0, 0.0], | ||
[101.0, 0.0], | ||
[101.0, 1.0], | ||
[100.0, 1.0], | ||
[100.0, 0.0] | ||
] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": { | ||
"this": "that" | ||
} | ||
} | ||
}] | ||
} | ||
assert.equal(false, GSV.isFeatureCollection(invalidFeatureCollection)) | ||
}) | ||
it('must be a string', function() { | ||
}); | ||
}); | ||
it('must have a member with the name "features"', function () { | ||
var invalidFeatureCollection = { | ||
"type": "FeatureCollection", | ||
"feature": [{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [102.0, 0.5] | ||
}, | ||
"properties": { | ||
"prop0": "value0" | ||
} | ||
}, { | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[102.0, 0.0], | ||
[103.0, 1.0], | ||
[104.0, 0.0], | ||
[105.0, 1.0] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": 0.0 | ||
} | ||
}, { | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[100.0, 0.0], | ||
[101.0, 0.0], | ||
[101.0, 1.0], | ||
[100.0, 1.0], | ||
[100.0, 0.0] | ||
] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": { | ||
"this": "that" | ||
} | ||
} | ||
}] | ||
} | ||
assert.equal(false, GSV.isFeatureCollection(invalidFeatureCollection)) | ||
}) | ||
}); | ||
}); | ||
}); | ||
*/ | ||
describe('member features', function () { | ||
it('must have an array of feature objects', function () { | ||
var invalidFeatureCollection = { | ||
"type": "FeatureCollection", | ||
"features": [{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [102.0, 0.5] | ||
}, | ||
"properties": { | ||
"prop0": "value0" | ||
} | ||
}, { | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "LineString", | ||
"coordinates": [ | ||
[102.0, 0.0], | ||
[103.0, 1.0], | ||
[0.0], | ||
[105.0, 1.0] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": 0.0 | ||
} | ||
}, { | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[100.0, 0.0], | ||
[101.0, 0.0], | ||
[101.0, 1.0], | ||
[100.0, 1.0], | ||
[100.0, 0.0] | ||
] | ||
] | ||
}, | ||
"properties": { | ||
"prop0": "value0", | ||
"prop1": { | ||
"this": "that" | ||
} | ||
} | ||
}] | ||
} | ||
assert.equal(false, GSV.isFeatureCollection(invalidFeatureCollection)) | ||
}) | ||
}) | ||
}) | ||
}) | ||
describe('Bounding Boxes', function() { | ||
it('must be a member named "bbox"', function() { | ||
}); | ||
describe('Bounding Boxes', function () { | ||
it('bbox member must be a 2*n array', function() { | ||
}); | ||
}); | ||
it('must be a member named "bbox"', function () { | ||
describe('Custom Checks', function(){ | ||
it("must only functions", function(){ | ||
}); | ||
}) | ||
it('must check on the described element', function() { | ||
GSV.define("Position", function(position){ | ||
errors = []; | ||
if(position[0] < -180 || position[0] > 180){ | ||
errors.push("the x must be between -180 and 180"); | ||
} | ||
if(position[1] < -90 || position[1] > 90){ | ||
errors.push("the y must be between -90 and 90"); | ||
} | ||
return errors; | ||
}); | ||
it('bbox member must be a 2*n array', function () { | ||
gj = {type: "Point", coordinates: [-200,3]}; | ||
assert.equal(false, GSV.isPoint(gj)); | ||
}) | ||
}) | ||
}); | ||
}); | ||
describe('Custom Checks', function () { | ||
it("must only functions", function () { | ||
}) | ||
it('must check on the described element', function () { | ||
GSV.define("Position", function (position) { | ||
errors = [] | ||
if (position[0] < -180 || position[0] > 180) { | ||
errors.push("the x must be between -180 and 180") | ||
} | ||
if (position[1] < -90 || position[1] > 90) { | ||
errors.push("the y must be between -90 and 90") | ||
} | ||
return errors | ||
}) | ||
gj = { | ||
type: "Point", | ||
coordinates: [-200, 3] | ||
} | ||
assert.equal(false, GSV.isPoint(gj)) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1633
63042
6
1