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

mongoose-geojson-schema

v2.2.5

Published

Schema definitions for GeoJSON types for use with Mongoose JS

Downloads

22,116

Readme

mongoose-geojson-schema

About

Schema definitions for GeoJSON types for use with Mongoose JS, a mongodb object model.

The GeoJSON Schema specifies geospatial data types for use in JSON-based projects. This package aims to make those data types available to those wanting to employ them in a mongoose schema, with validation following the strict guidelines available on the GeoJSON website. The following data types are available:

  • Point
  • MultiPoint
  • LineString
  • MultiLineString
  • Polygon
  • MultiPolygon

and the following super types:

  • Geometry
  • GeometryCollection
  • Feature
  • FeatureCollection

Coordinate Reference Systems

Following the GeoJSON spec, we assume a default coordinate reference system (CRS) of the WGS84 datum. That is, coordinates are validated to represent longitude and latitude units of decimal degrees.

If you wish to disable this validation, set the crs property to a null or alternate value following the GeoJSON spec for Coordinate Reference Sytems

Installation

First install node.js, mongodb and mongoose

$ npm install mongoose-geojson-schema --save

Usage v2.x

var GeoJSON = require('mongoose-geojson-schema');
var mongoose = require('mongoose');

var schema = new mongoose.Schema({
	any: mongoose.Schema.Types.GeoJSON,
	point: mongoose.Schema.Types.Point,
  multipoint: mongoose.Schema.Types.MultiPoint,
  linestring: mongoose.Schema.Types.LineString,
  multilinestring: mongoose.Schema.Types.MultiLineString,
  polygon: mongoose.Schema.Types.Polygon,
  multipolygon: mongoose.Schema.Types.MultiPolygon,
  geometry: mongoose.Schema.Types.Geometry,
  geometrycollection: mongoose.Schema.Types.GeometryCollection,
  feature: mongoose.Schema.Types.Feature,
  featurecollection: mongoose.Schema.Types.FeatureCollection
});

var db = mongoose.createConnection('localhost', 'test');
var Location = db.model('GeoJSON', schema);

var test = new Location({
	any: {
		type: "Point",
		coordinates: [-113.806458, 44.847784]
	},
	point: {
	  type: "Point",
	  coordinates: [12.123456, 13.134578]
	},
	...
	polygon: {
		type: "Polygon",
		coordinates: [
			[
				[12.123456, 13.1345678],
				[179.999999, -1.345],
				[12.0002, -45.4663],
				[12.123456, 13.1345678]
			],
			...
	}
});

Usage v1.x

var GeoJSON = require('mongoose-geojson-schema');
var mongoose = require('mongoose');

var schema = new mongoose.Schema({
	point: mongoose.Schema.Types.Point,
	multipoint: mongoose.Schema.Types.MultiPoint,
	linestring: mongoose.Schema.Types.LineString,
	multilinestring: mongoose.Schema.Types.MultiLineString,
	polygon: mongoose.Schema.Types.Polygon,
	multipolygon: mongoose.Schema.Types.MultiPolygon,
	geometry: mongoose.Schema.Types.Geometry,
	geometrycollection: mongoose.Schema.Types.GeometryCollection,
	feature: mongoose.Schema.Types.Feature,
	featurecollection: mongoose.Schema.Types.FeatureCollection
});

var db = mongoose.createConnection('localhost', 'test');
var model = db.model('GeoJSON', schema);

var test = new GeoJSON({
	point: {
	  type: "Point",
	  coordinates: [12.123456, 13.134578]
	},
	...
	polygon: {
		type: "Polygon",
		coordinates: [
			[
				[12.123456, 13.1345678],
				[179.999999, -1.345],
				[12.0002, -45.4663],
				[12.123456, 13.1345678]
			],
			...
	}
});

Usage v0.x

var GeoJSON = require('mongoose-geojson-schema');
var mongoose = require('mongoose');

var schema = new mongoose.Schema({
	geoFeature:GeoJSON.Feature
});

Testing

npm test

See Also

  • If you are developing in TypeScript, you can load GeoJSON Types to validate GeoJSON objects througout your code.

Contributors

Ben Dalton, Mark Stosberg, Joshua Kopecek

License

Copyright (c) 2014-2016, RideAmigos. (MIT License)

See LICENSE for more info.