原文地址: https://www.elastic.co/guide/cn/elasticsearch/guide/current/indexing-geo-shapes.html, 版权归 www.elastic.co 所有
英文版地址: https://www.elastic.co/guide/en/elasticsearch/guide/current/indexing-geo-shapes.html
英文版地址: https://www.elastic.co/guide/en/elasticsearch/guide/current/indexing-geo-shapes.html
请注意:
本书基于 Elasticsearch 2.x 版本,有些内容可能已经过时。
本书基于 Elasticsearch 2.x 版本,有些内容可能已经过时。
索引地理形状 (Indexing Geo Shapes)edit
地理形状通过 GeoJSON 来表示,这是一种开放的使用 JSON 实现的二维形状编码方式。
每个形状都包含了形状类型: 点(point), 线(line), 多边形(polygon), 包络面(envelope), 以及一个或多个经纬度坐标集合的数组。
在 GeoJSON 里,经纬度表示方式通常是 纬度 在前, 经度 在后。
如,我们用一个多边形(polygon )来索引阿姆斯特丹的达姆广场:
PUT /attractions/landmark/dam_square
{
"name" : "Dam Square, Amsterdam",
"location" : {
"type" : "polygon",
"coordinates" : [[
[ 4.89218, 52.37356 ],
[ 4.89205, 52.37276 ],
[ 4.89301, 52.37274 ],
[ 4.89392, 52.37250 ],
[ 4.89431, 52.37287 ],
[ 4.89331, 52.37346 ],
[ 4.89305, 52.37326 ],
[ 4.89218, 52.37356 ]
]]
}
}
上例中大量的方括号可能看起来让人困惑,不过实际上 GeoJSON 的语法非常简单:
-
用一个数组表示
经纬度坐标点:[lon,lat]
-
一组坐标点放到一个数组来表示一个多边形:
[[lon,lat],[lon,lat], ... ]
-
一个多边形(
polygon)可以包含多个多边形;第一个表示多边形的外轮廓,后续的多边形表示第一个多边形内部的空洞:[ [[lon,lat],[lon,lat], ... ], # main polygon [[lon,lat],[lon,lat], ... ], # hole in main polygon ... ]
参见 Geo-shape mapping documentation 了解更多支持的形状。