Giter Site home page Giter Site logo

hollyjm81 / mongoose-geojson-schema Goto Github PK

View Code? Open in Web Editor NEW

This project forked from echoes-xyz/mongoose-geojson-schema

0.0 0.0 0.0 168 KB

Schema definitions for GeoJSON types for use with Mongoose JS

License: MIT License

JavaScript 100.00%

mongoose-geojson-schema's Introduction

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.

mongoose-geojson-schema's People

Contributors

joshkopecek avatar markstos avatar bendalton avatar danstutzman avatar gerardsoleca avatar muhammadfaizan avatar daveybrown avatar dependabot[bot] avatar vedi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.