diff --git a/ckanext/spatial/plugin/__init__.py b/ckanext/spatial/plugin/__init__.py index 149df18..0cd8378 100644 --- a/ckanext/spatial/plugin/__init__.py +++ b/ckanext/spatial/plugin/__init__.py @@ -250,8 +250,6 @@ class SpatialQuery(SpatialQueryMixin, p.SingletonPlugin): else: # Check if coordinates are defined counter-clockwise, # otherwise we'll get wrong results from Solr - - import ipdb; ipdb.set_trace() lr = shapely.geometry.polygon.LinearRing(geometry['coordinates'][0]) lr_coords = list(lr.coords) if lr.is_ccw else reversed(list(lr.coords)) polygon = shapely.geometry.polygon.Polygon(lr_coords) @@ -259,7 +257,6 @@ class SpatialQuery(SpatialQueryMixin, p.SingletonPlugin): if not wkt: shape = shapely.geometry.shape(geometry) - import ipdb; ipdb.set_trace() if not shape.is_valid: log.error('Wrong geometry, not indexing') return pkg_dict diff --git a/ckanext/spatial/tests/base.py b/ckanext/spatial/tests/base.py index dc7ae0c..064a029 100644 --- a/ckanext/spatial/tests/base.py +++ b/ckanext/spatial/tests/base.py @@ -1,5 +1,7 @@ # -*- coding: utf-8 -*- +import os + geojson_examples = { "point": '{"type":"Point","coordinates":[100.0,0.0]}', "point_2": '{"type":"Point","coordinates":[20,10]}', @@ -23,3 +25,10 @@ geojson_examples = { class SpatialTestBase(object): db_srid = 4326 geojson_examples = geojson_examples + + def read_file(self, path): + + file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), path) + + with open(file_path, "r") as f: + return f.read() diff --git a/ckanext/spatial/tests/data/altafulla.geojson b/ckanext/spatial/tests/data/altafulla.geojson new file mode 100644 index 0000000..71a1f67 --- /dev/null +++ b/ckanext/spatial/tests/data/altafulla.geojson @@ -0,0 +1 @@ +{ "type": "MultiPolygon", "coordinates": [ [ [ [ 1.36285, 41.14643 ], [ 1.36512, 41.14967 ], [ 1.36656, 41.15016 ], [ 1.36787, 41.15036 ], [ 1.37021, 41.15141 ], [ 1.37172, 41.15457 ], [ 1.37326, 41.15776 ], [ 1.37285, 41.15823 ], [ 1.37324, 41.15899 ], [ 1.3751, 41.16005 ], [ 1.37595, 41.16193 ], [ 1.37684, 41.16201 ], [ 1.37842, 41.16258 ], [ 1.37816, 41.16386 ], [ 1.37814, 41.164 ], [ 1.37823, 41.16445 ], [ 1.37645, 41.16523 ], [ 1.3767, 41.16618 ], [ 1.37686, 41.16672 ], [ 1.37712, 41.16828 ], [ 1.37744, 41.16861 ], [ 1.37811, 41.1699 ], [ 1.37823, 41.17035 ], [ 1.37841, 41.17054 ], [ 1.37893, 41.17082 ], [ 1.37941, 41.1711 ], [ 1.38006, 41.17133 ], [ 1.3802, 41.17188 ], [ 1.38053, 41.17208 ], [ 1.38092, 41.17218 ], [ 1.38172, 41.17229 ], [ 1.38208, 41.17247 ], [ 1.38314, 41.17285 ], [ 1.38385, 41.17322 ], [ 1.38446, 41.1734 ], [ 1.38575, 41.1735 ], [ 1.38633, 41.17338 ], [ 1.38724, 41.17295 ], [ 1.38752, 41.17296 ], [ 1.38876, 41.17244 ], [ 1.38883, 41.17216 ], [ 1.38923, 41.17189 ], [ 1.39044, 41.17145 ], [ 1.39073, 41.17114 ], [ 1.39139, 41.17088 ], [ 1.39183, 41.17058 ], [ 1.3922, 41.1702 ], [ 1.39272, 41.16998 ], [ 1.39432, 41.1698 ], [ 1.39468, 41.16971 ], [ 1.39504, 41.169 ], [ 1.39512, 41.16848 ], [ 1.39566, 41.16728 ], [ 1.39539, 41.16695 ], [ 1.39521, 41.16672 ], [ 1.39407, 41.16546 ], [ 1.39304, 41.16516 ], [ 1.39276, 41.16417 ], [ 1.39252, 41.16169 ], [ 1.39223, 41.16069 ], [ 1.39215, 41.16042 ], [ 1.39194, 41.15995 ], [ 1.39145, 41.15934 ], [ 1.39095, 41.1587 ], [ 1.3904, 41.1577 ], [ 1.39051, 41.15655 ], [ 1.3904, 41.15493 ], [ 1.39039, 41.15489 ], [ 1.38996, 41.15255 ], [ 1.38957, 41.1513 ], [ 1.38973, 41.15002 ], [ 1.38965, 41.14966 ], [ 1.3893, 41.14924 ], [ 1.38879, 41.14883 ], [ 1.38835, 41.14825 ], [ 1.38819, 41.14789 ], [ 1.38814, 41.14751 ], [ 1.38819, 41.14683 ], [ 1.38766, 41.14564 ], [ 1.38756, 41.14495 ], [ 1.38725, 41.14448 ], [ 1.38701, 41.14376 ], [ 1.38525, 41.14099 ], [ 1.38708, 41.14086 ], [ 1.38731, 41.14087 ], [ 1.38791, 41.14092 ], [ 1.38846, 41.14088 ], [ 1.38842, 41.1407 ], [ 1.38838, 41.14045 ], [ 1.39062, 41.13781 ], [ 1.39156, 41.13672 ], [ 1.3899, 41.13265 ], [ 1.38982, 41.13244 ], [ 1.38954, 41.13251 ], [ 1.38924, 41.13248 ], [ 1.38896, 41.13238 ], [ 1.38886, 41.13239 ], [ 1.3886, 41.13243 ], [ 1.38852, 41.13244 ], [ 1.38846, 41.13242 ], [ 1.38833, 41.13235 ], [ 1.38827, 41.13234 ], [ 1.38802, 41.13239 ], [ 1.38774, 41.13249 ], [ 1.38765, 41.1325 ], [ 1.38738, 41.13254 ], [ 1.38705, 41.13257 ], [ 1.38674, 41.13256 ], [ 1.38647, 41.13249 ], [ 1.3862, 41.13248 ], [ 1.38591, 41.13253 ], [ 1.38567, 41.13264 ], [ 1.38549, 41.13278 ], [ 1.38547, 41.13284 ], [ 1.38557, 41.13302 ], [ 1.38575, 41.13318 ], [ 1.38592, 41.13334 ], [ 1.38596, 41.1334 ], [ 1.38598, 41.13346 ], [ 1.38585, 41.13367 ], [ 1.3856, 41.13383 ], [ 1.38539, 41.13396 ], [ 1.38514, 41.13405 ], [ 1.38488, 41.13414 ], [ 1.38465, 41.13421 ], [ 1.38439, 41.1343 ], [ 1.38411, 41.13438 ], [ 1.38384, 41.13441 ], [ 1.38352, 41.13443 ], [ 1.38322, 41.13444 ], [ 1.38294, 41.13444 ], [ 1.38267, 41.13443 ], [ 1.38239, 41.13443 ], [ 1.38211, 41.13441 ], [ 1.3818, 41.13438 ], [ 1.38151, 41.13437 ], [ 1.38123, 41.13434 ], [ 1.38096, 41.1343 ], [ 1.38065, 41.13425 ], [ 1.3804, 41.13422 ], [ 1.38016, 41.13419 ], [ 1.37989, 41.13414 ], [ 1.3791, 41.13402 ], [ 1.37836, 41.13391 ], [ 1.37748, 41.13373 ], [ 1.37664, 41.13355 ], [ 1.37611, 41.13344 ], [ 1.37545, 41.13327 ], [ 1.37476, 41.1331 ], [ 1.37435, 41.13294 ], [ 1.37386, 41.13278 ], [ 1.37326, 41.13253 ], [ 1.3733, 41.13264 ], [ 1.37522, 41.1384 ], [ 1.36729, 41.14019 ], [ 1.36661, 41.14019 ], [ 1.36583, 41.14019 ], [ 1.365, 41.14019 ], [ 1.36469, 41.1402 ], [ 1.36425, 41.1402 ], [ 1.36357, 41.14019 ], [ 1.36283, 41.14019 ], [ 1.36211, 41.14021 ], [ 1.36154, 41.1402 ], [ 1.361, 41.14018 ], [ 1.3611, 41.14098 ], [ 1.36114, 41.14131 ], [ 1.36121, 41.14174 ], [ 1.36128, 41.14201 ], [ 1.36135, 41.14223 ], [ 1.36153, 41.14281 ], [ 1.36176, 41.14335 ], [ 1.36183, 41.14346 ], [ 1.36191, 41.14356 ], [ 1.36197, 41.14378 ], [ 1.36199, 41.14401 ], [ 1.36202, 41.14429 ], [ 1.36209, 41.14459 ], [ 1.36218, 41.14492 ], [ 1.36223, 41.14522 ], [ 1.36227, 41.14539 ], [ 1.3623, 41.14553 ], [ 1.36233, 41.14564 ], [ 1.36238, 41.14576 ], [ 1.36244, 41.14587 ], [ 1.3625, 41.146 ], [ 1.36259, 41.14613 ], [ 1.36266, 41.14621 ], [ 1.36273, 41.1463 ], [ 1.36285, 41.14643 ] ] ] ] } diff --git a/ckanext/spatial/tests/data/hawaii.geojson b/ckanext/spatial/tests/data/hawaii.geojson new file mode 100644 index 0000000..7d96200 --- /dev/null +++ b/ckanext/spatial/tests/data/hawaii.geojson @@ -0,0 +1 @@ +{ "type": "MultiPolygon", "coordinates": [ [ [ [ -156.04965, 19.78045 ], [ -156.00627, 19.81758 ], [ -155.97665, 19.85053 ], [ -155.94925, 19.85703 ], [ -155.91566, 19.88713 ], [ -155.89253, 19.93216 ], [ -155.85659, 19.96889 ], [ -155.83195, 19.98278 ], [ -155.82547, 20.02594 ], [ -155.85038, 20.06251 ], [ -155.89065, 20.12358 ], [ -155.90278, 20.17707 ], [ -155.89066, 20.25524 ], [ -155.85329, 20.27155 ], [ -155.79888, 20.25411 ], [ -155.737, 20.22277 ], [ -155.70433, 20.19169 ], [ -155.63746, 20.15305 ], [ -155.59803, 20.12454 ], [ -155.55893, 20.13157 ], [ -155.50256, 20.11416 ], [ -155.38758, 20.06712 ], [ -155.27032, 20.01452 ], [ -155.16663, 19.93789 ], [ -155.12462, 19.89729 ], [ -155.08634, 19.8554 ], [ -155.09122, 19.77637 ], [ -155.08712, 19.72801 ], [ -155.04538, 19.73982 ], [ -155.00642, 19.73929 ], [ -154.9811, 19.69069 ], [ -154.97434, 19.6332 ], [ -154.94711, 19.60486 ], [ -154.85262, 19.54917 ], [ -154.81442, 19.53009 ], [ -154.81601, 19.50065 ], [ -154.87662, 19.43322 ], [ -154.94419, 19.38185 ], [ -155.02054, 19.33132 ], [ -155.11327, 19.29061 ], [ -155.15963, 19.26837 ], [ -155.20589, 19.26091 ], [ -155.26462, 19.27421 ], [ -155.31337, 19.2507 ], [ -155.36063, 19.20893 ], [ -155.3907, 19.20117 ], [ -155.45352, 19.15195 ], [ -155.50528, 19.13791 ], [ -155.55533, 19.06938 ], [ -155.5907, 19.00767 ], [ -155.61397, 18.9704 ], [ -155.63805, 18.94172 ], [ -155.67201, 18.91747 ], [ -155.72604, 18.96944 ], [ -155.80611, 19.01397 ], [ -155.88155, 19.03664 ], [ -155.91422, 19.09915 ], [ -155.91207, 19.17911 ], [ -155.90256, 19.25843 ], [ -155.89084, 19.2989 ], [ -155.8887, 19.34803 ], [ -155.90909, 19.41545 ], [ -155.92473, 19.45391 ], [ -155.95149, 19.48665 ], [ -155.96935, 19.55596 ], [ -155.97821, 19.60816 ], [ -155.99773, 19.64282 ], [ -156.02898, 19.6501 ], [ -156.03333, 19.66923 ], [ -156.06436, 19.73077 ], [ -156.04965, 19.78045 ] ] ], [ [ [ -157.05913, 20.91341 ], [ -157.01, 20.92976 ], [ -156.93753, 20.92527 ], [ -156.87312, 20.89468 ], [ -156.83705, 20.86357 ], [ -156.80847, 20.8204 ], [ -156.83832, 20.76458 ], [ -156.89029, 20.74485 ], [ -156.90908, 20.73953 ], [ -156.96789, 20.73508 ], [ -156.99068, 20.7759 ], [ -156.99183, 20.8266 ], [ -157.01091, 20.85448 ], [ -157.05966, 20.88463 ], [ -157.05913, 20.91341 ] ] ], [ [ [ -156.67047, 20.55991 ], [ -156.61073, 20.59377 ], [ -156.56714, 20.60489 ], [ -156.54303, 20.58011 ], [ -156.53964, 20.52764 ], [ -156.58624, 20.51171 ], [ -156.66881, 20.50474 ], [ -156.70227, 20.53245 ], [ -156.67047, 20.55991 ] ] ], [ [ [ -156.69989, 20.92063 ], [ -156.6809, 20.98026 ], [ -156.61958, 21.02779 ], [ -156.56277, 21.01617 ], [ -156.51871, 20.95466 ], [ -156.48105, 20.8982 ], [ -156.4033, 20.91583 ], [ -156.33282, 20.94645 ], [ -156.24255, 20.93784 ], [ -156.19471, 20.89197 ], [ -156.13267, 20.86137 ], [ -156.05979, 20.81054 ], [ -156.00353, 20.79555 ], [ -155.98541, 20.74424 ], [ -156.00187, 20.69806 ], [ -156.04379, 20.6649 ], [ -156.1299, 20.62752 ], [ -156.21026, 20.62852 ], [ -156.28439, 20.59649 ], [ -156.37763, 20.57843 ], [ -156.43187, 20.59814 ], [ -156.44367, 20.65602 ], [ -156.45844, 20.73668 ], [ -156.46224, 20.75395 ], [ -156.47356, 20.79076 ], [ -156.50603, 20.79946 ], [ -156.53775, 20.77841 ], [ -156.55462, 20.7861 ], [ -156.63179, 20.82124 ], [ -156.6878, 20.89072 ], [ -156.69989, 20.92063 ] ] ], [ [ [ -157.27722, 21.15843 ], [ -157.2497, 21.1844 ], [ -157.26069, 21.22568 ], [ -157.20212, 21.2193 ], [ -157.12821, 21.20149 ], [ -157.03999, 21.19091 ], [ -157.01427, 21.20069 ], [ -156.98403, 21.2122 ], [ -156.96285, 21.21213 ], [ -156.92111, 21.16907 ], [ -156.91786, 21.16902 ], [ -156.84159, 21.16793 ], [ -156.74223, 21.17621 ], [ -156.70911, 21.15865 ], [ -156.73934, 21.11134 ], [ -156.8022, 21.06709 ], [ -156.87714, 21.0493 ], [ -156.95387, 21.06613 ], [ -157.02617, 21.08901 ], [ -157.08066, 21.10198 ], [ -157.17161, 21.0907 ], [ -157.25253, 21.08767 ], [ -157.31075, 21.10163 ], [ -157.27722, 21.15843 ] ] ], [ [ [ -158.23219, 21.58381 ], [ -158.12561, 21.58674 ], [ -158.07989, 21.6281 ], [ -158.05069, 21.67122 ], [ -157.9923, 21.708 ], [ -157.96863, 21.7127 ], [ -157.92459, 21.65118 ], [ -157.87735, 21.57528 ], [ -157.83695, 21.52994 ], [ -157.84549, 21.46675 ], [ -157.8139, 21.4403 ], [ -157.76457, 21.46133 ], [ -157.72251, 21.45922 ], [ -157.72432, 21.40331 ], [ -157.7106, 21.3585 ], [ -157.6518, 21.3139 ], [ -157.65503, 21.30939 ], [ -157.67307, 21.2842 ], [ -157.7001, 21.264 ], [ -157.7572, 21.278 ], [ -157.77994, 21.26525 ], [ -157.8096, 21.2577 ], [ -157.85105, 21.28453 ], [ -157.89, 21.3065 ], [ -157.95074, 21.31251 ], [ -157.98153, 21.3159 ], [ -158.0245, 21.3093 ], [ -158.0883, 21.2988 ], [ -158.1033, 21.2979 ], [ -158.12937, 21.34482 ], [ -158.13093, 21.34896 ], [ -158.1403, 21.3738 ], [ -158.1792, 21.4043 ], [ -158.18265, 21.43007 ], [ -158.233, 21.4876 ], [ -158.23117, 21.52386 ], [ -158.27768, 21.57879 ], [ -158.23219, 21.58381 ] ] ], [ [ [ -160.24961, 21.81514 ], [ -160.22896, 21.88912 ], [ -160.19396, 21.92239 ], [ -160.13705, 21.94863 ], [ -160.12226, 21.96288 ], [ -160.11275, 21.99525 ], [ -160.07212, 22.00333 ], [ -160.05854, 21.99638 ], [ -160.05113, 21.98106 ], [ -160.07029, 21.96395 ], [ -160.08579, 21.92729 ], [ -160.07907, 21.89608 ], [ -160.12428, 21.87679 ], [ -160.15609, 21.86793 ], [ -160.1748, 21.84692 ], [ -160.18978, 21.82245 ], [ -160.20585, 21.77952 ], [ -160.23037, 21.78967 ], [ -160.24961, 21.81514 ] ] ], [ [ [ -159.78375, 22.0649 ], [ -159.74525, 22.09751 ], [ -159.73054, 22.13995 ], [ -159.70553, 22.15932 ], [ -159.61165, 22.20139 ], [ -159.58106, 22.22349 ], [ -159.54392, 22.2217 ], [ -159.51076, 22.20355 ], [ -159.48794, 22.22951 ], [ -159.43171, 22.22002 ], [ -159.40247, 22.2326 ], [ -159.36151, 22.21409 ], [ -159.31229, 22.18308 ], [ -159.29301, 22.12296 ], [ -159.31828, 22.06142 ], [ -159.33449, 22.0417 ], [ -159.33256, 21.99935 ], [ -159.33768, 21.95117 ], [ -159.38527, 21.91244 ], [ -159.44487, 21.86863 ], [ -159.52692, 21.88389 ], [ -159.57452, 21.89281 ], [ -159.60328, 21.89225 ], [ -159.64977, 21.93385 ], [ -159.7078, 21.96123 ], [ -159.7548, 21.97777 ], [ -159.7867, 22.0188 ], [ -159.78375, 22.0649 ] ] ] ] } diff --git a/ckanext/spatial/tests/test_spatial_search.py b/ckanext/spatial/tests/test_spatial_search.py index 2e26d10..eea9848 100644 --- a/ckanext/spatial/tests/test_spatial_search.py +++ b/ckanext/spatial/tests/test_spatial_search.py @@ -49,6 +49,283 @@ class TestBBoxSearch(SpatialTestBase): extras={"ext_bbox": "-10,-20,10,a"}, ) + def test_spatial_real_multipolygon_inside_extent_no_intersect(self): + """ + Testing this scenario, will return a result as the whole extent of + the two polygons was indexed: + + xxxxxxxx + xxx xx xxxx + x Polygon 1 x x xxxx + x xxx xx xx + x xx x xx + xxxxxxxx xx xxx + ┌────────┐ xxxx x + │ Search │ xx xx + │ BBox │ xx x + │ │ x Polygon 2 xx + └────────┘ xx x + xx xxxx + x xxxxx + x xxxx + xxxx xxxx + xxx + + """ + dataset = factories.Dataset( + extras=[ + { + "key": "spatial", + "value": self.read_file("data/hawaii.geojson") + } + ] + ) + + result = helpers.call_action( + "package_search", extras={"ext_bbox": "-156.570,19.959,-155.960,20.444"} + ) + + assert result["count"] == 1 + assert result["results"][0]["id"] == dataset["id"] + + def test_spatial_query_nz(self): + dataset = factories.Dataset(extras=[{"key": "spatial", "value": extents["nz"]}]) + + result = helpers.call_action( + "package_search", extras={"ext_bbox": "56,-54,189,-28"} + ) + + assert result["count"] == 1 + assert result["results"][0]["id"] == dataset["id"] + + def test_spatial_query_nz_wrap(self): + dataset = factories.Dataset(extras=[{"key": "spatial", "value": extents["nz"]}]) + result = helpers.call_action( + "package_search", extras={"ext_bbox": "-203,-54,-167,-28"} + ) + + assert result["count"] == 1 + assert result["results"][0]["id"] == dataset["id"] + + def test_spatial_query_ohio(self): + + dataset = factories.Dataset( + extras=[{"key": "spatial", "value": extents["ohio"]}] + ) + + result = helpers.call_action( + "package_search", extras={"ext_bbox": "-110,37,-78,53"} + ) + + assert result["count"] == 1 + assert result["results"][0]["id"] == dataset["id"] + + def test_spatial_query_ohio_wrap(self): + + dataset = factories.Dataset( + extras=[{"key": "spatial", "value": extents["ohio"]}] + ) + + result = helpers.call_action( + "package_search", extras={"ext_bbox": "258,37,281,51"} + ) + + assert result["count"] == 1 + assert result["results"][0]["id"] == dataset["id"] + + def test_spatial_query_dateline_1(self): + + dataset = factories.Dataset( + extras=[{"key": "spatial", "value": extents["dateline"]}] + ) + + result = helpers.call_action( + "package_search", extras={"ext_bbox": "-197,56,-128,70"} + ) + + assert result["count"] == 1 + assert result["results"][0]["id"] == dataset["id"] + + def test_spatial_query_dateline_2(self): + + dataset = factories.Dataset( + extras=[{"key": "spatial", "value": extents["dateline"]}] + ) + + result = helpers.call_action( + "package_search", extras={"ext_bbox": "162,54,237,70"} + ) + + assert result["count"] == 1 + assert result["results"][0]["id"] == dataset["id"] + + def test_spatial_query_dateline_3(self): + + dataset = factories.Dataset( + extras=[{"key": "spatial", "value": extents["dateline2"]}] + ) + + result = helpers.call_action( + "package_search", extras={"ext_bbox": "-197,56,-128,70"} + ) + + assert result["count"] == 1 + assert result["results"][0]["id"] == dataset["id"] + + def test_spatial_query_dateline_4(self): + + dataset = factories.Dataset( + extras=[{"key": "spatial", "value": extents["dateline2"]}] + ) + + result = helpers.call_action( + "package_search", extras={"ext_bbox": "162,54,237,70"} + ) + + assert result["count"] == 1 + assert result["results"][0]["id"] == dataset["id"] + + +@pytest.mark.usefixtures("clean_db", "clean_index", "harvest_setup") +@pytest.mark.ckan_config("ckanext.spatial.search_backend", "solr-spatial-field") +class TestSpatialFieldSearch(SpatialTestBase): + def test_spatial_query_point(self): + dataset = factories.Dataset( + extras=[{"key": "spatial", "value": self.geojson_examples["point"]}] + ) + + result = helpers.call_action( + "package_search", extras={"ext_bbox": "-180,-90,180,90"} + ) + + assert result["count"] == 1 + assert result["results"][0]["id"] == dataset["id"] + + def test_spatial_polygon(self): + dataset = factories.Dataset( + extras=[{"key": "spatial", "value": self.geojson_examples["polygon"]}] + ) + + result = helpers.call_action( + "package_search", extras={"ext_bbox": "-180,-90,180,90"} + ) + + assert result["count"] == 1 + assert result["results"][0]["id"] == dataset["id"] + + def test_spatial_real_polygon(self): + dataset = factories.Dataset( + extras=[ + { + "key": "spatial", + "value": self.read_file("data/altafulla.geojson") + } + ] + ) + + result = helpers.call_action( + "package_search", extras={"ext_bbox": "-180,-90,180,90"} + ) + + assert result["count"] == 1 + assert result["results"][0]["id"] == dataset["id"] + + def test_spatial_real_multipolygon(self): + dataset = factories.Dataset( + extras=[ + { + "key": "spatial", + "value": self.read_file("data/hawaii.geojson") + } + ] + ) + + result = helpers.call_action( + "package_search", extras={"ext_bbox": "-180,-90,180,90"} + ) + + assert result["count"] == 1 + assert result["results"][0]["id"] == dataset["id"] + + def test_spatial_real_multipolygon_inside_extent_no_intersect(self): + """ + Testing this scenario, should not return results: + + xxxxxxxx + xxx xx xxxx + x Polygon 1 x x xxxx + x xxx xx xx + x xx x xx + xxxxxxxx xx xxx + ┌────────┐ xxxx x + │ Search │ xx xx + │ BBox │ xx x + │ │ x Polygon 2 xx + └────────┘ xx x + xx xxxx + x xxxxx + x xxxx + xxxx xxxx + xxx + + """ + factories.Dataset( + extras=[ + { + "key": "spatial", + "value": self.read_file("data/hawaii.geojson") + } + ] + ) + + result = helpers.call_action( + "package_search", extras={"ext_bbox": "-156.570,19.959,-155.960,20.444"} + ) + + assert result["count"] == 0 + + def test_spatial_polygon_holes(self): + dataset = factories.Dataset( + extras=[{"key": "spatial", "value": self.geojson_examples["polygon_holes"]}] + ) + + result = helpers.call_action( + "package_search", extras={"ext_bbox": "-180,-90,180,90"} + ) + + assert result["count"] == 1 + assert result["results"][0]["id"] == dataset["id"] + + def test_spatial_multipolygon(self): + dataset = factories.Dataset( + extras=[{"key": "spatial", "value": self.geojson_examples["multipolygon"]}] + ) + + result = helpers.call_action( + "package_search", extras={"ext_bbox": "-180,-90,180,90"} + ) + assert result["count"] == 1 + assert result["results"][0]["id"] == dataset["id"] + + def test_spatial_query_outside_bbox(self): + + factories.Dataset( + extras=[{"key": "spatial", "value": self.geojson_examples["point"]}] + ) + + result = helpers.call_action( + "package_search", extras={"ext_bbox": "-10,-20,10,20"} + ) + + assert result["count"] == 0 + + def test_spatial_query_wrong_bbox(self): + with pytest.raises(SearchError): + helpers.call_action( + "package_search", + extras={"ext_bbox": "-10,-20,10,a"}, + ) + def test_spatial_query_nz(self): dataset = factories.Dataset(extras=[{"key": "spatial", "value": extents["nz"]}]) @@ -146,5 +423,3 @@ class TestBBoxSearch(SpatialTestBase): assert result["count"] == 1 assert result["results"][0]["id"] == dataset["id"] - -