SlideShare a Scribd company logo
1 of 31
@mongodb @idbentley @10gen




MongoDB 2.4 Geo
Features
Ian Bentley
Web Engineer, 10gen
Planar Geometry
         2.4 Geospatial features – Ian Bentley
xkcd.com/977


Spherical Geometry
         2.4 Geospatial features – Ian Bentley
MongoDB has had geo for a
while
• `2d` index
   – Store points on 2d plane
   – Search for points within a:
      • Rectangle ($box)
      • Polygon ($polygon)
      • Circle ($center)
      • Circle on a sphere ($centerSphere)
   – Search for nearest points ($near, $nearSphere)




                      2.4 Geospatial features – Ian Bentley
Some desirable things!
• Storing non-point geometries
• Within searches on a sphere
• Searching for intersecting geometries on a
 sphere
• Better support for compound indexes




                 2.4 Geospatial features – Ian Bentley
Storing non-point geometries
• GeoJSON – A collaborative community project
 that produced a specification for encoding
 geometric entities in JSON
• Gaining wide support
  – OpenLayers
  – PostGIS
  – Libraries in several languages




                    2.4 Geospatial features – Ian Bentley
GeoJSON allows us to
encode
Points:


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




                     2.4 Geospatial features – Ian Bentley
GeoJSON allows us to
encode
LineStrings:


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




                    2.4 Geospatial features – Ian Bentley
GeoJSON allows us to
encode
Polygons:


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


                          2.4 Geospatial features – Ian Bentley
Within searches on a sphere
• $geoWithin operator
• Takes a GeoJSON polygon geometry as a
 specifier
• Returns any geometries of any type that are fully
 contained within the polygon
• Works without any index.




                  2.4 Geospatial features – Ian Bentley
Intersecting geometries on a
sphere
• $geoIntersects operator
• Takes any GeoJSON geometry as a specifier
• Returns any geometries that have a non-empty
 intersection
• Lots of edge cases – intersecting edges, points
 on lines.
• Works without any index.



                  2.4 Geospatial features – Ian Bentley
Better support for compound
indexes
• Unlike 2d indexes, 2dsphere indexes aren’t
 required to be the first field of a compound index
   – Filtering potential documents before doing geo query can
     drastically improve the performance of some queries
      • “Find me Hot Dog Stands within New York state”
      • “Find me geometries in New York state that are
        Hot Dog Stands”
• Multiple geo fields can be in the same index
   – “Find routes with start location 50miles from JFK and end
     location 100miles from YYC”

                     2.4 Geospatial features – Ian Bentley
Demo Example
• You can find all the code, and data powering the
 demo on github, and read about it on my blog
• Let’s take a close look at the python that does
 the actual work.




                    2.4 Geospatial features – Ian Bentley
It’s this simple - within
def find_within(points):
   # When defining a polygon, the first point should
   # also appear as the last point.
   points.append(points[0])
   poly = {
        "type": "Polygon",
        "coordinates": [points]
   }
   places = collection.find(
       {"geo": { "$within": { "$geometry": poly } } } )
   places.limit(500)
   return places
                       2.4 Geospatial features – Ian Bentley
It’s this simple - intersects
def find_intersects(points):
   line = {
       "type": "LineString",
       "coordinates": points
       }
   places = collection.find(
       {"geo":{ "$geoIntersects":
           { "$geometry": line } } } )
   places.limit(50)
   return places




                      2.4 Geospatial features – Ian Bentley
It’s this simple - near
def find_nearest(point):
   point = {
            "type": "Point",
            "coordinates": point
            }
   places = collection.find(
       {"geo": { "$near": { "$geometry": point } } })
   places.limit(10)
   return places




                      2.4 Geospatial features – Ian Bentley
How 2dsphere works
How do you index a spherical
coordinate?
• Divide the geometry that you are indexing into a
 grid.
• For each cell in the grid, calculate a key, based
 upon its position on the sphere.
• Insert each cell into a standard B-tree
• MongoDB uses google’s S2 C++ library for the
 heavy lifting.


                  2.4 Geospatial features – Ian Bentley
Coarse Grid overlayed on the
UK
          2.4 Geospatial features – Ian Bentley
Coverings
• A covering of a geometry is a minimal set of cells
 that completely cover’s a geometry
• S2 can efficiently generate coverings for arbitrary
 geometries.




                  2.4 Geospatial features – Ian Bentley
Covering of Grid of the UK
         2.4 Geospatial features – Ian Bentley
Covering of A4 surrounding
Trafalgar Square
          2.4 Geospatial features – Ian Bentley
Cells
• S2 defines cell sizes from level 1 to level 31
• The higher the level, the smaller the cell
• Different levels are optimized for different queries
   – If you have densely packed geometries, and you are
     doing a $near search, a higher level will be efficient
   – If you are doing a $within search with a large polygon, a
     lower level will be more efficient
• By default we use all levels between 500m and
 100km on a side

                      2.4 Geospatial features – Ian Bentley
Near search
         2.4 Geospatial features – Ian Bentley
Near search
         2.4 Geospatial features – Ian Bentley
Near search
         2.4 Geospatial features – Ian Bentley
Near search
         2.4 Geospatial features – Ian Bentley
Near search
         2.4 Geospatial features – Ian Bentley
Near search
         2.4 Geospatial features – Ian Bentley
Q&A

More Related Content

Similar to Webinar: MongoDB 2.4 Feature Demo and Q&A on Geo Capabilities

OSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross LawleyOSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross LawleyNETWAYS
 
Efficient Query Processing in Geographic Web Search Engines
Efficient Query Processing in Geographic Web Search EnginesEfficient Query Processing in Geographic Web Search Engines
Efficient Query Processing in Geographic Web Search EnginesYen-Yu Chen
 
The Latest in Spatial & Temporal Search: Presented by David Smiley
The Latest in Spatial & Temporal Search: Presented by David SmileyThe Latest in Spatial & Temporal Search: Presented by David Smiley
The Latest in Spatial & Temporal Search: Presented by David SmileyLucidworks
 
Lucene solr 4 spatial extended deep dive
Lucene solr 4 spatial   extended deep diveLucene solr 4 spatial   extended deep dive
Lucene solr 4 spatial extended deep divelucenerevolution
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleMongoDB
 
Webinar: Building Your First Application with MongoDB
Webinar: Building Your First Application with MongoDBWebinar: Building Your First Application with MongoDB
Webinar: Building Your First Application with MongoDBMongoDB
 
2012 URISA Track, Geologic Mapping 101: Common Pitfalls and Suggestions for a...
2012 URISA Track, Geologic Mapping 101: Common Pitfalls and Suggestions for a...2012 URISA Track, Geologic Mapping 101: Common Pitfalls and Suggestions for a...
2012 URISA Track, Geologic Mapping 101: Common Pitfalls and Suggestions for a...GIS in the Rockies
 
Geoindexing with MongoDB
Geoindexing with MongoDBGeoindexing with MongoDB
Geoindexing with MongoDBleafnode
 
PostGIS and Spatial SQL
PostGIS and Spatial SQLPostGIS and Spatial SQL
PostGIS and Spatial SQLTodd Barr
 
OSCON july 2011
OSCON july 2011OSCON july 2011
OSCON july 2011chelm
 

Similar to Webinar: MongoDB 2.4 Feature Demo and Q&A on Geo Capabilities (12)

OSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross LawleyOSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
 
Efficient Query Processing in Geographic Web Search Engines
Efficient Query Processing in Geographic Web Search EnginesEfficient Query Processing in Geographic Web Search Engines
Efficient Query Processing in Geographic Web Search Engines
 
The Latest in Spatial & Temporal Search: Presented by David Smiley
The Latest in Spatial & Temporal Search: Presented by David SmileyThe Latest in Spatial & Temporal Search: Presented by David Smiley
The Latest in Spatial & Temporal Search: Presented by David Smiley
 
Lucene solr 4 spatial extended deep dive
Lucene solr 4 spatial   extended deep diveLucene solr 4 spatial   extended deep dive
Lucene solr 4 spatial extended deep dive
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You Scale
 
Webinar: Building Your First Application with MongoDB
Webinar: Building Your First Application with MongoDBWebinar: Building Your First Application with MongoDB
Webinar: Building Your First Application with MongoDB
 
2012 URISA Track, Geologic Mapping 101: Common Pitfalls and Suggestions for a...
2012 URISA Track, Geologic Mapping 101: Common Pitfalls and Suggestions for a...2012 URISA Track, Geologic Mapping 101: Common Pitfalls and Suggestions for a...
2012 URISA Track, Geologic Mapping 101: Common Pitfalls and Suggestions for a...
 
Geoindexing with MongoDB
Geoindexing with MongoDBGeoindexing with MongoDB
Geoindexing with MongoDB
 
Day 6 - PostGIS
Day 6 - PostGISDay 6 - PostGIS
Day 6 - PostGIS
 
Jquery2012 defs
Jquery2012 defsJquery2012 defs
Jquery2012 defs
 
PostGIS and Spatial SQL
PostGIS and Spatial SQLPostGIS and Spatial SQL
PostGIS and Spatial SQL
 
OSCON july 2011
OSCON july 2011OSCON july 2011
OSCON july 2011
 

More from 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
 

More from 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...
 

Recently uploaded

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 

Recently uploaded (20)

Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 

Webinar: MongoDB 2.4 Feature Demo and Q&A on Geo Capabilities

  • 1. @mongodb @idbentley @10gen MongoDB 2.4 Geo Features Ian Bentley Web Engineer, 10gen
  • 2. Planar Geometry 2.4 Geospatial features – Ian Bentley
  • 3. xkcd.com/977 Spherical Geometry 2.4 Geospatial features – Ian Bentley
  • 4. MongoDB has had geo for a while • `2d` index – Store points on 2d plane – Search for points within a: • Rectangle ($box) • Polygon ($polygon) • Circle ($center) • Circle on a sphere ($centerSphere) – Search for nearest points ($near, $nearSphere) 2.4 Geospatial features – Ian Bentley
  • 5. Some desirable things! • Storing non-point geometries • Within searches on a sphere • Searching for intersecting geometries on a sphere • Better support for compound indexes 2.4 Geospatial features – Ian Bentley
  • 6. Storing non-point geometries • GeoJSON – A collaborative community project that produced a specification for encoding geometric entities in JSON • Gaining wide support – OpenLayers – PostGIS – Libraries in several languages 2.4 Geospatial features – Ian Bentley
  • 7. GeoJSON allows us to encode Points: { geo: { type: "Point", coordinates: [100.0, 0.0] } } 2.4 Geospatial features – Ian Bentley
  • 8. GeoJSON allows us to encode LineStrings: { geo: { type: "LineString", coordinates: [ [100.0, 0.0], [101.0, 1.0] ] } } 2.4 Geospatial features – Ian Bentley
  • 9. GeoJSON allows us to encode Polygons: { geo: { type: "Polygon", coordinates: [ [ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ] ] } } 2.4 Geospatial features – Ian Bentley
  • 10. Within searches on a sphere • $geoWithin operator • Takes a GeoJSON polygon geometry as a specifier • Returns any geometries of any type that are fully contained within the polygon • Works without any index. 2.4 Geospatial features – Ian Bentley
  • 11. Intersecting geometries on a sphere • $geoIntersects operator • Takes any GeoJSON geometry as a specifier • Returns any geometries that have a non-empty intersection • Lots of edge cases – intersecting edges, points on lines. • Works without any index. 2.4 Geospatial features – Ian Bentley
  • 12. Better support for compound indexes • Unlike 2d indexes, 2dsphere indexes aren’t required to be the first field of a compound index – Filtering potential documents before doing geo query can drastically improve the performance of some queries • “Find me Hot Dog Stands within New York state” • “Find me geometries in New York state that are Hot Dog Stands” • Multiple geo fields can be in the same index – “Find routes with start location 50miles from JFK and end location 100miles from YYC” 2.4 Geospatial features – Ian Bentley
  • 14. • You can find all the code, and data powering the demo on github, and read about it on my blog • Let’s take a close look at the python that does the actual work. 2.4 Geospatial features – Ian Bentley
  • 15. It’s this simple - within def find_within(points): # When defining a polygon, the first point should # also appear as the last point. points.append(points[0]) poly = { "type": "Polygon", "coordinates": [points] } places = collection.find( {"geo": { "$within": { "$geometry": poly } } } ) places.limit(500) return places 2.4 Geospatial features – Ian Bentley
  • 16. It’s this simple - intersects def find_intersects(points): line = { "type": "LineString", "coordinates": points } places = collection.find( {"geo":{ "$geoIntersects": { "$geometry": line } } } ) places.limit(50) return places 2.4 Geospatial features – Ian Bentley
  • 17. It’s this simple - near def find_nearest(point): point = { "type": "Point", "coordinates": point } places = collection.find( {"geo": { "$near": { "$geometry": point } } }) places.limit(10) return places 2.4 Geospatial features – Ian Bentley
  • 19. How do you index a spherical coordinate? • Divide the geometry that you are indexing into a grid. • For each cell in the grid, calculate a key, based upon its position on the sphere. • Insert each cell into a standard B-tree • MongoDB uses google’s S2 C++ library for the heavy lifting. 2.4 Geospatial features – Ian Bentley
  • 20. Coarse Grid overlayed on the UK 2.4 Geospatial features – Ian Bentley
  • 21. Coverings • A covering of a geometry is a minimal set of cells that completely cover’s a geometry • S2 can efficiently generate coverings for arbitrary geometries. 2.4 Geospatial features – Ian Bentley
  • 22. Covering of Grid of the UK 2.4 Geospatial features – Ian Bentley
  • 23. Covering of A4 surrounding Trafalgar Square 2.4 Geospatial features – Ian Bentley
  • 24. Cells • S2 defines cell sizes from level 1 to level 31 • The higher the level, the smaller the cell • Different levels are optimized for different queries – If you have densely packed geometries, and you are doing a $near search, a higher level will be efficient – If you are doing a $within search with a large polygon, a lower level will be more efficient • By default we use all levels between 500m and 100km on a side 2.4 Geospatial features – Ian Bentley
  • 25. Near search 2.4 Geospatial features – Ian Bentley
  • 26. Near search 2.4 Geospatial features – Ian Bentley
  • 27. Near search 2.4 Geospatial features – Ian Bentley
  • 28. Near search 2.4 Geospatial features – Ian Bentley
  • 29. Near search 2.4 Geospatial features – Ian Bentley
  • 30. Near search 2.4 Geospatial features – Ian Bentley
  • 31. Q&A

Editor's Notes

  1. Hit Record and make sure it recordsOpen your demo.Move your mouse.Make announcement about QA five minutes before and as you start
  2. This is 6th grade geometry on the cartesian plane. Often called (inexactly) Euclidean geometryAn plane is infinite in all directions. This is a convenient way of reasoning about geometry because math on the plane is easy. As a simplification of a sphere, however, it has pretty big problems as soon as you start to worry about large polygons, long lines, or any degree of accuracy.
  3. As is excellently highlighted by Randall Munroe of xkcd, projecting a sphere onto a plane is non-obvious. It’s similarly not easy the other direction.Managing the math for sphere’s is much more difficult than on a plane, and definitely not something most of us want to implement.
  4. The 2d index was introduced in Mongodb 2.2End this slide by saying: “All this is great, but there are some additional features that we might like.”
  5. Points are great, but we want to store arbitrary polygons, lines, etc.
  6. Notice that the first point is the same as the last point.This is the simplest polygon form. The coordinate specification is a list of list of point specs. The first list of point specifications describes the exterior shell of the polygon, and each subsequent list of points describes a hole in the polygon.MongoDB will reject any polygons that self intersect with a parse error.
  7. Within searches on the plane with large polygons can be significantly different than on the sphere because they follow the curvature of the sphere.
  8. Re: edge cases: Some are documented on mongodb.org, but there are far too many to detail, so make sure to play around with your particular edge cases.
  9. If you have a collection of documents that are all the businesses in America, filtering for type Hot Dog Stand will reduce the set of results significantly, and searching for an exact match string compare on a normal mongo index is a very quick operation, compared to a geo index search. Because of that stating the question in the first order will be much faster than stating it in the second way.Indexing multiple geo fields was not possible between 2.4, and make possible a whole suite of queries that weren’t possible before.
  10. 1st point and 2nd point define the first line.2nd point and 3rd point define the second line.So on.
  11. $maxDistance operator is an optional operator that allows us to specify a maximum distance away from a point, which to go looking.
  12. Tricky bitsHow do you use that index efficiently?How do you decide the size of the cells? How do you calculate thebtree key
  13. Works by looking at concentric donuts starting from the center point.Here we are searching for pubs near a point on Leicester SquareNothing in donut 1
  14. The porcupine is within the second donut, but although the Brewmaster is within the covering for the second donut, it isn’t actually within the donut
  15. This continues until we have found enough points to fill a batch