SlideShare une entreprise Scribd logo
1  sur  32
Télécharger pour lire hors ligne
Map the Globe, simply
Polygon indexing and GeoJSON support
in MongoDB
Greg Studer
greg@10gen.com
mongoNYC 2013
● 2d vs 2dsphere
● (Quick) overview of previous geospatial features
in MongoDB
● New line/polygon indexing on spherical globe
GeoJSON - lines and polygons
● Geo in aggregation
● Future Roadmap
Why use (2dsphere) geospatial indexing?
1. Have earth-like coordinates and regions tagged
to other data over large areas
2. Want to query this data
based on location
3. Don't necessarily want to
think a lot about the fact
that the earth is round
[ from Jpatokal at wikimedia.org ]
https://secure.wikimedia.org/wikipedia/commons/wiki/File:World-airline-routemap-2009.png
[ from Jpatokal at wikimedia.org ]
https://secure.wikimedia.org/wikipedia/commons/wiki/File:World-airline-routemap-2009.png
https://www.e-education.psu.edu/natureofgeoinfo
Why use (2d) geospatial indexing?
1. Have regional or virtual world coordinates
embedded in other data
2. (For now) Only indexing
locations
3. Don't want spherical
overhead
Overview of geo features
● 2.2 - "2d"
Index only (multi-)points
Query near points or within simple polygons
// Make a flat 2d index [-180 -> 180)
> db.coll.ensureIndex(
{ location : "2d", type : 1 } )
// Insert some point data
> db.coll.insert({ name : "Shake Shack",
type : "rest",
location : [ -73.9881353, 40.7415064 ]
})
> db.coll.insert({ name : "Park Avenue
Tavern", type : "bar",
location : [ -73.9786924, 40.7502231 ]
})
// Find in Manhattan Mall
> db.coll.find({ location : { $geoWithin : {
$polygon : [[ -73.9884761, 40.7491204 ],
[ -73.988829, 40.7486387 ],
[ -73.9901297, 40.7491856 ],
[ -73.9897768, 40.7496673 ],
[ -73.9884761, 40.7491204 ]] }}},
type : "rest" })
// Find near Washington Square (center)
> db.coll.find({ location : {
$geoNear : [ -73.7695467, 42.6622728 ] },
type : "rest" });
Overview of geo features
● 2.2 - "2d"
DEMO - NYC OpenStreetMaps data
github.com/mongodb/mongo-snippets/tree/master/2dsphere
Overview of geo features
● Current 2.4 - "2dsphere"
Index points, lines, and polygons (on sphere)
Understands simple GeoJSON
Query with points, lines, and polygons
Within-region, Intersect-region, Near-point
queries
GeoJSON
● Widely supported open JSON standard
http://www.geojson.org/
● Simple language:
{ type : 'Point',
coordinates : [<lon>, <lat>] }
{ type : 'LineString',
coordinates : [[<lon>, <lat>],...] }
{ type : 'Polygon',
coordinates : [[[<lon>,<lat>],...],...]}
+ other MultiXXX types (future) ...
// Make a spherical 2d compound index
> db.coll.ensureIndex(
{ type : 1, location : "2dsphere" } )
// Insert Park Avenue
> db.coll.insert(
{ name : "Park Avenue", type : "road",
location : { type : 'LineString',
coordinates : [
[ -73.9359712600708, 40.80942429324451],
[ -73.93676519393921, 40.80820620367037],
... ]} });
// Insert Great Hill
> db.coll.insert(
{ name : "Great Hill", type : "park",
location : { type : 'Polygon',
coordinates : [[
[ -73.95841598510742, 40.79724239132546],
[ -73.95817995071411, 40.79691751000055],
... ]]} });
// Find docs with geometry that intersects
// a route
> db.coll.find({ location :
{ $geoIntersects : { $geometry :
{ type : 'LineString',
// Run coordinates
coordinates : [
[ -73.95586252212524, 40.77964777966238 ],
[ -73.95886659622192, 40.78091513739611 ],
... ]} }}})
Overview of geo features
● Current 2.4 - "2dsphere"
DEMO - NYC OpenStreetMaps data
github.com/mongodb/mongo-snippets/tree/master/2dsphere
Overview of geo features
● Current 2.4 - "2dsphere"
Reduced shape distortion
DEMO - NYC OpenStreetMaps data
github.com/mongodb/mongo-snippets/tree/master/2dsphere
Technology
● GeoJSON
http://www.geojson.org
● Google S2 Geometry Library
Apache License 2.0
http://code.google.com/p/s2-geometry-library
image by user geek3 @ http://en.
wikipedia.org/wiki/File:
Sphere_wireframe_10deg_6r.svg
S2
S2
00
0110
11
10|01
10|0010|11
10|10
● 2d vs 2dsphere
● (Quick) overview of previous geospatial features
in MongoDB
● New line/polygon indexing on spherical globe
GeoJSON - lines and polygons
● Geo in aggregation
● Future Roadmap
Overview of geo features
● Current 2.4 - aggregation support
Geospatial predicates in aggregation
Near sorting in aggregation, custom output
fields
> db.ny.aggregate([
// Find everything in MidTown/Hell's Kitchen
{ $match : { geo: { $geoWithin: { $geometry:
{ type: "Polygon", coordinates: [[
// Midtown/Hell's Kitchen
[ -73.9984130859375, 40.78028146155187 ],
[ -73.95240783691406, 40.76182096906601 ],
[ -73.96888732910156, 40.73945350425846 ],
[ -74.01420593261719, 40.75531957477602 ],
[ -73.9984130859375, 40.78028146155187 ]
]] } } } } },
...
...
// Organize stuff we want
{ $project :
{ tags : 1,
info : { name : "$name",
lonLat : "$geo.coordinates" }} },
{ $unwind : "$tags" },
// Count by tag types
{ $group : { _id : "$tags",
total : { $sum : 1 },
locs : { $push : "$info" } }}
]); // end
{ "result" : [
{ "_id" : "park", "total" : 18,
"locs" : [{
"name" : "Hells Kitchen Park",
"lonLat" : [ -73.9925, 40.7630556 ] },
...
{ "_id" : "bar", "total" : 28,
"locs" : [
{ "name" : "Landmark Tavern",
"lonLat" : [ -73.9963261, 40.7631922 ] },
{ "name" : "Pony Bar",
"lonLat" : [ -73.994236, 40.761723 ] },
...
...
> db.ny.aggregate([
// Find near Times Square
{ $geoNear : {
near : {
type: "Point",
// Times Square
coordinates: [ -73.98508787155151,
40.75905795418586 ] },
distanceField : "distance",
spherical : true, // 2dsphere
num : 1000 } },
...
...
// Organize stuff we want
{ $project :
{ tags : 1,
info : { name : "$name",
distance : "$distance",
lonLat : "$geo.coordinates" }} },
{ $unwind : "$tags" },
// Count by tag types
{ $group : { _id : "$tags",
total : { $sum : 1 },
locs : { $push : "$info" } }}
]); // end
...
{ "result" : [
{ "_id" : "park", "total" : 11,
"locs" : [{
"name" : "Ramone Aponte Park",
"distance" : 449.7417003854033, // m
"lonLat" : [ -73.9894444, 40.7613889 ]},
...
{ "_id" : "bar", "total" : 24,
"locs" : [{
"name" : "The Lambs Club",
"distance" : 275.0270424641914, // m
"lonLat" : [ -73.9963261, 40.7631922 ]},
...
...
[ from Jpatokal at wikimedia.org ]
https://secure.wikimedia.org/wikipedia/commons/wiki/File:World-airline-routemap-2009.png
Future
● Further support for other predicates
OGC Simple Features
● GeoJSON composite shapes
● Indexing API to allow similar enhancements for
"flat plane" work
● Space open for non-default CRSes
Thanks!
greg@10gen.com

Contenu connexe

Tendances

Webinar: Exploring the Aggregation Framework
Webinar: Exploring the Aggregation FrameworkWebinar: Exploring the Aggregation Framework
Webinar: Exploring the Aggregation FrameworkMongoDB
 
Integration of Google-map in Rails Application
Integration of Google-map in Rails ApplicationIntegration of Google-map in Rails Application
Integration of Google-map in Rails ApplicationSwati Jadhav
 
Fun with D3.js: Data Visualization Eye Candy with Streaming JSON
Fun with D3.js: Data Visualization Eye Candy with Streaming JSONFun with D3.js: Data Visualization Eye Candy with Streaming JSON
Fun with D3.js: Data Visualization Eye Candy with Streaming JSONTomomi Imura
 
The Aggregation Framework
The Aggregation FrameworkThe Aggregation Framework
The Aggregation FrameworkMongoDB
 
Nosh slides mongodb web application - mongo philly 2011
Nosh slides   mongodb web application - mongo philly 2011Nosh slides   mongodb web application - mongo philly 2011
Nosh slides mongodb web application - mongo philly 2011MongoDB
 
First app online conf
First app   online confFirst app   online conf
First app online confMongoDB
 
20110514 mongo dbチューニング
20110514 mongo dbチューニング20110514 mongo dbチューニング
20110514 mongo dbチューニングYuichi Matsuo
 
MongoDB dla administratora
MongoDB dla administratora MongoDB dla administratora
MongoDB dla administratora 3camp
 
はじめてのMongoDB
はじめてのMongoDBはじめてのMongoDB
はじめてのMongoDBTakahiro Inoue
 
How to calculate the optimal undo retention in Oracle
How to calculate the optimal undo retention in OracleHow to calculate the optimal undo retention in Oracle
How to calculate the optimal undo retention in OracleJorge Batista
 
Having fun with graphs, a short introduction to D3.js
Having fun with graphs, a short introduction to D3.jsHaving fun with graphs, a short introduction to D3.js
Having fun with graphs, a short introduction to D3.jsMichael Hackstein
 
MySQL flexible schema and JSON for Internet of Things
MySQL flexible schema and JSON for Internet of ThingsMySQL flexible schema and JSON for Internet of Things
MySQL flexible schema and JSON for Internet of ThingsAlexander Rubin
 
The Web map stack on Django
The Web map stack on DjangoThe Web map stack on Django
The Web map stack on DjangoPaul Smith
 

Tendances (20)

10. R getting spatial
10.  R getting spatial10.  R getting spatial
10. R getting spatial
 
Webinar: Exploring the Aggregation Framework
Webinar: Exploring the Aggregation FrameworkWebinar: Exploring the Aggregation Framework
Webinar: Exploring the Aggregation Framework
 
Integration of Google-map in Rails Application
Integration of Google-map in Rails ApplicationIntegration of Google-map in Rails Application
Integration of Google-map in Rails Application
 
Litebox
LiteboxLitebox
Litebox
 
Fun with D3.js: Data Visualization Eye Candy with Streaming JSON
Fun with D3.js: Data Visualization Eye Candy with Streaming JSONFun with D3.js: Data Visualization Eye Candy with Streaming JSON
Fun with D3.js: Data Visualization Eye Candy with Streaming JSON
 
Pycon2011
Pycon2011Pycon2011
Pycon2011
 
The Aggregation Framework
The Aggregation FrameworkThe Aggregation Framework
The Aggregation Framework
 
Nosh slides mongodb web application - mongo philly 2011
Nosh slides   mongodb web application - mongo philly 2011Nosh slides   mongodb web application - mongo philly 2011
Nosh slides mongodb web application - mongo philly 2011
 
First app online conf
First app   online confFirst app   online conf
First app online conf
 
20110514 mongo dbチューニング
20110514 mongo dbチューニング20110514 mongo dbチューニング
20110514 mongo dbチューニング
 
MongoDB dla administratora
MongoDB dla administratora MongoDB dla administratora
MongoDB dla administratora
 
はじめてのMongoDB
はじめてのMongoDBはじめてのMongoDB
はじめてのMongoDB
 
Scrollytelling
ScrollytellingScrollytelling
Scrollytelling
 
Talk MongoDB - Amil
Talk MongoDB - AmilTalk MongoDB - Amil
Talk MongoDB - Amil
 
How to calculate the optimal undo retention in Oracle
How to calculate the optimal undo retention in OracleHow to calculate the optimal undo retention in Oracle
How to calculate the optimal undo retention in Oracle
 
Having fun with graphs, a short introduction to D3.js
Having fun with graphs, a short introduction to D3.jsHaving fun with graphs, a short introduction to D3.js
Having fun with graphs, a short introduction to D3.js
 
MySQL flexible schema and JSON for Internet of Things
MySQL flexible schema and JSON for Internet of ThingsMySQL flexible schema and JSON for Internet of Things
MySQL flexible schema and JSON for Internet of Things
 
The Web map stack on Django
The Web map stack on DjangoThe Web map stack on Django
The Web map stack on Django
 
Fact, Fiction, and FP
Fact, Fiction, and FPFact, Fiction, and FP
Fact, Fiction, and FP
 
Lenses
LensesLenses
Lenses
 

Similaire à Geospatial Enhancements in MongoDB 2.4

OSCON july 2011
OSCON july 2011OSCON july 2011
OSCON july 2011chelm
 
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...MongoDB
 
Conceptos básicos. Seminario web 5: Introducción a Aggregation Framework
Conceptos básicos. Seminario web 5: Introducción a Aggregation FrameworkConceptos básicos. Seminario web 5: Introducción a Aggregation Framework
Conceptos básicos. Seminario web 5: Introducción a Aggregation FrameworkMongoDB
 
Handling Real-time Geostreams
Handling Real-time GeostreamsHandling Real-time Geostreams
Handling Real-time Geostreamsguest35660bc
 
Handling Real-time Geostreams
Handling Real-time GeostreamsHandling Real-time Geostreams
Handling Real-time GeostreamsRaffi Krikorian
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsMongoDB
 
Geospatial Graphs made easy with OrientDB - Codemotion Warsaw 2016
Geospatial Graphs made easy with OrientDB - Codemotion Warsaw 2016Geospatial Graphs made easy with OrientDB - Codemotion Warsaw 2016
Geospatial Graphs made easy with OrientDB - Codemotion Warsaw 2016Luigi Dell'Aquila
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs偉格 高
 
2013-03-23 - NoSQL Spartakiade
2013-03-23 - NoSQL Spartakiade2013-03-23 - NoSQL Spartakiade
2013-03-23 - NoSQL SpartakiadeJohannes Hoppe
 
Webinar: Data Processing and Aggregation Options
Webinar: Data Processing and Aggregation OptionsWebinar: Data Processing and Aggregation Options
Webinar: Data Processing and Aggregation OptionsMongoDB
 
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based ServicesDas Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based ServicesStephan Schmidt
 
GeoTechTalk InkSatogaeri Project
GeoTechTalk InkSatogaeri ProjectGeoTechTalk InkSatogaeri Project
GeoTechTalk InkSatogaeri ProjectKentaro Ishimaru
 
CouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 HourCouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 HourPeter Friese
 
Mongoskin - Guilin
Mongoskin - GuilinMongoskin - Guilin
Mongoskin - GuilinJackson Tian
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation FrameworkCaserta
 
2014 bigdatacamp asya_kamsky
2014 bigdatacamp asya_kamsky2014 bigdatacamp asya_kamsky
2014 bigdatacamp asya_kamskyData Con LA
 
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial IndexesBack to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial IndexesMongoDB
 
Introduction To PostGIS
Introduction To PostGISIntroduction To PostGIS
Introduction To PostGISmleslie
 

Similaire à Geospatial Enhancements in MongoDB 2.4 (20)

OSCON july 2011
OSCON july 2011OSCON july 2011
OSCON july 2011
 
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
 
Conceptos básicos. Seminario web 5: Introducción a Aggregation Framework
Conceptos básicos. Seminario web 5: Introducción a Aggregation FrameworkConceptos básicos. Seminario web 5: Introducción a Aggregation Framework
Conceptos básicos. Seminario web 5: Introducción a Aggregation Framework
 
Handling Real-time Geostreams
Handling Real-time GeostreamsHandling Real-time Geostreams
Handling Real-time Geostreams
 
Handling Real-time Geostreams
Handling Real-time GeostreamsHandling Real-time Geostreams
Handling Real-time Geostreams
 
Maps tek11
Maps tek11Maps tek11
Maps tek11
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev Teams
 
Geospatial Graphs made easy with OrientDB - Codemotion Warsaw 2016
Geospatial Graphs made easy with OrientDB - Codemotion Warsaw 2016Geospatial Graphs made easy with OrientDB - Codemotion Warsaw 2016
Geospatial Graphs made easy with OrientDB - Codemotion Warsaw 2016
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
 
2013-03-23 - NoSQL Spartakiade
2013-03-23 - NoSQL Spartakiade2013-03-23 - NoSQL Spartakiade
2013-03-23 - NoSQL Spartakiade
 
Webinar: Data Processing and Aggregation Options
Webinar: Data Processing and Aggregation OptionsWebinar: Data Processing and Aggregation Options
Webinar: Data Processing and Aggregation Options
 
Das Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based ServicesDas Web Wird Mobil - Geolocation und Location Based Services
Das Web Wird Mobil - Geolocation und Location Based Services
 
GeoTechTalk InkSatogaeri Project
GeoTechTalk InkSatogaeri ProjectGeoTechTalk InkSatogaeri Project
GeoTechTalk InkSatogaeri Project
 
CouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 HourCouchDB Mobile - From Couch to 5K in 1 Hour
CouchDB Mobile - From Couch to 5K in 1 Hour
 
Mongoskin - Guilin
Mongoskin - GuilinMongoskin - Guilin
Mongoskin - Guilin
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation Framework
 
2014 bigdatacamp asya_kamsky
2014 bigdatacamp asya_kamsky2014 bigdatacamp asya_kamsky
2014 bigdatacamp asya_kamsky
 
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial IndexesBack to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
 
dojo.Patterns
dojo.Patternsdojo.Patterns
dojo.Patterns
 
Introduction To PostGIS
Introduction To PostGISIntroduction To PostGIS
Introduction To PostGIS
 

Plus de MongoDB

MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB
 
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB
 
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 MongoDB SoCal 2020: MongoDB Atlas Jump Start MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB SoCal 2020: MongoDB Atlas Jump StartMongoDB
 
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB
 
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB
 
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB
 
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB
 
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB
 
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB
 
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB
 

Plus de MongoDB (20)

MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
 
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
 
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 MongoDB SoCal 2020: MongoDB Atlas Jump Start MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
 
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
 
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
 
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
 
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
 
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
 
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
 

Geospatial Enhancements in MongoDB 2.4

  • 1. Map the Globe, simply Polygon indexing and GeoJSON support in MongoDB Greg Studer greg@10gen.com mongoNYC 2013
  • 2. ● 2d vs 2dsphere ● (Quick) overview of previous geospatial features in MongoDB ● New line/polygon indexing on spherical globe GeoJSON - lines and polygons ● Geo in aggregation ● Future Roadmap
  • 3. Why use (2dsphere) geospatial indexing? 1. Have earth-like coordinates and regions tagged to other data over large areas 2. Want to query this data based on location 3. Don't necessarily want to think a lot about the fact that the earth is round
  • 4. [ from Jpatokal at wikimedia.org ] https://secure.wikimedia.org/wikipedia/commons/wiki/File:World-airline-routemap-2009.png
  • 5. [ from Jpatokal at wikimedia.org ] https://secure.wikimedia.org/wikipedia/commons/wiki/File:World-airline-routemap-2009.png
  • 7. Why use (2d) geospatial indexing? 1. Have regional or virtual world coordinates embedded in other data 2. (For now) Only indexing locations 3. Don't want spherical overhead
  • 8. Overview of geo features ● 2.2 - "2d" Index only (multi-)points Query near points or within simple polygons
  • 9. // Make a flat 2d index [-180 -> 180) > db.coll.ensureIndex( { location : "2d", type : 1 } ) // Insert some point data > db.coll.insert({ name : "Shake Shack", type : "rest", location : [ -73.9881353, 40.7415064 ] }) > db.coll.insert({ name : "Park Avenue Tavern", type : "bar", location : [ -73.9786924, 40.7502231 ] })
  • 10. // Find in Manhattan Mall > db.coll.find({ location : { $geoWithin : { $polygon : [[ -73.9884761, 40.7491204 ], [ -73.988829, 40.7486387 ], [ -73.9901297, 40.7491856 ], [ -73.9897768, 40.7496673 ], [ -73.9884761, 40.7491204 ]] }}}, type : "rest" }) // Find near Washington Square (center) > db.coll.find({ location : { $geoNear : [ -73.7695467, 42.6622728 ] }, type : "rest" });
  • 11. Overview of geo features ● 2.2 - "2d" DEMO - NYC OpenStreetMaps data github.com/mongodb/mongo-snippets/tree/master/2dsphere
  • 12. Overview of geo features ● Current 2.4 - "2dsphere" Index points, lines, and polygons (on sphere) Understands simple GeoJSON Query with points, lines, and polygons Within-region, Intersect-region, Near-point queries
  • 13. GeoJSON ● Widely supported open JSON standard http://www.geojson.org/ ● Simple language: { type : 'Point', coordinates : [<lon>, <lat>] } { type : 'LineString', coordinates : [[<lon>, <lat>],...] } { type : 'Polygon', coordinates : [[[<lon>,<lat>],...],...]} + other MultiXXX types (future) ...
  • 14. // Make a spherical 2d compound index > db.coll.ensureIndex( { type : 1, location : "2dsphere" } ) // Insert Park Avenue > db.coll.insert( { name : "Park Avenue", type : "road", location : { type : 'LineString', coordinates : [ [ -73.9359712600708, 40.80942429324451], [ -73.93676519393921, 40.80820620367037], ... ]} });
  • 15. // Insert Great Hill > db.coll.insert( { name : "Great Hill", type : "park", location : { type : 'Polygon', coordinates : [[ [ -73.95841598510742, 40.79724239132546], [ -73.95817995071411, 40.79691751000055], ... ]]} });
  • 16. // Find docs with geometry that intersects // a route > db.coll.find({ location : { $geoIntersects : { $geometry : { type : 'LineString', // Run coordinates coordinates : [ [ -73.95586252212524, 40.77964777966238 ], [ -73.95886659622192, 40.78091513739611 ], ... ]} }}})
  • 17. Overview of geo features ● Current 2.4 - "2dsphere" DEMO - NYC OpenStreetMaps data github.com/mongodb/mongo-snippets/tree/master/2dsphere
  • 18. Overview of geo features ● Current 2.4 - "2dsphere" Reduced shape distortion DEMO - NYC OpenStreetMaps data github.com/mongodb/mongo-snippets/tree/master/2dsphere
  • 19. Technology ● GeoJSON http://www.geojson.org ● Google S2 Geometry Library Apache License 2.0 http://code.google.com/p/s2-geometry-library image by user geek3 @ http://en. wikipedia.org/wiki/File: Sphere_wireframe_10deg_6r.svg
  • 20. S2
  • 22. ● 2d vs 2dsphere ● (Quick) overview of previous geospatial features in MongoDB ● New line/polygon indexing on spherical globe GeoJSON - lines and polygons ● Geo in aggregation ● Future Roadmap
  • 23. Overview of geo features ● Current 2.4 - aggregation support Geospatial predicates in aggregation Near sorting in aggregation, custom output fields
  • 24. > db.ny.aggregate([ // Find everything in MidTown/Hell's Kitchen { $match : { geo: { $geoWithin: { $geometry: { type: "Polygon", coordinates: [[ // Midtown/Hell's Kitchen [ -73.9984130859375, 40.78028146155187 ], [ -73.95240783691406, 40.76182096906601 ], [ -73.96888732910156, 40.73945350425846 ], [ -74.01420593261719, 40.75531957477602 ], [ -73.9984130859375, 40.78028146155187 ] ]] } } } } }, ...
  • 25. ... // Organize stuff we want { $project : { tags : 1, info : { name : "$name", lonLat : "$geo.coordinates" }} }, { $unwind : "$tags" }, // Count by tag types { $group : { _id : "$tags", total : { $sum : 1 }, locs : { $push : "$info" } }} ]); // end
  • 26. { "result" : [ { "_id" : "park", "total" : 18, "locs" : [{ "name" : "Hells Kitchen Park", "lonLat" : [ -73.9925, 40.7630556 ] }, ... { "_id" : "bar", "total" : 28, "locs" : [ { "name" : "Landmark Tavern", "lonLat" : [ -73.9963261, 40.7631922 ] }, { "name" : "Pony Bar", "lonLat" : [ -73.994236, 40.761723 ] }, ... ...
  • 27. > db.ny.aggregate([ // Find near Times Square { $geoNear : { near : { type: "Point", // Times Square coordinates: [ -73.98508787155151, 40.75905795418586 ] }, distanceField : "distance", spherical : true, // 2dsphere num : 1000 } }, ...
  • 28. ... // Organize stuff we want { $project : { tags : 1, info : { name : "$name", distance : "$distance", lonLat : "$geo.coordinates" }} }, { $unwind : "$tags" }, // Count by tag types { $group : { _id : "$tags", total : { $sum : 1 }, locs : { $push : "$info" } }} ]); // end ...
  • 29. { "result" : [ { "_id" : "park", "total" : 11, "locs" : [{ "name" : "Ramone Aponte Park", "distance" : 449.7417003854033, // m "lonLat" : [ -73.9894444, 40.7613889 ]}, ... { "_id" : "bar", "total" : 24, "locs" : [{ "name" : "The Lambs Club", "distance" : 275.0270424641914, // m "lonLat" : [ -73.9963261, 40.7631922 ]}, ... ...
  • 30. [ from Jpatokal at wikimedia.org ] https://secure.wikimedia.org/wikipedia/commons/wiki/File:World-airline-routemap-2009.png
  • 31. Future ● Further support for other predicates OGC Simple Features ● GeoJSON composite shapes ● Indexing API to allow similar enhancements for "flat plane" work ● Space open for non-default CRSes