Skip to content

JSON schema files and a validator for the GeoJSON specification

License

Notifications You must be signed in to change notification settings

yagajs/geojson-schema

Repository files navigation

JSON schema definitions and validator for GeoJSON

Build Status

This module serves the JSON schema definitions for GeoJSON and a validator extended from the NPM module jsonschema.

It serves declaration files for TypeScript.

How to use

First you have to install this library from npm:

npm install --save @yaga/geojson-schema
# OR
yarn add  @yaga/geojson-schema

You will find the schema definitions as single json files in the subfolder schema or while

Use this module with TypeScript:

import { GeoJSONValidator, validate, schemas } from "@yaga/geojson-schema";

const point = {
    type: "Point",
    coordinates: [1, 2],
};

// With an instance of a class
const aNewValidator = new GeoJSONValidator();

console.log(
    "Validation results:",
    aNewValidator.validate(point, schemas.point),
);

// With a factory function
console.log(
    "Validation results:",
    validate(point, schemas.point),
);

Use the module with JavaScript:

const { GeoJSONValidator, validate, schemas } = require('@yaga/geojson-schema');

const point = {
    type: "Point",
    coordinates: [1, 2],
};

// With an instance of a class
const aNewValidator = new GeoJSONValidator();

console.log(
    "Validation results:",
    aNewValidator.validate(point, schemas.point),
);

// With a factory function
console.log(
    "Validation results:",
    validate(point, schemas.point),
);

Schemas

The module provides the following schemas:

import { schemas } from "@yaga/geojson-schema";
// The namespace schemas includes the following schemas:
  • geometryTypes: http://geojson.org/schema/geometry-types
  • geoJSONTypes: http://geojson.org/schema/geojson-types
  • bbox: http://geojson.org/schema/bbox
  • geoJSONObject: http://geojson.org/schema/geojson-object
  • geometryObject: http://geojson.org/schema/geometry-object
  • position: http://geojson.org/schema/position
  • point: http://geojson.org/schema/point
  • multiPoint: http://geojson.org/schema/multi-point
  • lineString: http://geojson.org/schema/line-string
  • multiLineString: http://geojson.org/schema/multi-line-string
  • polygon: http://geojson.org/schema/polygon
  • multiPolygon: http://geojson.org/schema/multi-polygon
  • geometryCollection: http://geojson.org/schema/geometry-collection
  • anyGeometry: http://geojson.org/schema/any-geometry
  • feature: http://geojson.org/schema/feature
  • featureCollection: http://geojson.org/schema/feature-collection

The list represents the key followed by the schema-id

For further information look at the GeoJSON specification or the TypeScript TypeDefinition for GeoJSON.

Scripts Tasks

Scripts registered in package.json:

  • transpile: Transpile TypeScript Code to JavaScript.
  • lint: Use the linter for TypeScript Code.
  • test: Run software-tests in node.
  • dist: Make everything ready for a release.

License

This library is released under the ISC License.

Links

About

JSON schema files and a validator for the GeoJSON specification

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published