├── .github └── workflows │ ├── deploy.yml │ └── test.yml ├── .gitignore ├── Makefile ├── bin ├── format.js └── transform-package-json.js ├── license.md ├── package-lock.json ├── package.json ├── readme.md ├── src └── schema │ ├── Feature.js │ ├── FeatureCollection.js │ ├── GeoJSON.js │ ├── Geometry.js │ ├── GeometryCollection.js │ ├── LineString.js │ ├── MultiLineString.js │ ├── MultiPoint.js │ ├── MultiPolygon.js │ ├── Point.js │ ├── Polygon.js │ └── ref │ ├── BoundingBox.js │ ├── LineStringCoordinates.js │ ├── LinearRingCoordinates.js │ ├── PointCoordinates.js │ └── PolygonCoordinates.js └── test ├── assert.js ├── fixtures ├── invalid │ ├── feature │ │ ├── 1d-point.json │ │ ├── boolean-id.json │ │ ├── no-geometry.json │ │ ├── no-properties.json │ │ ├── no-type.json │ │ └── object-id.json │ ├── featurecollection │ │ ├── no-features.json │ │ └── no-type.json │ ├── geometrycollection │ │ ├── 1d.json │ │ ├── bad-geometry.json │ │ ├── no-geometries.json │ │ └── no-type.json │ ├── linestring │ │ ├── 1d.json │ │ ├── bad-bbox.json │ │ ├── no-coordinates.json │ │ └── no-type.json │ ├── multilinestring │ │ ├── 1d.json │ │ ├── bad-bbox.json │ │ ├── no-coordinates.json │ │ └── no-type.json │ ├── multipoint │ │ ├── 1d.json │ │ ├── bad-bbox.json │ │ ├── no-coordinates.json │ │ └── no-type.json │ ├── multipolygon │ │ ├── 1d.json │ │ ├── bad-bbox.json │ │ ├── no-coordinates.json │ │ └── no-type.json │ ├── point │ │ ├── 1d.json │ │ ├── bad-bbox.json │ │ ├── no-coordinates.json │ │ └── no-type.json │ └── polygon │ │ ├── 1d.json │ │ ├── bad-type.json │ │ ├── no-coordinates.json │ │ └── no-type.json └── valid │ ├── feature │ ├── basic.json │ ├── empty-polygon.json │ ├── null-geometry.json │ ├── with-number-id.json │ └── with-string-id.json │ ├── featurecollection │ ├── basic.json │ └── empty.json │ ├── geometrycollection │ ├── 3d.json │ ├── basic.json │ └── bbox.json │ ├── linestring │ ├── 3d.json │ ├── basic.json │ └── bbox.json │ ├── multilinestring │ ├── 3d.json │ ├── basic.json │ └── bbox.json │ ├── multipoint │ ├── 3d.json │ ├── basic.json │ └── bbox.json │ ├── multipolygon │ ├── 3d.json │ ├── basic.json │ └── bbox.json │ ├── point │ ├── 3d.json │ ├── basic.json │ ├── bbox.json │ └── extended.json │ └── polygon │ ├── 3d.json │ ├── basic.json │ ├── bbox.json │ └── extended.json └── test.js /.github/workflows/deploy.yml: -------------------------------------------------------------------------------- 1 | name: Deploy to GitHub Pages 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | workflow_dispatch: 8 | 9 | permissions: 10 | contents: read 11 | pages: write 12 | id-token: write 13 | 14 | jobs: 15 | build: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - name: Clone Repository 19 | uses: actions/checkout@v4 20 | 21 | - name: Set up Node 22 | uses: actions/setup-node@v4 23 | with: 24 | node-version: '20' 25 | 26 | - name: Setup Pages 27 | id: pages 28 | uses: actions/configure-pages@v4 29 | 30 | - name: Build Schema 31 | run: make test 32 | 33 | - name: Upload Artifact 34 | uses: actions/upload-pages-artifact@v3 35 | with: 36 | path: ./build 37 | 38 | deploy: 39 | environment: 40 | name: github-pages 41 | url: ${{ steps.deployment.outputs.page_url }} 42 | runs-on: ubuntu-latest 43 | needs: build 44 | steps: 45 | - name: Deploy to GitHub Pages 46 | id: deployment 47 | uses: actions/deploy-pages@v4 48 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - main 7 | 8 | jobs: 9 | test: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Clone Repository 13 | uses: actions/checkout@v4 14 | 15 | - name: Set up Node 16 | uses: actions/setup-node@v4 17 | with: 18 | node-version: '20' 19 | 20 | - name: Run Tests 21 | run: make test 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /node_modules/ 3 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .DELETE_ON_ERROR: 2 | 3 | BIN_DIR := ./bin 4 | BUILD_DIR := ./build 5 | SRC_DIR := ./src 6 | SCHEMA_DIR := $(SRC_DIR)/schema 7 | 8 | export PATH := $(BIN_DIR):./node_modules/.bin/:$(PATH) 9 | 10 | SRC_SCHEMA := $(shell ls $(SCHEMA_DIR)/*.js) 11 | BUILD_SCHEMA := $(patsubst $(SCHEMA_DIR)/%.js,$(BUILD_DIR)/%.json,$(SRC_SCHEMA)) 12 | ALL_JS := $(shell find $(SRC_DIR) -type f -name '*.js') $(shell ls $(BIN_DIR)/*) 13 | 14 | .PHONY: build 15 | build: $(BUILD_SCHEMA) $(BUILD_DIR)/package.json $(BUILD_DIR)/readme.md 16 | 17 | # Install dependencies 18 | node_modules/.install: package.json 19 | @npm install 20 | @touch $@ 21 | 22 | # Build all schema 23 | $(BUILD_SCHEMA): $(SRC_SCHEMA) node_modules/.install 24 | @mkdir -p $(dir $@) 25 | @format.js $(patsubst $(BUILD_DIR)/%.json,$(SCHEMA_DIR)/%.js,./$@) > $@ 26 | 27 | $(BUILD_DIR)/package.json: package.json node_modules/.install 28 | @mkdir -p $(dir $@) 29 | @transform-package-json.js package.json > $@ 30 | 31 | $(BUILD_DIR)/readme.md: readme.md 32 | @mkdir -p $(dir $@) 33 | @cp readme.md $@ 34 | 35 | .PHONY: test 36 | test: build lint 37 | @node test/test.js 38 | 39 | .PHONY: lint 40 | lint: $(ALL_JS) node_modules/.install 41 | @eslint $(ALL_JS); 42 | 43 | .PHONY: lint-fix 44 | lint-fix: $(ALL_JS) node_modules/.install 45 | @eslint --fix $(ALL_JS); 46 | 47 | .PHONY: clean 48 | clean: 49 | @rm -rf $(BUILD_DIR) 50 | -------------------------------------------------------------------------------- /bin/format.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | import path from 'path'; 3 | 4 | async function main() { 5 | const baseURL = 'https://geojson.org/schema/'; 6 | const command = path.basename(process.argv[1]); 7 | const usage = `${command} 8 | 9 | Provided the path to a schema module (e.g. src/schema/Point.js), ${command} 10 | will write the formatted JSON schema to stdout. 11 | `; 12 | 13 | if (!process.argv[2]) { 14 | throw new Error(usage); 15 | } 16 | 17 | const input = path.resolve(process.argv[2]); 18 | 19 | let schema; 20 | try { 21 | const mod = await import(input); 22 | schema = mod.default; 23 | } catch (err) { 24 | throw new Error(`Failed to import ${input}: ${err.message}\n`); 25 | } 26 | 27 | return Object.assign( 28 | { 29 | $schema: 'http://json-schema.org/draft-07/schema#', 30 | $id: `${baseURL}${path.basename(input)}on`, 31 | }, 32 | schema 33 | ); 34 | } 35 | 36 | main() 37 | .then((schema) => { 38 | process.stdout.write(JSON.stringify(schema, null, 2) + '\n'); 39 | }) 40 | .catch((err) => { 41 | process.stderr.write(err.message + '\n', () => process.exit(1)); 42 | }); 43 | -------------------------------------------------------------------------------- /bin/transform-package-json.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | import {basename, resolve} from 'node:path'; 3 | import {readFile} from 'node:fs/promises'; 4 | 5 | async function main() { 6 | const command = basename(process.argv[1]); 7 | const usage = `${command} 8 | 9 | Provided the path to a package.json, ${command} 10 | will write the modified package.json to stdout. 11 | `; 12 | 13 | if (!process.argv[2]) { 14 | throw new Error(usage); 15 | } 16 | 17 | const input = resolve(process.argv[2]); 18 | 19 | const pkgData = await readFile(input, {encoding: 'utf-8'}); 20 | const pkg = JSON.parse(pkgData); 21 | delete pkg.private; 22 | return pkg; 23 | } 24 | 25 | main() 26 | .then((schema) => { 27 | process.stdout.write(JSON.stringify(schema, null, 2) + '\n'); 28 | }) 29 | .catch((err) => { 30 | process.stderr.write(err.message + '\n', () => process.exit(1)); 31 | }); 32 | -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2018 Tim Schaub 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "geojson-schema", 3 | "version": "1.0.5", 4 | "private": true, 5 | "repository": { 6 | "type": "git", 7 | "url": "git://github.com/geojson/schema.git" 8 | }, 9 | "keywords": [ 10 | "geojson", 11 | "schema" 12 | ], 13 | "license": "MIT", 14 | "type": "module", 15 | "scripts": { 16 | "lint": "make lint", 17 | "pretest": "npm run lint", 18 | "test": "make test", 19 | "build": "make build" 20 | }, 21 | "devDependencies": { 22 | "ajv": "^8.12.0", 23 | "eslint": "^8.57.0", 24 | "eslint-config-tschaub": "^14.1.2", 25 | "globby": "^14.0.1" 26 | }, 27 | "eslintConfig": { 28 | "extends": "tschaub" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # GeoJSON Schema 2 | 3 | This repository provides tools for building [JSON Schema](https://json-schema.org/) docs for [GeoJSON](https://geojson.org/). A schema is generated for each of the GeoJSON object types, and each individual doc is complete (without `$ref`s to other documents). So applications can consume just what they need and avoid extra fetching. 4 | 5 | See JSON Schema docs for the GeoJSON types below: 6 | * [`FeatureCollection`](https://geojson.org/schema/FeatureCollection.json) 7 | * [`Feature`](https://geojson.org/schema/Feature.json) 8 | * [`Geometry`](https://geojson.org/schema/Geometry.json) 9 | * [`GeometryCollection`](https://geojson.org/schema/GeometryCollection.json) 10 | * [`MultiPolygon`](https://geojson.org/schema/MultiPolygon.json) 11 | * [`MultiLineString`](https://geojson.org/schema/MultiLineString.json) 12 | * [`MultiPoint`](https://geojson.org/schema/MultiPoint.json) 13 | * [`Polygon`](https://geojson.org/schema/Polygon.json) 14 | * [`LineString`](https://geojson.org/schema/LineString.json) 15 | * [`Point`](https://geojson.org/schema/Point.json) 16 | 17 | The overall GeoJSON schema can be found at 18 | * [`GeoJSON`](https://geojson.org/schema/GeoJSON.json) 19 | 20 | The schema files are also published to the [`geojson-schema` package](https://www.npmjs.com/package/geojson-schema) on npm. You can add them as a dependency to your project with the following: 21 | 22 | npm install geojson-schema 23 | 24 | ## Limitations 25 | 26 | The schema can not be used to validate that linear rings are closed or that they follow the right-hand rule. These two elements of the [GeoJSON specification](https://datatracker.ietf.org/doc/html/rfc7946) cannot be represented in JSON Schema. To enforce these two elements of linear ring validation, parsers must implement their own logic on top of JSON Schema validation. 27 | 28 | # Development 29 | 30 | Install dependencies: 31 | 32 | npm install 33 | 34 | To build the schema docs: 35 | 36 | make 37 | 38 | The output will be in the `build` directory. 39 | 40 | A CI job builds commits pushed to `main`. After a successful build, artifacts are pushed to the `gh-pages` branch and will be accessible at geojson.org/schema/.json (e.g. https://geojson.org/schema/Point.json). 41 | 42 | ![Status](https://github.com/geojson/schema/actions/workflows/test.yml/badge.svg) 43 | 44 | # Publishing 45 | 46 | To publish the [`geojson-schema` package](https://www.npmjs.com/package/geojson-schema), run the following: 47 | 48 | npm version minor # or major or patch 49 | make build 50 | git push --tags origin main 51 | pushd build && npm publish && popd 52 | -------------------------------------------------------------------------------- /src/schema/Feature.js: -------------------------------------------------------------------------------- 1 | import BoundingBox from './ref/BoundingBox.js'; 2 | import GeometryCollection from './GeometryCollection.js'; 3 | import LineString from './LineString.js'; 4 | import MultiLineString from './MultiLineString.js'; 5 | import MultiPoint from './MultiPoint.js'; 6 | import MultiPolygon from './MultiPolygon.js'; 7 | import Point from './Point.js'; 8 | import Polygon from './Polygon.js'; 9 | 10 | export default { 11 | title: 'GeoJSON Feature', 12 | type: 'object', 13 | required: ['type', 'properties', 'geometry'], 14 | properties: { 15 | type: { 16 | type: 'string', 17 | enum: ['Feature'], 18 | }, 19 | id: { 20 | oneOf: [{type: 'number'}, {type: 'string'}], 21 | }, 22 | properties: { 23 | oneOf: [{type: 'null'}, {type: 'object'}], 24 | }, 25 | geometry: { 26 | oneOf: [ 27 | {type: 'null'}, 28 | Point, 29 | LineString, 30 | Polygon, 31 | MultiPoint, 32 | MultiLineString, 33 | MultiPolygon, 34 | GeometryCollection, 35 | ], 36 | }, 37 | bbox: BoundingBox, 38 | }, 39 | }; 40 | -------------------------------------------------------------------------------- /src/schema/FeatureCollection.js: -------------------------------------------------------------------------------- 1 | import BoundingBox from './ref/BoundingBox.js'; 2 | import Feature from './Feature.js'; 3 | 4 | export default { 5 | title: 'GeoJSON FeatureCollection', 6 | type: 'object', 7 | required: ['type', 'features'], 8 | properties: { 9 | type: { 10 | type: 'string', 11 | enum: ['FeatureCollection'], 12 | }, 13 | features: { 14 | type: 'array', 15 | items: Feature, 16 | }, 17 | bbox: BoundingBox, 18 | }, 19 | }; 20 | -------------------------------------------------------------------------------- /src/schema/GeoJSON.js: -------------------------------------------------------------------------------- 1 | import Feature from './Feature.js'; 2 | import FeatureCollection from './FeatureCollection.js'; 3 | import GeometryCollection from './GeometryCollection.js'; 4 | import LineString from './LineString.js'; 5 | import MultiLineString from './MultiLineString.js'; 6 | import MultiPoint from './MultiPoint.js'; 7 | import MultiPolygon from './MultiPolygon.js'; 8 | import Point from './Point.js'; 9 | import Polygon from './Polygon.js'; 10 | 11 | export default { 12 | title: 'GeoJSON', 13 | oneOf: [ 14 | Point, 15 | LineString, 16 | Polygon, 17 | MultiPoint, 18 | MultiLineString, 19 | MultiPolygon, 20 | GeometryCollection, 21 | Feature, 22 | FeatureCollection, 23 | ], 24 | }; 25 | -------------------------------------------------------------------------------- /src/schema/Geometry.js: -------------------------------------------------------------------------------- 1 | import LineString from './LineString.js'; 2 | import MultiLineString from './MultiLineString.js'; 3 | import MultiPoint from './MultiPoint.js'; 4 | import MultiPolygon from './MultiPolygon.js'; 5 | import Point from './Point.js'; 6 | import Polygon from './Polygon.js'; 7 | 8 | export default { 9 | title: 'GeoJSON Geometry', 10 | oneOf: [ 11 | Point, 12 | LineString, 13 | Polygon, 14 | MultiPoint, 15 | MultiLineString, 16 | MultiPolygon, 17 | ], 18 | }; 19 | -------------------------------------------------------------------------------- /src/schema/GeometryCollection.js: -------------------------------------------------------------------------------- 1 | import BoundingBox from './ref/BoundingBox.js'; 2 | import LineString from './LineString.js'; 3 | import MultiLineString from './MultiLineString.js'; 4 | import MultiPoint from './MultiPoint.js'; 5 | import MultiPolygon from './MultiPolygon.js'; 6 | import Point from './Point.js'; 7 | import Polygon from './Polygon.js'; 8 | 9 | export default { 10 | title: 'GeoJSON GeometryCollection', 11 | type: 'object', 12 | required: ['type', 'geometries'], 13 | properties: { 14 | type: { 15 | type: 'string', 16 | enum: ['GeometryCollection'], 17 | }, 18 | geometries: { 19 | type: 'array', 20 | items: { 21 | oneOf: [ 22 | Point, 23 | LineString, 24 | Polygon, 25 | MultiPoint, 26 | MultiLineString, 27 | MultiPolygon, 28 | ], 29 | }, 30 | }, 31 | bbox: BoundingBox, 32 | }, 33 | }; 34 | -------------------------------------------------------------------------------- /src/schema/LineString.js: -------------------------------------------------------------------------------- 1 | import BoundingBox from './ref/BoundingBox.js'; 2 | import LineStringCoordinates from './ref/LineStringCoordinates.js'; 3 | 4 | export default { 5 | title: 'GeoJSON LineString', 6 | type: 'object', 7 | required: ['type', 'coordinates'], 8 | properties: { 9 | type: { 10 | type: 'string', 11 | enum: ['LineString'], 12 | }, 13 | coordinates: LineStringCoordinates, 14 | bbox: BoundingBox, 15 | }, 16 | }; 17 | -------------------------------------------------------------------------------- /src/schema/MultiLineString.js: -------------------------------------------------------------------------------- 1 | import BoundingBox from './ref/BoundingBox.js'; 2 | import LineStringCoordinates from './ref/LineStringCoordinates.js'; 3 | 4 | export default { 5 | title: 'GeoJSON MultiLineString', 6 | type: 'object', 7 | required: ['type', 'coordinates'], 8 | properties: { 9 | type: { 10 | type: 'string', 11 | enum: ['MultiLineString'], 12 | }, 13 | coordinates: { 14 | type: 'array', 15 | items: LineStringCoordinates, 16 | }, 17 | bbox: BoundingBox, 18 | }, 19 | }; 20 | -------------------------------------------------------------------------------- /src/schema/MultiPoint.js: -------------------------------------------------------------------------------- 1 | import BoundingBox from './ref/BoundingBox.js'; 2 | import PointCoordinates from './ref/PointCoordinates.js'; 3 | 4 | export default { 5 | title: 'GeoJSON MultiPoint', 6 | type: 'object', 7 | required: ['type', 'coordinates'], 8 | properties: { 9 | type: { 10 | type: 'string', 11 | enum: ['MultiPoint'], 12 | }, 13 | coordinates: { 14 | type: 'array', 15 | items: PointCoordinates, 16 | }, 17 | bbox: BoundingBox, 18 | }, 19 | }; 20 | -------------------------------------------------------------------------------- /src/schema/MultiPolygon.js: -------------------------------------------------------------------------------- 1 | import BoundingBox from './ref/BoundingBox.js'; 2 | import PolygonCoordinates from './ref/PolygonCoordinates.js'; 3 | 4 | export default { 5 | title: 'GeoJSON MultiPolygon', 6 | type: 'object', 7 | required: ['type', 'coordinates'], 8 | properties: { 9 | type: { 10 | type: 'string', 11 | enum: ['MultiPolygon'], 12 | }, 13 | coordinates: { 14 | type: 'array', 15 | items: PolygonCoordinates, 16 | }, 17 | bbox: BoundingBox, 18 | }, 19 | }; 20 | -------------------------------------------------------------------------------- /src/schema/Point.js: -------------------------------------------------------------------------------- 1 | import BoundingBox from './ref/BoundingBox.js'; 2 | import PointCoordinates from './ref/PointCoordinates.js'; 3 | 4 | export default { 5 | title: 'GeoJSON Point', 6 | type: 'object', 7 | required: ['type', 'coordinates'], 8 | properties: { 9 | type: { 10 | type: 'string', 11 | enum: ['Point'], 12 | }, 13 | coordinates: PointCoordinates, 14 | bbox: BoundingBox, 15 | }, 16 | }; 17 | -------------------------------------------------------------------------------- /src/schema/Polygon.js: -------------------------------------------------------------------------------- 1 | import BoundingBox from './ref/BoundingBox.js'; 2 | import PolygonCoordinates from './ref/PolygonCoordinates.js'; 3 | 4 | export default { 5 | title: 'GeoJSON Polygon', 6 | type: 'object', 7 | required: ['type', 'coordinates'], 8 | properties: { 9 | type: { 10 | type: 'string', 11 | enum: ['Polygon'], 12 | }, 13 | coordinates: PolygonCoordinates, 14 | bbox: BoundingBox, 15 | }, 16 | }; 17 | -------------------------------------------------------------------------------- /src/schema/ref/BoundingBox.js: -------------------------------------------------------------------------------- 1 | export default { 2 | type: 'array', 3 | minItems: 4, 4 | items: { 5 | type: 'number', 6 | }, 7 | }; 8 | -------------------------------------------------------------------------------- /src/schema/ref/LineStringCoordinates.js: -------------------------------------------------------------------------------- 1 | import PointCoordinates from './PointCoordinates.js'; 2 | 3 | export default { 4 | type: 'array', 5 | minItems: 2, 6 | items: PointCoordinates, 7 | }; 8 | -------------------------------------------------------------------------------- /src/schema/ref/LinearRingCoordinates.js: -------------------------------------------------------------------------------- 1 | import PointCoordinates from './PointCoordinates.js'; 2 | 3 | export default { 4 | type: 'array', 5 | minItems: 4, 6 | items: PointCoordinates, 7 | }; 8 | -------------------------------------------------------------------------------- /src/schema/ref/PointCoordinates.js: -------------------------------------------------------------------------------- 1 | export default { 2 | type: 'array', 3 | minItems: 2, 4 | items: { 5 | type: 'number', 6 | }, 7 | }; 8 | -------------------------------------------------------------------------------- /src/schema/ref/PolygonCoordinates.js: -------------------------------------------------------------------------------- 1 | import LinearRingCoordinates from './LinearRingCoordinates.js'; 2 | 3 | export default { 4 | type: 'array', 5 | items: LinearRingCoordinates, 6 | }; 7 | -------------------------------------------------------------------------------- /test/assert.js: -------------------------------------------------------------------------------- 1 | import Ajv from 'ajv'; 2 | import fs from 'fs'; 3 | import {promisify} from 'util'; 4 | import {globby} from 'globby'; 5 | import path from 'path'; 6 | import {fileURLToPath} from 'url'; 7 | 8 | const readFile = promisify(fs.readFile); 9 | 10 | async function readJson(file) { 11 | const data = await readFile(file, 'utf8'); 12 | return JSON.parse(data); 13 | } 14 | 15 | const baseDir = path.dirname(fileURLToPath(import.meta.url)); 16 | 17 | const fixturesDir = path.join(baseDir, 'fixtures'); 18 | const schemaDir = path.join(baseDir, '..', 'build'); 19 | 20 | function reportErrors(schemaName, fixtureName, errors) { 21 | let message = `${fixtureName}:\n`; 22 | for (const error of errors) { 23 | message += ` ${fixtureName} ${error.message} (${schemaName}${error.schemaPath})\n`; 24 | } 25 | process.stderr.write(message); 26 | process.exit(1); 27 | } 28 | 29 | function fatal(err) { 30 | process.stderr.write(`${err.message}\n`); 31 | process.exit(1); 32 | } 33 | 34 | async function assertValidity(validity, schemaName, fixturePattern) { 35 | const ajv = new Ajv({allErrors: true, verbose: true}); 36 | const schemaPath = path.join(schemaDir, schemaName); 37 | const schema = await readJson(schemaPath); 38 | let validate; 39 | try { 40 | validate = ajv.compile(schema); 41 | } catch (err) { 42 | throw new Error(`Error compiling schema ${schemaPath}: ${err.message}`); 43 | } 44 | const paths = await globby(fixturePattern, {cwd: fixturesDir}); 45 | for (const fixtureName of paths) { 46 | const fixture = await readJson(path.join(fixturesDir, fixtureName)); 47 | const valid = validate(fixture); 48 | if (validity && !valid) { 49 | reportErrors(schemaName, fixtureName, validate.errors); 50 | } else if (!validity && valid) { 51 | throw new Error( 52 | `Expected ${fixtureName} not to validate against ${schemaName}` 53 | ); 54 | } 55 | } 56 | } 57 | 58 | export function valid(schemaName, fixturePattern) { 59 | assertValidity(true, schemaName, fixturePattern).catch(fatal); 60 | } 61 | 62 | export function invalid(schemaName, fixturePattern) { 63 | assertValidity(false, schemaName, fixturePattern).catch(fatal); 64 | } 65 | -------------------------------------------------------------------------------- /test/fixtures/invalid/feature/1d-point.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "ABC", 3 | "type": "Feature", 4 | "geometry": { 5 | "type": "Point", 6 | "coordinates": [ 7 | -122.308150179 8 | ] 9 | }, 10 | "properties": { 11 | "name": "Dinagat Islands" 12 | } 13 | } -------------------------------------------------------------------------------- /test/fixtures/invalid/feature/boolean-id.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Feature", 3 | "id": false, 4 | "geometry": { 5 | "type": "Point", 6 | "coordinates": [0, 0] 7 | }, 8 | "properties": { 9 | "name": "basic" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/invalid/feature/no-geometry.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Feature", 3 | "id": "1", 4 | "properties": { 5 | "name": "no geometry" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/invalid/feature/no-properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Feature", 3 | "id": "1", 4 | "geometry": { 5 | "type": "Point", 6 | "coordinates": [0, 0] 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /test/fixtures/invalid/feature/no-type.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "1", 3 | "geometry": { 4 | "type": "Point", 5 | "coordinates": [0, 0] 6 | }, 7 | "properties": { 8 | "name": "basic" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /test/fixtures/invalid/feature/object-id.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Feature", 3 | "id": { 4 | "foo": "bar" 5 | }, 6 | "geometry": { 7 | "type": "Point", 8 | "coordinates": [0, 0] 9 | }, 10 | "properties": { 11 | "name": "basic" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /test/fixtures/invalid/featurecollection/no-features.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection" 3 | } -------------------------------------------------------------------------------- /test/fixtures/invalid/featurecollection/no-type.json: -------------------------------------------------------------------------------- 1 | { 2 | "features": [ 3 | { 4 | "type": "Feature", 5 | "id": "1", 6 | "geometry": { 7 | "type": "Point", 8 | "coordinates": [0, 0] 9 | }, 10 | "properties": { 11 | "name": "basic" 12 | } 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /test/fixtures/invalid/geometrycollection/1d.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "GeometryCollection", 3 | "geometries": [ 4 | { 5 | "type": "Point", 6 | "coordinates": [0, 0] 7 | }, 8 | { 9 | "type": "LineString", 10 | "coordinates": [[-110, 45], [110]] 11 | }, 12 | { 13 | "type": "Polygon", 14 | "coordinates": [ 15 | [ 16 | [100.0, 0.0], 17 | [101.0, 0.0], 18 | [101.0, 1.0], 19 | [100.0, 1.0], 20 | [100.0, 0.0] 21 | ], 22 | [ 23 | [100.8, 0.8], 24 | [100.8, 0.2], 25 | [100.2, 0.2], 26 | [100.2, 0.8], 27 | [100.8, 0.8] 28 | ] 29 | ] 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /test/fixtures/invalid/geometrycollection/bad-geometry.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "GeometryCollection", 3 | "geometries": [ 4 | { 5 | "type": "Point", 6 | "coordinates": [0, 0] 7 | }, 8 | { 9 | "type": "Line", 10 | "coordinates": [[-110, 45], [110, -45]] 11 | }, 12 | { 13 | "type": "Polygon", 14 | "coordinates": [ 15 | [ 16 | [100.0, 0.0], 17 | [101.0, 0.0], 18 | [101.0, 1.0], 19 | [100.0, 1.0], 20 | [100.0, 0.0] 21 | ], 22 | [ 23 | [100.8, 0.8], 24 | [100.8, 0.2], 25 | [100.2, 0.2], 26 | [100.2, 0.8], 27 | [100.8, 0.8] 28 | ] 29 | ] 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /test/fixtures/invalid/geometrycollection/no-geometries.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "GeometryCollection", 3 | "coordinates": [ 4 | { 5 | "type": "Point", 6 | "coordinates": [0, 0] 7 | }, 8 | { 9 | "type": "LineString", 10 | "coordinates": [[-110, 45], [110, -45]] 11 | }, 12 | { 13 | "type": "Polygon", 14 | "coordinates": [ 15 | [ 16 | [100.0, 0.0], 17 | [101.0, 0.0], 18 | [101.0, 1.0], 19 | [100.0, 1.0], 20 | [100.0, 0.0] 21 | ], 22 | [ 23 | [100.8, 0.8], 24 | [100.8, 0.2], 25 | [100.2, 0.2], 26 | [100.2, 0.8], 27 | [100.8, 0.8] 28 | ] 29 | ] 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /test/fixtures/invalid/geometrycollection/no-type.json: -------------------------------------------------------------------------------- 1 | { 2 | "geometries": [ 3 | { 4 | "type": "Point", 5 | "coordinates": [0, 0] 6 | }, 7 | { 8 | "type": "LineString", 9 | "coordinates": [[-110, 45], [110, -45]] 10 | }, 11 | { 12 | "type": "Polygon", 13 | "coordinates": [ 14 | [ 15 | [100.0, 0.0], 16 | [101.0, 0.0], 17 | [101.0, 1.0], 18 | [100.0, 1.0], 19 | [100.0, 0.0] 20 | ], 21 | [ 22 | [100.8, 0.8], 23 | [100.8, 0.2], 24 | [100.2, 0.2], 25 | [100.2, 0.8], 26 | [100.8, 0.8] 27 | ] 28 | ] 29 | } 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /test/fixtures/invalid/linestring/1d.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "LineString", 3 | "coordinates": [[-110], [110]] 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/invalid/linestring/bad-bbox.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "LineString", 3 | "coordinates": [[-110, 45], [110, -45]], 4 | "bbox": [-110, -45, 110] 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/invalid/linestring/no-coordinates.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "LineString", 3 | "coords": [[-110, 45], [110, -45]] 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/invalid/linestring/no-type.json: -------------------------------------------------------------------------------- 1 | { 2 | "kind": "LineString", 3 | "coordinates": [[-110, 45], [110, -45]] 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/invalid/multilinestring/1d.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "MultiLineString", 3 | "coordinates": [ 4 | [[-111, 45], [111, -45]], 5 | [[-111, -45], [111]] 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/invalid/multilinestring/bad-bbox.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "MultiLineString", 3 | "bbox": [-111, -45, 111], 4 | "coordinates": [ 5 | [[-111, 45], [111, -45]], 6 | [[-111, -45], [111, 45]] 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /test/fixtures/invalid/multilinestring/no-coordinates.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "MultiLineString", 3 | "cordinates": [ 4 | [[-111, 45], [111, -45]], 5 | [[-111, -45], [111, 45]] 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/invalid/multilinestring/no-type.json: -------------------------------------------------------------------------------- 1 | { 2 | "coordinates": [ 3 | [[-111, 45], [111, -45]], 4 | [[-111, -45], [111, 45]] 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /test/fixtures/invalid/multipoint/1d.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "MultiPoint", 3 | "coordinates": [ 4 | [100, 0], 5 | [101] 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/invalid/multipoint/bad-bbox.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "MultiPoint", 3 | "coordinates": [ 4 | [100, 0], 5 | [101, 1] 6 | ], 7 | "bbox": [100, 101, 1] 8 | } 9 | -------------------------------------------------------------------------------- /test/fixtures/invalid/multipoint/no-coordinates.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "MultiPoint", 3 | "coordinate": [ 4 | [100, 0], 5 | [101, 1] 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/invalid/multipoint/no-type.json: -------------------------------------------------------------------------------- 1 | { 2 | "kind": "MultiPoint", 3 | "coordinates": [ 4 | [100, 0], 5 | [101, 1] 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/invalid/multipolygon/1d.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "MultiPolygon", 3 | "coordinates": [ 4 | [ 5 | [ 6 | [102.0, 2.0], 7 | [103.0, 2.0], 8 | [103.0, 3.0], 9 | [102.0, 3.0], 10 | [102.0, 2.0] 11 | ] 12 | ], 13 | [ 14 | [ 15 | [100.0, 0.0], 16 | [101.0, 0.0], 17 | [101.0, 1.0], 18 | [100.0, 1.0], 19 | [100.0, 0.0] 20 | ], 21 | [ 22 | [100.2, 0.2], 23 | [100.8, 0.2], 24 | [100.8, 0.8], 25 | [100.2, 0.8], 26 | [100.2] 27 | ] 28 | ] 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /test/fixtures/invalid/multipolygon/bad-bbox.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "MultiPolygon", 3 | "bbox": 42, 4 | "coordinates": [ 5 | [ 6 | [ 7 | [102.0, 2.0], 8 | [103.0, 2.0], 9 | [103.0, 3.0], 10 | [102.0, 3.0], 11 | [102.0, 2.0] 12 | ] 13 | ], 14 | [ 15 | [ 16 | [100.0, 0.0], 17 | [101.0, 0.0], 18 | [101.0, 1.0], 19 | [100.0, 1.0], 20 | [100.0, 0.0] 21 | ], 22 | [ 23 | [100.2, 0.2], 24 | [100.8, 0.2], 25 | [100.8, 0.8], 26 | [100.2, 0.8], 27 | [100.2, 0.2] 28 | ] 29 | ] 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /test/fixtures/invalid/multipolygon/no-coordinates.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "MultiPolygon" 3 | } 4 | -------------------------------------------------------------------------------- /test/fixtures/invalid/multipolygon/no-type.json: -------------------------------------------------------------------------------- 1 | { 2 | "typo": "MultiPolygon", 3 | "coordinates": [ 4 | [ 5 | [ 6 | [102.0, 2.0], 7 | [103.0, 2.0], 8 | [103.0, 3.0], 9 | [102.0, 3.0], 10 | [102.0, 2.0] 11 | ] 12 | ], 13 | [ 14 | [ 15 | [100.0, 0.0], 16 | [101.0, 0.0], 17 | [101.0, 1.0], 18 | [100.0, 1.0], 19 | [100.0, 0.0] 20 | ], 21 | [ 22 | [100.2, 0.2], 23 | [100.8, 0.2], 24 | [100.8, 0.8], 25 | [100.2, 0.8], 26 | [100.2, 0.2] 27 | ] 28 | ] 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /test/fixtures/invalid/point/1d.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Point", 3 | "coordinates": [0] 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/invalid/point/bad-bbox.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Point", 3 | "coordinates": [0, 0], 4 | "bbox": [0, 0] 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/invalid/point/no-coordinates.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Point" 3 | } 4 | -------------------------------------------------------------------------------- /test/fixtures/invalid/point/no-type.json: -------------------------------------------------------------------------------- 1 | { 2 | "coordinates": [0, 0] 3 | } 4 | -------------------------------------------------------------------------------- /test/fixtures/invalid/polygon/1d.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Polygon", 3 | "coordinates": [ 4 | [ 5 | [100], 6 | [101.0, 0.0], 7 | [101.0, 1.0], 8 | [100.0, 1.0], 9 | [100.0, 0.0] 10 | ], 11 | [ 12 | [100.8, 0.8], 13 | [100.8, 0.2], 14 | [100.2, 0.2], 15 | [100.2, 0.8], 16 | [100.8, 0.8] 17 | ] 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /test/fixtures/invalid/polygon/bad-type.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Polgon", 3 | "coordinates": [ 4 | [ 5 | [100.0, 0.0], 6 | [101.0, 0.0], 7 | [101.0, 1.0], 8 | [100.0, 1.0], 9 | [100.0, 0.0] 10 | ], 11 | [ 12 | [100.8, 0.8], 13 | [100.8, 0.2], 14 | [100.2, 0.2], 15 | [100.2, 0.8], 16 | [100.8, 0.8] 17 | ] 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /test/fixtures/invalid/polygon/no-coordinates.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Polygon" 3 | } 4 | -------------------------------------------------------------------------------- /test/fixtures/invalid/polygon/no-type.json: -------------------------------------------------------------------------------- 1 | { 2 | "coordinates": [ 3 | [ 4 | [100.0, 0.0], 5 | [101.0, 0.0], 6 | [101.0, 1.0], 7 | [100.0, 1.0], 8 | [100.0, 0.0] 9 | ], 10 | [ 11 | [100.8, 0.8], 12 | [100.8, 0.2], 13 | [100.2, 0.2], 14 | [100.2, 0.8], 15 | [100.8, 0.8] 16 | ] 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /test/fixtures/valid/feature/basic.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Feature", 3 | "id": "1", 4 | "geometry": { 5 | "type": "Point", 6 | "coordinates": [0, 0] 7 | }, 8 | "properties": { 9 | "name": "basic" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/valid/feature/empty-polygon.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "ABC", 3 | "type": "Feature", 4 | "properties": {}, 5 | "geometry": { 6 | "type": "Polygon", 7 | "coordinates": [] 8 | } 9 | } -------------------------------------------------------------------------------- /test/fixtures/valid/feature/null-geometry.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Feature", 3 | "id": "1", 4 | "geometry": null, 5 | "properties": { 6 | "name": "null geometry" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /test/fixtures/valid/feature/with-number-id.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Feature", 3 | "id": 42, 4 | "geometry": { 5 | "type": "Point", 6 | "coordinates": [0, 0] 7 | }, 8 | "properties": { 9 | "name": "basic" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/valid/feature/with-string-id.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Feature", 3 | "id": "feature.1", 4 | "geometry": { 5 | "type": "Point", 6 | "coordinates": [0, 0] 7 | }, 8 | "properties": { 9 | "name": "basic" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/valid/featurecollection/basic.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "id": "1", 7 | "geometry": { 8 | "type": "Point", 9 | "coordinates": [0, 0] 10 | }, 11 | "properties": { 12 | "name": "basic" 13 | } 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /test/fixtures/valid/featurecollection/empty.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [] 4 | } -------------------------------------------------------------------------------- /test/fixtures/valid/geometrycollection/3d.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "GeometryCollection", 3 | "geometries": [ 4 | { 5 | "type": "Point", 6 | "coordinates": [0, 0, 10] 7 | }, 8 | { 9 | "type": "LineString", 10 | "coordinates": [[-110, 45], [110, -45]] 11 | }, 12 | { 13 | "type": "Polygon", 14 | "coordinates": [ 15 | [ 16 | [100.0, 0.0], 17 | [101.0, 0.0], 18 | [101.0, 1.0], 19 | [100.0, 1.0], 20 | [100.0, 0.0] 21 | ], 22 | [ 23 | [100.8, 0.8], 24 | [100.8, 0.2], 25 | [100.2, 0.2], 26 | [100.2, 0.8], 27 | [100.8, 0.8] 28 | ] 29 | ] 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /test/fixtures/valid/geometrycollection/basic.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "GeometryCollection", 3 | "geometries": [ 4 | { 5 | "type": "Point", 6 | "coordinates": [0, 0] 7 | }, 8 | { 9 | "type": "LineString", 10 | "coordinates": [[-110, 45], [110, -45]] 11 | }, 12 | { 13 | "type": "Polygon", 14 | "coordinates": [ 15 | [ 16 | [100.0, 0.0], 17 | [101.0, 0.0], 18 | [101.0, 1.0], 19 | [100.0, 1.0], 20 | [100.0, 0.0] 21 | ], 22 | [ 23 | [100.8, 0.8], 24 | [100.8, 0.2], 25 | [100.2, 0.2], 26 | [100.2, 0.8], 27 | [100.8, 0.8] 28 | ] 29 | ] 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /test/fixtures/valid/geometrycollection/bbox.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "GeometryCollection", 3 | "bbox": [-110, -45, 110, 45], 4 | "geometries": [ 5 | { 6 | "type": "Point", 7 | "coordinates": [0, 0] 8 | }, 9 | { 10 | "type": "LineString", 11 | "coordinates": [[-110, 45], [110, -45]] 12 | }, 13 | { 14 | "type": "Polygon", 15 | "coordinates": [ 16 | [ 17 | [100.0, 0.0], 18 | [101.0, 0.0], 19 | [101.0, 1.0], 20 | [100.0, 1.0], 21 | [100.0, 0.0] 22 | ], 23 | [ 24 | [100.8, 0.8], 25 | [100.8, 0.2], 26 | [100.2, 0.2], 27 | [100.2, 0.8], 28 | [100.8, 0.8] 29 | ] 30 | ] 31 | } 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /test/fixtures/valid/linestring/3d.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "LineString", 3 | "coordinates": [[-110, 45, 100], [110, -45, 200]] 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/valid/linestring/basic.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "LineString", 3 | "coordinates": [[-110, 45], [110, -45]] 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/valid/linestring/bbox.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "LineString", 3 | "coordinates": [[-110, 45], [110, -45]], 4 | "bbox": [-110, -45, 110, 45] 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/valid/multilinestring/3d.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "MultiLineString", 3 | "coordinates": [ 4 | [[-111, 45, 10], [111, -45, 20]], 5 | [[-111, -45, 30], [111, 45, 40]] 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/valid/multilinestring/basic.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "MultiLineString", 3 | "coordinates": [ 4 | [[-111, 45], [111, -45]], 5 | [[-111, -45], [111, 45]] 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/valid/multilinestring/bbox.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "MultiLineString", 3 | "bbox": [-111, -45, 111, 45], 4 | "coordinates": [ 5 | [[-111, 45], [111, -45]], 6 | [[-111, -45], [111, 45]] 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /test/fixtures/valid/multipoint/3d.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "MultiPoint", 3 | "coordinates": [ 4 | [100, 0, 1], 5 | [101, 1, -1] 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/valid/multipoint/basic.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "MultiPoint", 3 | "coordinates": [ 4 | [100, 0], 5 | [101, 1] 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /test/fixtures/valid/multipoint/bbox.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "MultiPoint", 3 | "coordinates": [ 4 | [100, 0], 5 | [101, 1] 6 | ], 7 | "bbox": [100, 0, 101, 1] 8 | } 9 | -------------------------------------------------------------------------------- /test/fixtures/valid/multipolygon/3d.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "MultiPolygon", 3 | "coordinates": [ 4 | [ 5 | [ 6 | [102.0, 2.0, 10], 7 | [103.0, 2.0, 10], 8 | [103.0, 3.0, 10], 9 | [102.0, 3.0, 10], 10 | [102.0, 2.0, 10] 11 | ] 12 | ], 13 | [ 14 | [ 15 | [100.0, 0.0, 20], 16 | [101.0, 0.0, 20], 17 | [101.0, 1.0, 20], 18 | [100.0, 1.0, 20], 19 | [100.0, 0.0, 20] 20 | ], 21 | [ 22 | [100.2, 0.2, 30], 23 | [100.8, 0.2, 30], 24 | [100.8, 0.8, 30], 25 | [100.2, 0.8, 30], 26 | [100.2, 0.2, 30] 27 | ] 28 | ] 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /test/fixtures/valid/multipolygon/basic.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "MultiPolygon", 3 | "coordinates": [ 4 | [ 5 | [ 6 | [102.0, 2.0], 7 | [103.0, 2.0], 8 | [103.0, 3.0], 9 | [102.0, 3.0], 10 | [102.0, 2.0] 11 | ] 12 | ], 13 | [ 14 | [ 15 | [100.0, 0.0], 16 | [101.0, 0.0], 17 | [101.0, 1.0], 18 | [100.0, 1.0], 19 | [100.0, 0.0] 20 | ], 21 | [ 22 | [100.2, 0.2], 23 | [100.8, 0.2], 24 | [100.8, 0.8], 25 | [100.2, 0.8], 26 | [100.2, 0.2] 27 | ] 28 | ] 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /test/fixtures/valid/multipolygon/bbox.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "MultiPolygon", 3 | "bbox": [100, 0, 103, 3], 4 | "coordinates": [ 5 | [ 6 | [ 7 | [102.0, 2.0], 8 | [103.0, 2.0], 9 | [103.0, 3.0], 10 | [102.0, 3.0], 11 | [102.0, 2.0] 12 | ] 13 | ], 14 | [ 15 | [ 16 | [100.0, 0.0], 17 | [101.0, 0.0], 18 | [101.0, 1.0], 19 | [100.0, 1.0], 20 | [100.0, 0.0] 21 | ], 22 | [ 23 | [100.2, 0.2], 24 | [100.8, 0.2], 25 | [100.8, 0.8], 26 | [100.2, 0.8], 27 | [100.2, 0.2] 28 | ] 29 | ] 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /test/fixtures/valid/point/3d.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Point", 3 | "coordinates": [-110, 45, 100] 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/valid/point/basic.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Point", 3 | "coordinates": [0, 0] 4 | } 5 | -------------------------------------------------------------------------------- /test/fixtures/valid/point/bbox.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Point", 3 | "coordinates": [0, 0], 4 | "bbox": [0, 0, 0, 0] 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/valid/point/extended.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Point", 3 | "coordinates": [0, 0], 4 | "title": "Null Island" 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/valid/polygon/3d.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Polygon", 3 | "coordinates": [ 4 | [ 5 | [100.0, 0.0, 10], 6 | [101.0, 0.0, 10], 7 | [101.0, 1.0, 10], 8 | [100.0, 1.0, 10], 9 | [100.0, 0.0, 10] 10 | ], 11 | [ 12 | [100.8, 0.8, 10], 13 | [100.8, 0.2, 10], 14 | [100.2, 0.2, 10], 15 | [100.2, 0.8, 10], 16 | [100.8, 0.8, 10] 17 | ] 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /test/fixtures/valid/polygon/basic.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Polygon", 3 | "coordinates": [ 4 | [ 5 | [100.0, 0.0], 6 | [101.0, 0.0], 7 | [101.0, 1.0], 8 | [100.0, 1.0], 9 | [100.0, 0.0] 10 | ], 11 | [ 12 | [100.8, 0.8], 13 | [100.8, 0.2], 14 | [100.2, 0.2], 15 | [100.2, 0.8], 16 | [100.8, 0.8] 17 | ] 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /test/fixtures/valid/polygon/bbox.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "Polygon", 3 | "coordinates": [ 4 | [ 5 | [100.0, 0.0], 6 | [101.0, 0.0], 7 | [101.0, 1.0], 8 | [100.0, 1.0], 9 | [100.0, 0.0] 10 | ], 11 | [ 12 | [100.8, 0.8], 13 | [100.8, 0.2], 14 | [100.2, 0.2], 15 | [100.2, 0.8], 16 | [100.8, 0.8] 17 | ] 18 | ], 19 | "bbox": [100, 0, 101, 1] 20 | } 21 | -------------------------------------------------------------------------------- /test/fixtures/valid/polygon/extended.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Titled Polygon", 3 | "type": "Polygon", 4 | "coordinates": [ 5 | [ 6 | [100.0, 0.0], 7 | [101.0, 0.0], 8 | [101.0, 1.0], 9 | [100.0, 1.0], 10 | [100.0, 0.0] 11 | ], 12 | [ 13 | [100.8, 0.8], 14 | [100.8, 0.2], 15 | [100.2, 0.2], 16 | [100.2, 0.8], 17 | [100.8, 0.8] 18 | ] 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | import {valid, invalid} from './assert.js'; 2 | 3 | valid('Point.json', 'valid/point/**/*.json'); 4 | valid('LineString.json', 'valid/linestring/**/*.json'); 5 | valid('Polygon.json', 'valid/polygon/**/*.json'); 6 | valid('MultiPoint.json', 'valid/multipoint/**/*.json'); 7 | valid('MultiLineString.json', 'valid/multilinestring/**/*.json'); 8 | valid('MultiPolygon.json', 'valid/multipolygon/**/*.json'); 9 | valid('GeometryCollection.json', 'valid/geometrycollection/**/*.json'); 10 | valid('GeoJSON.json', 'valid/**/*.json'); 11 | 12 | invalid('Point.json', 'invalid/**/*.json'); 13 | invalid('LineString.json', 'invalid/**/*.json'); 14 | invalid('Polygon.json', 'invalid/**/*.json'); 15 | invalid('MultiPoint.json', 'invalid/**/*.json'); 16 | invalid('MultiLineString.json', 'invalid/**/*.json'); 17 | invalid('MultiPolygon.json', 'invalid/**/*.json'); 18 | invalid('GeometryCollection.json', 'invalid/**/*.json'); 19 | invalid('Feature.json', 'invalid/**/*.json'); 20 | invalid('FeatureCollection.json', 'invalid/**/*.json'); 21 | invalid('GeoJSON.json', 'invalid/**/*.json'); 22 | --------------------------------------------------------------------------------