SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

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

OSCON july 2011
OSCON july 2011OSCON july 2011
OSCON july 2011
chelm
 

Semelhante a 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
 

Mais de MongoDB

Mais 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...
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 

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

Notas do Editor

  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