npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gjtk

v2.1.0

Published

GeoJSON ToolKit

Downloads

116

Readme

GeoJSON ToolKit

gjtk is a library for working with GeoJSON.

Installation

gjtk is available on npm.

npm install gjtk

Usage

var gjtk = require('gjtk');

Validation Methods

All validation methods take a single argument.

isGeoJSON

returns true when passed a valid GeoJSON object, otherwise false

GeoJSON always consists of a single object. This object (referred to as the GeoJSON object [above]) represents a geometry, feature, or collection of features.

isGeometry

returns true when passed a valid GeoJSON Geometry, otherwise false

A geometry is a GeoJSON object where the type member's value is one of the following strings: "Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon", or "GeometryCollection".

isPosition

returns true when passed a valid GeoJSON Position, otherwise false

A position is represented by an array of numbers. There must be at least two elements, and may be more. The order of elements must follow x, y, z order (easting, northing, altitude for coordinates in a projected coordinate reference system, or longitude, latitude, altitude for coordinates in a geographic coordinate reference system). Any number of additional elements are allowed -- interpretation and meaning of additional elements is beyond the scope of this specification.

isPointCoordinates

returns true when passed valid GeoJSON Point coordinates, otherwise false

example

[100.0, 0.0]

isMultiPointCoordinates

returns true when passed valid GeoJSON MultiPoint coordinates, otherwise false

example

[ [100.0, 0.0], [101.0, 1.0], [102.0, 2.0] ]

isLineStringCoordinates

returns true when passed valid GeoJSON LineString coordinates, otherwise false

example

[ [100.0, 0.0], [101.0, 1.0] ]

isLinearRingCoordinates

returns true when passed valid GeoJSON LinearRing coordinates, otherwise false

A LinearRing is closed LineString with 4 or more positions. The first and last positions are equivalent (they represent equivalent points). Though a LinearRing is not explicitly represented as a GeoJSON geometry type, it is referred to in the Polygon geometry type definition.

example

[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]

isMultiLineStringCoordinates

returns true when passed valid GeoJSON MultiLineString coordinates, otherwise false

example

[
  [ [100.0, 0.0], [101.0, 1.0] ],
  [ [102.0, 2.0], [103.0, 3.0] ]
]

isPolygonCoordinates

returns true when passed valid GeoJSON Polygon coordinates, otherwise false

example

  • 0 holes
[
  [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
]
  • 1 hole
[
  [ [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] ]
]
  • etc.

isMultiPolygonCoordinates

returns true when passed valid GeoJSON MultiPolygon coordinates, otherwise false

example

[
  [
    [ [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] ]
  ]
]

isPoint

returns true when passed a valid GeoJSON Point, otherwise false

example

{ "type": "Point", "coordinates": [100.0, 0.0] }

isMultiPoint

returns true when passed a valid GeoJSON MultiPoint, otherwise false

example

{ "type": "MultiPoint", "coordinates": [ [100.0, 0.0], [101.0, 1.0] ] }

isLineString

returns true when passed a valid GeoJSON LineString, otherwise false

example

{
  "type": "LineString",
  "coordinates": [ [100.0, 0.0], [101.0, 1.0] ]
}

isMultiLineString

returns true when passed a valid GeoJSON MultiLineString, otherwise false

example

{
  "type": "MultiLineString",
  "coordinates": [
    [ [100.0, 0.0], [101.0, 1.0] ],
    [ [102.0, 2.0], [103.0, 3.0] ]
  ]
}

isPolygon

returns true when passed a valid GeoJSON Polygon, otherwise false

example

  • 0 holes
{
  "type": "Polygon",
  "coordinates": [
    [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ]
  ]
}
  • 1 hole
{
  "type": "Polygon",
  "coordinates": [
    [ [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] ]
  ]
}
  • etc.

isMultiPolygon

returns true when passed a valid GeoJSON MultiPolygon, otherwise false

example

{
  "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] ]
    ]
  ]
}

isGeometryCollection

returns true when passed a valid GeoJSON Geometry Collection, otherwise false

example

{
  "type": "GeometryCollection",
  "geometries": [
    {
      "type": "Point",
      "coordinates": [100.0, 0.0]
    },
    {
      "type": "LineString",
      "coordinates": [ [101.0, 0.0], [102.0, 1.0] ]
    }
  ]
}

isFeature

returns true when passed a valid GeoJSON Feature, otherwise false

example

{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [125.6, 10.1]
  },
  "properties": {
    "name": "Dinagat Islands"
  }
}

isFeatureCollection

returns true when passed a valid GeoJSON Feature Collection, otherwise false

example

{
  "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"
        }
      }
    }
  ]
}

isCRS

returns true when passed a valid GeoJSON Coordinate Reference System, otherwise false

example

{
  "type": "name",
  "properties": {
    "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
  }
}
{
  "type": "link", 
  "properties": {
    "href": "http://example.com/crs/42",
    "type": "proj4"
  }
}

hasCRS

returns true when passed an object that validly specifies a GeoJSON Coordinate Reference System, otherwise false

The coordinate reference system (CRS) of a GeoJSON object is determined by its "crs" member (referred to as the CRS object below). If an object has no crs member, then its parent or grandparent object's crs member may be acquired. If no crs member can be so acquired, the default CRS shall apply to the GeoJSON object.

isLink

returns true when passed a valid GeoJSON Link, otherwise false

example

{
  "type": "link",
  "properties": {
    "href": "data.crs",
    "type": "ogcwkt"
  }
}

isBbox (not implemented)

returns true when passed a valid GeoJSON Bounding Box, otherwise false

example

[-180.0, -90.0, 180.0, 90.0]

hasBbox (partially implemented)

returns true when passed an object that validly specifies a GeoJSON Bounding Box, otherwise false

example

{
  "type": "Feature",
  "bbox": [-180.0, -90.0, 180.0, 90.0],
  "geometry": {
    "type": "Polygon",
    "coordinates": [
      [ [-180.0, 10.0], [20.0, 90.0], [180.0, -5.0], [-30.0, -90.0] ]
    ]
  }
}

Utility Methods

Comparison

equalPositions(position1, position2)

returns true when all parameters are identical GeoJSON Positions, otherwise false

containedPolygon(innerLinearRing, outerLinearRing)

returns true when one GeoJSON LinearRing contains another, otherwise false

Templates

Point(Position)

returns a GeoJSON Point object

Feature(Geometry, properties)

returns a GeoJSON Feature object

FeatureCollection(Features)

returns a GeoJSON FeatureCollection object

GeometryCollection(Geometries)

returns a GeoJSON GeometryCollection object

Extraction

These methods all take a single argument: a valid GeoJSON object.

positionsOf

returns all the Positions in a valid GeoJSON object

featuresOf

returns all the Features in a valid GeoJSON object

geometriesOf

returns all the Geometries in a valid GeoJSON object