问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

mongodb 3.2 geowithin 和 within的区别

发布网友 发布时间:2022-05-06 08:35

我来回答

2个回答

懂视网 时间:2022-05-06 12:56

Motivation Geometric processing as a field of study has many applications, and has resulted in lots of research, and powerful tools. Many modern web applications have location based components, and require a data storage engines capable of

Motivation

Geometric processing as a field of study has many applications, and has resulted in lots of research, and powerful tools. Many modern web applications have location based components, and require a data storage engines capable of managing geometric information. Typically this requires the introduction of an additional storage engine into your infrastructure, which can be a time consuming and expensive operation.

MongoDB has a set of geometric storage and search features. The MongoDB 2.4 release brought several improvements to MongoDB’s existing geo capabilities and the introduction of the 2dsphere index.

The primary conceptual difference (though there are also many functional differences) between the 2d and 2dsphere indexes, is the type of coordinate system that they consider. Planar coordinate systems are useful for certain applications, and can serve as a simplifying approximation of spherical coordinates. As you consider larger geometries, or consider geometries near the meridians and poles however, the requirement to use proper spherical coordinates becomes important.

In addition to this major conceptional difference, there are also significant functional differences, which are outlined in some depth in the Geospatial Indexes and Queries section of the MongoDB documentation. This post will discuss the new features that have been added in the 2.4 release.

What’s New

Storing non-point geometries

Unlike the 2d index, which only allowed the storage of points, the 2dsphere index allows the storage and querying of points, lines, and polygons. To support the storage of different geometries, instead of introducing a proprietary format, MongoDB conforms to the GeoJSON standard. GeoJSON is a collaborative community project that produced a specification for encoding entities in JSON. It has garnered significant support, including the OpenLayers project, PostGIS, and has growing language support for python and ruby.

Here are a few simple examples of GeoJSON embedded documents:

A BSON Document with a GeoJSON Point embedded in the geo field:

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

A BSON Document with a GeoJSON LineString embedded in the geo field:

 {
 geo: {
  type: “LineString”,
  coordinates: [ [100.0, 0.0], [101.0, 1.0] ]
 }
 }
A BSON Document with a GeoJSON Polygon embedded in the `geo` field:
 {
 geo: {
  type: “Polygon”,
  coordinates: [
  [ [100.0, 0.0], [101.0, 0.0],
   [101.0, 1.0], [100.0, 1.0],
   [100.0, 0.0] ]
  ]
 }
 }

Note: A GeoJSON Polygon’s coordinates are an array of arrays of point specifications. Each array of point specifications should have the same starting and ending point to form a closed loop. The first array of point specifications defines the polygon’s exterior geometry, and each subsequent array of point specifications defines a “hole” in the polygon. Polygons should be non self-intersecting, and holes should be fully contained by the polygon.

Inclusion searches on a sphere

The new $geoWithin operator, which takes a Polygon geometry as a specifier, returns any geometries of any type that are fully contained within the polygon. It will work well without any index, but must look at every document in the collection to do so.

Intersecting geometries on a sphere

The new $geoIntersects operator, which takes any geometry as a specifier, returns any geometries that have a non-empty intersection with the specifier. $geoIntersects also works well without an index, and must also look at each document in the collection.

Better support for compound indexes

The 2d index can only be used in a compound index if 1. it is the first field, 2. there are exactly two fields in the compound index, and 3. if the second field isn’t a 2d index. 2dsphere indexes aren’t limited in this way, which allows us to pre-filter based on a non-geo field - which is often more efficient.

Consider the following queries: Find me Hot Dog Stands in New York state i.e. use a compound index: (business_type, location). Find me geometries in New York state that are Hot Dog stands i.e. use the compound index: (location, business_type)

The first query will be much more efficient than the second, because business_type is a simple text field, and greatly reduces the set of geometries to search.

Additionally, we can have multiple 2dsphere indexes in the same compound index. This allows queries like: “Find routes with a start location within 50 miles from JFK, and an end location within 100 miles of YYC”.

How it Works

Everything starts when you insert a geometry into a 2dsphere index. We use the open source s2?C++ library?from google to select a minimal set of cells that fully cover a geometry. This set of grid cells is called a covering, and the size of the cells is dynamic (between 500m and 100km on a side) based upon the size of the polygon being covered.

image

fig 3 - A very low granularity covering of the entire United Kingdom

image

fig 4 - A fairly granular covering of the A4 around Trafalgar Square.?

Each cell in these coverings is now added to a standard B-tree index, with a key that is easily calculable by the location on surface of the sphere - more granular(smaller) cells will have the same prefix as a larger cell that occupies the same area of the surface of the sphere.

Intersection & Within searches

Finding geometries that may be intersecting or within a search polygon becomes as easy as generating a covering for the search specifier, and for each cell in that covering, query the B-tree for any geometries that interact with these cells. Once the list of possibly interacting geometries has been retrieved from the index, each geometry in checked in turn to see if it should be included in the result set.

Near searches

The near search provided by the $near operator is implemented by doing $within searches on concentrically growing donuts (circular polygons with with circular holes).

image?

We encourage user feedback and testing on these new Geo features and are excited to see what the community builds.

Map images ??OpenStreetMap?contributors, licensed under the Creative?Commons Attribution-ShareAlike 2.0?license (CC-BY-SA).?

Map data ??OpenStreetMap?contributors, licensed under the?Open Data Commons Open Database License?(ODbL).

热心网友 时间:2022-05-06 10:04

Deprecated since version 2.4: $geoWithin replaces $within in MongoDB 2.4.
以上是官方信息,区别就是被替代了,应该是没什么区别
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
想买红米但没银行卡 开美宜佳便利店是加盟好还是直接转一个美宜佳店好 ...就给你一个交易号,能到美宜佳付款,请问美宜佳是怎样付款的_百度知 ... 用美宜佳代购会不会看到我买的东西 重返帝国弓弩营对诸葛连弩有加成吗 重返帝国城市风格选什么好 重返帝国城市风格选择推荐 重返帝国城市风格怎么切换 重返帝国城市如何切换风格 重返帝国城市风格大全 特色兵种及增益介绍 重返帝国特殊兵种怎么生产-特殊兵种生产攻略 重返帝国怎么训练诸葛弩 储蓄国债电子式和凭证式的区别是什么? 看了文明礼仪小短片后的读后感 储蓄国债的发行对象什么 行政机关能否购买储蓄国债(电子式)? 有什么关于文明礼仪的相声,小品视频??? 求有关文明礼仪的视屏下载 农行信用卡20天没收到怎么办?挂失重新寄要多上时间? 信用卡补卡要多久,会寄送到哪? 小米手机怎么手动搜索网络 民生银行信用卡未收到第二次补发需要多久时间 您好,我的信用卡快一年未领取,现在银行说给我重新制卡补寄,需要多 电脑屏幕亮度? 请问农行的信用卡被退回,这个什么时候才能寄出?什么时候才能收到? win的名词是? 信用卡被退回重新申请邮寄需要多少天?一般银行重寄多少天没寄出? 请教各位~~~想找一句短话或者一个成语,以 jia 字开头 ,以 xin 字 结尾的,请各位赐教~ 广发银行信用卡邮寄我没有收到又退回去了,现在重新又邮寄了一张卡,需要多久到,我选的是加急送, 我的信用卡没收到被退回了黄石那边。已经电话客服申请重寄了。请问大概多久会重新邮寄? 找xin字开头的四字成语 xin字开头的词语有哪些 开发商做人防工程划算吗? 电子式储蓄国债只向个人投资者发售 中国的人防工程做得怎么样? 什么是人防系统,在什么单位工作啊,有前景吗 为什么用迅雷不能下载网页上的视频了? 人防商铺值得投资吗?买人防商铺为何不能贷款?如果使用权过了,怎么办? 人防工程三个效益是? 用迅雷下载网页上的视频不显示下载标志 人防工程可以做经营用吗 土豆网上的视频我怎么用迅雷下载不了啊 人防工程 属于什么行业,建筑吗?? 迅雷看看网页上的视频没办法下载,怎么下载?!! 迅雷7不能下载网页里的视频? 为什么现在迅雷助手无法下载网页中的视频了? 用什么方法能将网页上的视频下载下来 ??我拿迅雷下载的都是swf格式的,根本打不开 请高人指点!!! 急急急 结合自己的人生体验 .谈谈你对某个感兴趣的哲学家的哲学观点的认识 3000字左右的 藐视左手天才论 康德的观点对后世的影响是什么? 德国古典主义哲学 3000字左右 主题在 康德,费希特,谢林,黑格尔 这些相关均可。 什么是先验幻相