elasticsearch - 弹性:存储“FeatureCollection”类型的 GeoJSON,并进行查询
问题描述
我使用Elastic 7.x来存储这样的文档:
{
"id": "polygon_tests_01.ast-ORTHOMOSAIC",
"name": "tmpl_integration_test_GeoTIFF",
"region": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"coordinates": [[[-149.67474372431124,61.27942558978003],
[-149.65726554157862,60.993770332779064],
[-150.11544465434918,61.15680203118899],
[-149.87699170822603,61.28122531469481],
[-149.67474372431124,61.27942558978003]]],
"type": "Polygon"
},
"properties": {}
}
],
"type": "Feature",
"properties": {}
}
... more data...
}
试图为它创建一个映射,我使用:
{
"mappings": {
"properties": {
"region": {
"properties": {
"features": {
"properties": {
"geometry": {
"type": "geo_shape"
}
}
}
}
}
}
}
}
首先 - 这是正确的映射方式吗?
其次,假设我想创建一个查询,从具有相交“区域”的弹性所有文档中提取。我使用这个查询:
{
"query": {
"geo_shape": {
"region.features.geometry": {
"relation": "intersects",
"shape": {
"type": "polygon",
"coordinates": [[[10.526270711323841,10.444489244321758],
[11.925063668547947,10.371171909552444],
[11.070002142972083,9.364612094349482],
[10.526270711323841,10.444489244321758]
]]
}
}
}
}
}
唉,我得到一个错误:
failed to find geo_shape field [region.features.geometry]
那么如何存储“标准化”类型的 GeoJSONFeatureCollection
并进行下降查询呢?
解决方案
ES 确实支持,但需要GeometryCollections
进行一些预处理。
使用最小可重现索引设置:
PUT geoindex
{
"mappings": {
"properties": {
"regions": {
"type": "geo_shape"
}
}
}
}
提取features
以符合 w/
POST geoindex/_doc
{
"id": "polygon_tests_01.ast-ORTHOMOSAIC",
"name": "tmpl_integration_test_GeoTIFF",
"regions": {
"type": "geometrycollection",
"geometries": [
{
"type": "polygon",
"coordinates": [[[-149.67474372431124,61.27942558978003],[-149.65726554157862,60.993770332779064],[-150.11544465434918,61.15680203118899],[-149.87699170822603,61.28122531469481],[-149.67474372431124,61.27942558978003]]]
}
]
}
}
请注意,它regions.geometries
可以包含多个 geojson 特征,而不仅仅是多边形。
之后,我们可以查询多边形相交:
POST geoindex/_search
{
"query": {
"geo_shape": {
"regions": {
"relation": "intersects",
"shape": {
"type": "polygon",
"coordinates": [[[-149.68734741210938,61.34276125480617],[-149.78347778320312,61.268912537559316],[-149.53628540039062,61.18628656437939],[-149.37286376953125,61.29662618671741],[-149.4085693359375,61.3671195097931],[-149.65164184570312,61.37962043716795],[-149.68734741210938,61.34276125480617]]]
}
}
}
}
}
注意:您的索引多边形位于安克雷奇,AK,而查询中的多边形位于尼日利亚东部。两者不会重叠:)
推荐阅读
- bash - 如何不列出“。” 和 curl 命令中的“..”:“ curl -l ftp:”
- c# - 如何使用 foreach 循环在列表中的短语之间添加分隔符?
- android - 特定设备androidx中的searchview问题
- datepicker - 仅限月份的 Quicksight 日期选择器
- java - 在java中使用FUTURA字体创建pdf
- r - 交叉R中的相似词
- ibm-mobilefirst - 使用域 mfp 8 服务器使用真实移动设备返回“请求超时”?
- java - 如何循环浏览我创建的砖块图形?
- c - C - 为字符串中的每个字符打印 ASCII 值
- java - 如何使用这些带有 java 文件名的源文件?