parent
65de1d0e77
commit
4a4c36f4e2
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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 ] ] ] ] }
|
File diff suppressed because one or more lines are too long
|
@ -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"]
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue