GeometryCollection Query
A GeoJSON GeometryCollection Query against any GeoJSON type.
Couchbase Server 7.1.2
QueryShape for a GeometryCollection Query
A GeoJSON query via a GeoShape of GeometryCollection to find GeoJSON types in a Search index using the 3 relations intersects, contains, and within.
GeometryCollection Intersects
Query
An intersect
query for geometrycollection returns all the matched documents with shapes that overlap with the area of any of the shapes in the geometrycollection array within the query.
A geometrycollection intersection
query sample is given below.
{
"query": {
"field": "<<fieldName>>",
"geometry": {
"shape": {
"type": "geometrycollection",
"geometries": [{
"type": "linestring",
"coordinates": [
[1.954764, 50.962097],
[3.029578, 49.868547]
]
}, {
"type": "multipolygon",
"coordinates": [
[
[
[-114.027099609375, 42.00848901572399],
[-114.04907226562499, 36.99377838872517],
[-109.05029296875, 36.99377838872517],
[-109.05029296875, 40.98819156349393],
[-111.060791015625, 40.98819156349393],
[-111.02783203125, 42.00848901572399],
[-114.027099609375, 42.00848901572399]
]
],
[
[
[-109.05029296875, 37.00255267215955],
[-102.041015625, 37.00255267215955],
[-102.041015625, 40.9964840143779],
[-109.05029296875, 40.9964840143779],
[-109.05029296875, 37.00255267215955]
]
]
]
}]
},
"relation": "intersects"
}
}
}
The intersection rules are similar to that of the respective shapes composed within the GeometryCollection array. The rules will be applied to any indexed GeoJSON shape in the array. If any of the query shapes within the geometries array intersects with any of the indexed shapes, then it will be a matching document.
GeometryCollection Contains
Query
A contains
query for geometrycollection returns all the matched documents with shapes that contain the geometrycollection within the query.
A geometrycollection contains
query sample is given below.
{{
"query": {
"field": "<<fieldName>>",
"geometry": {
"shape": {
"type": "geometrycollection",
"geometries": [{
"type": "linestring",
"coordinates": [
[1.954764, 50.962097],
[3.029578, 49.868547]
]
}, {
"type": "multipolygon",
"coordinates": [
[
[
[-114.027099609375, 42.00848901572399],
[-114.04907226562499, 36.99377838872517],
[-109.05029296875, 36.99377838872517],
[-109.05029296875, 40.98819156349393],
[-111.060791015625, 40.98819156349393],
[-111.02783203125, 42.00848901572399],
[-114.027099609375, 42.00848901572399]
]
],
[
[
[-109.05029296875, 37.00255267215955],
[-102.041015625, 37.00255267215955],
[-102.041015625, 40.9964840143779],
[-109.05029296875, 40.9964840143779],
[-109.05029296875, 37.00255267215955]
]
]
]
}]
},
"relation": "contains"
}
}
}
The containment rules are similar to that of the respective shapes composed within the GeometryCollection array. The rules will be applied to any indexed GeoJSON shape in the array. If all of the query shapes within the geometries array contained within any (cumulatively) of the indexed shapes completely, then it will be a matching document.
GeometryCollection WithIn
Query
The Within query is not supported by line geometries.
A within
query for geometrycollection returns all the matched documents with shapes that contain the geometrycollection within the query.
A geometrycollection contains
query sample is given below.
{
"query": {
"field": "<<fieldName>>",
"geometry": {
"shape": {
"type": "geometrycollection",
"geometries": [{
"type": "linestring",
"coordinates": [
[1.954764, 50.962097],
[3.029578, 49.868547]
]
}, {
"type": "multipolygon",
"coordinates": [
[
[
[-114.027099609375, 42.00848901572399],
[-114.04907226562499, 36.99377838872517],
[-109.05029296875, 36.99377838872517],
[-109.05029296875, 40.98819156349393],
[-111.060791015625, 40.98819156349393],
[-111.02783203125, 42.00848901572399],
[-114.027099609375, 42.00848901572399]
]
],
[
[
[-109.05029296875, 37.00255267215955],
[-102.041015625, 37.00255267215955],
[-102.041015625, 40.9964840143779],
[-109.05029296875, 40.9964840143779],
[-109.05029296875, 37.00255267215955]
]
]
]
}]
},
"relation": "within"
}
}
}
The within rules are similar to that of the respective shapes composed within the GeometryCollection array. The rules will be applied to any indexed GeoJSON shape in the array. If any of the query shapes within the geometries array contain any of the indexed shapes completely, then it will be a matching document.
Example GeometryCollection Query (against Points)
It is assumed that you your cluster has 1) a modified travel-sample with GeoJSON data and 2) a Search index as per Creating a GeoJSON Index via the REST API prior to running this example. |
Matches when the geometrycollection in the query contains the point in the document including points on the edge or coinciding with the vertices of the geometrycollection.
The results are specified to be sorted on name
. Note type hotel and landmark have a name field and type airport has an airportname field all these values are analyzed as a keyword (exposed as name
).
curl -s -XPOST -H "Content-Type: application/json" \
-u ${CB_USERNAME}:${CB_PASSWORD} http://${CB_HOSTNAME}:8094/api/index/test_geojson/query \
-d '{
"query": {
"field": "geojson",
"geometry": {
"shape": {
"type": "geometrycollection",
"geometries": [{
"type": "linestring",
"coordinates": [
[1.954764, 50.962097],
[3.029578, 49.868547]
]
}, {
"type": "multipolygon",
"coordinates": [
[
[
[-114.027099609375, 42.00848901572399],
[-114.04907226562499, 36.99377838872517],
[-109.05029296875, 36.99377838872517],
[-109.05029296875, 40.98819156349393],
[-111.060791015625, 40.98819156349393],
[-111.02783203125, 42.00848901572399],
[-114.027099609375, 42.00848901572399]
]
],
[
[
[-109.05029296875, 37.00255267215955],
[-102.041015625, 37.00255267215955],
[-102.041015625, 40.9964840143779],
[-109.05029296875, 40.9964840143779],
[-109.05029296875, 37.00255267215955]
]
]
]
}]
},
"relation": "intersects"
}
},
"size": 5,
"from": 0,
"sort": ["name"]
}' | jq .
The output of five (5) hits (from a total of 47 matching docs) is as follows
{
"status": {
"total": 1,
"failed": 0,
"successful": 1
},
"request": {
"query": {
"geometry": {
"shape": {
"type": "geometrycollection",
"geometries": [
{
"type": "linestring",
"coordinates": [
[
1.954764,
50.962097
],
[
3.029578,
49.868547
]
]
},
{
"type": "multipolygon",
"coordinates": [
[
[
[
-114.027099609375,
42.00848901572399
],
[
-114.04907226562499,
36.99377838872517
],
[
-109.05029296875,
36.99377838872517
],
[
-109.05029296875,
40.98819156349393
],
[
-111.060791015625,
40.98819156349393
],
[
-111.02783203125,
42.00848901572399
],
[
-114.027099609375,
42.00848901572399
]
]
],
[
[
[
-109.05029296875,
37.00255267215955
],
[
-102.041015625,
37.00255267215955
],
[
-102.041015625,
40.9964840143779
],
[
-109.05029296875,
40.9964840143779
],
[
-109.05029296875,
37.00255267215955
]
]
]
]
}
]
},
"relation": "intersects"
},
"field": "geojson"
},
"size": 5,
"from": 0,
"highlight": null,
"fields": null,
"facets": null,
"explain": false,
"sort": [
"name"
],
"includeLocations": false,
"search_after": null,
"search_before": null
},
"hits": [
{
"index": "test_geojson_3397081757afba65_4c1c5584",
"id": "airport_7001",
"score": 0.06568712770601859,
"sort": [
"Aspen Pitkin County Sardy Field"
]
},
{
"index": "test_geojson_3397081757afba65_4c1c5584",
"id": "airport_8854",
"score": 0.03222560611574136,
"sort": [
"Boulder Municipal"
]
},
{
"index": "test_geojson_3397081757afba65_4c1c5584",
"id": "airport_6999",
"score": 0.030963288954845132,
"sort": [
"Brigham City"
]
},
{
"index": "test_geojson_3397081757afba65_4c1c5584",
"id": "airport_7857",
"score": 0.06475045434251171,
"sort": [
"Bryce Canyon"
]
},
{
"index": "test_geojson_3397081757afba65_4c1c5584",
"id": "airport_3567",
"score": 0.03222560611574136,
"sort": [
"Buckley Afb"
]
}
],
"total_hits": 47,
"max_score": 0.23169125425271897,
"took": 32362669,
"facets": null
}
Example GeometryCollection Query (against Circles)
It is assumed that you your cluster has 1) a modified travel-sample with GeoJSON data and 2) a Search index as per Creating a GeoJSON Index via the REST API prior to running this example. |
Intersects when the query geometrycollection intersects the circular region in the document.
The results are specified to be sorted on name
. Note type hotel and landmark have a name field and type airport has an airportname field all these values are analyzed as a keyword (exposed as name
).
curl -s -XPOST -H "Content-Type: application/json" \
-u ${CB_USERNAME}:${CB_PASSWORD} http://${CB_HOSTNAME}:8094/api/index/test_geojson/query \
-d '{
"query": {
"field": "geoarea",
"geometry": {
"shape": {
"type": "geometrycollection",
"geometries": [{
"type": "linestring",
"coordinates": [
[1.954764, 50.962097],
[3.029578, 49.868547]
]
}, {
"type": "multipolygon",
"coordinates": [
[
[
[-114.027099609375, 42.00848901572399],
[-114.04907226562499, 36.99377838872517],
[-109.05029296875, 36.99377838872517],
[-109.05029296875, 40.98819156349393],
[-111.060791015625, 40.98819156349393],
[-111.02783203125, 42.00848901572399],
[-114.027099609375, 42.00848901572399]
]
],
[
[
[-109.05029296875, 37.00255267215955],
[-102.041015625, 37.00255267215955],
[-102.041015625, 40.9964840143779],
[-109.05029296875, 40.9964840143779],
[-109.05029296875, 37.00255267215955]
]
]
]
}]
},
"relation": "intersects"
}
},
"size": 5,
"from": 0,
"sort": ["name"]
}' | jq .
The output of five (5) hits (from a total of 52 matching docs) is as follows
{
"status": {
"total": 1,
"failed": 0,
"successful": 1
},
"request": {
"query": {
"geometry": {
"shape": {
"type": "geometrycollection",
"geometries": [
{
"type": "linestring",
"coordinates": [
[
1.954764,
50.962097
],
[
3.029578,
49.868547
]
]
},
{
"type": "multipolygon",
"coordinates": [
[
[
[
-114.027099609375,
42.00848901572399
],
[
-114.04907226562499,
36.99377838872517
],
[
-109.05029296875,
36.99377838872517
],
[
-109.05029296875,
40.98819156349393
],
[
-111.060791015625,
40.98819156349393
],
[
-111.02783203125,
42.00848901572399
],
[
-114.027099609375,
42.00848901572399
]
]
],
[
[
[
-109.05029296875,
37.00255267215955
],
[
-102.041015625,
37.00255267215955
],
[
-102.041015625,
40.9964840143779
],
[
-109.05029296875,
40.9964840143779
],
[
-109.05029296875,
37.00255267215955
]
]
]
]
}
]
},
"relation": "intersects"
},
"field": "geoarea"
},
"size": 5,
"from": 0,
"highlight": null,
"fields": null,
"facets": null,
"explain": false,
"sort": [
"name"
],
"includeLocations": false,
"search_after": null,
"search_before": null
},
"hits": [
{
"index": "test_geojson_3397081757afba65_4c1c5584",
"id": "airport_7001",
"score": 0.044156513771700656,
"sort": [
"Aspen Pitkin County Sardy Field"
]
},
{
"index": "test_geojson_3397081757afba65_4c1c5584",
"id": "airport_8854",
"score": 0.021237915321935485,
"sort": [
"Boulder Municipal"
]
},
{
"index": "test_geojson_3397081757afba65_4c1c5584",
"id": "airport_1258",
"score": 0.4165991857145269,
"sort": [
"Bray"
]
},
{
"index": "test_geojson_3397081757afba65_4c1c5584",
"id": "airport_6999",
"score": 0.01797996798708474,
"sort": [
"Brigham City"
]
},
{
"index": "test_geojson_3397081757afba65_4c1c5584",
"id": "airport_7857",
"score": 0.09702723621245812,
"sort": [
"Bryce Canyon"
]
}
],
"total_hits": 52,
"max_score": 0.8460432736575045,
"took": 18306647,
"facets": null
}