Skip to content

Commit

Permalink
Drop support for PostGIS search backend
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Oct 31, 2023
1 parent 7d83b71 commit b4e9d97
Show file tree
Hide file tree
Showing 20 changed files with 8 additions and 1,463 deletions.
123 changes: 0 additions & 123 deletions .github/workflows/test-postgis.yml

This file was deleted.

8 changes: 3 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ ckanext-spatial - Geo related plugins for CKAN
This extension contains plugins that add geospatial capabilities to CKAN_,
including:

* A spatial field on the default CKAN dataset schema, that uses PostGIS_
as the backend and allows to perform spatial queries and to display the
dataset extent on the frontend.
* Geospatial dataset search powered by Solr, providing a bounding box via
a UI map widget or the API.
* Harvesters to import geospatial metadata into CKAN from other sources
in ISO 19139 format and others.
* Commands to support the CSW standard using pycsw_.
Expand Down Expand Up @@ -53,15 +52,14 @@ guidelines that apply to CKAN core, described in
Copying and License
-------------------

This material is copyright (c) 2011-2021 Open Knowledge Foundation and contributors.
This material is copyright (c) 2011-2023 Open Knowledge Foundation and contributors.

It is open and licensed under the GNU Affero General Public License (AGPL) v3.0
whose full text may be found at:

http://www.fsf.org/licensing/licenses/agpl-3.0.html

.. _CKAN: http://ckan.org
.. _PostGIS: http://postgis.org
.. _pycsw: http://pycsw.org
.. _GeoJSON: http://geojson.org
.. _ckanext-geoview: https://github.com/ckan/ckanext-geoview
30 changes: 0 additions & 30 deletions ckanext/spatial/cli.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# encoding: utf-8
import click
import logging

import ckanext.spatial.util as util


log = logging.getLogger(__name__)

def get_commands():
return [
spatial,
spatial_validation
]

Expand Down Expand Up @@ -45,29 +41,3 @@ def report_csv(filepath):
def validate_file(filepath):
"""Performs validation on the given metadata file."""
return util.validate_file(filepath)


@click.group(short_help=u"Performs spatially related operations.")
def spatial():
pass


@spatial.command()
@click.argument('srid', required=False)
def initdb(srid):
"""
Creates the necessary tables. You must have PostGIS installed
and configured in the database.
You can provide the SRID of the geometry column. Default is 4326.
"""
return util.initdb(srid)


@spatial.command('extents')
def update_extents():
"""
Creates or updates the extent geometry column for datasets with
an extent defined in the 'spatial' extra.
"""

return util.update_extents()
60 changes: 0 additions & 60 deletions ckanext/spatial/commands/spatial.py

This file was deleted.

78 changes: 3 additions & 75 deletions ckanext/spatial/plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,33 +40,15 @@
"solr", # Deprecated, please update to "solr-bbox"
"solr-bbox",
"solr-spatial-field",
"postgis", # Deprecated: will be removed in the next version
]


class SpatialMetadata(p.SingletonPlugin):

p.implements(p.IPackageController, inherit=True)
p.implements(p.IConfigurable, inherit=True)
p.implements(p.IConfigurer, inherit=True)
p.implements(p.ITemplateHelpers, inherit=True)

use_postgis = False

# IConfigurable

def configure(self, config):

# PostGIS is no longer required, support for it will be dropped in the future
self.use_postgis = tk.asbool(config.get("ckan.spatial.use_postgis", False))

if self.use_postgis:

from ckanext.spatial.postgis.model import setup as setup_model

if not tk.asbool(config.get("ckan.spatial.testing", False)):
log.debug("Setting up the spatial model")
setup_model()

# IConfigure

Expand Down Expand Up @@ -100,12 +82,6 @@ def after_dataset_update(self, context, data_dict):
def after_delete(self, context, data_dict):
return self.after_dataset_delete(context, data_dict)

def after_dataset_delete(self, context, data_dict):

if self.use_postgis:
from ckanext.spatial.postgis.model import save_package_extent
save_package_extent(data_dict["id"], None)

def check_spatial_extra(self, dataset_dict, update=False):
'''
For a given dataset, looks at the spatial extent (as given in the
Expand All @@ -114,24 +90,14 @@ def check_spatial_extra(self, dataset_dict, update=False):

dataset_id = dataset_dict["id"]
geometry = dataset_dict.get("spatial")
delete = False

if not geometry:
# Check extras
for extra in dataset_dict.get("extras", []):
if extra["key"] == "spatial":
if extra.get("deleted"):
delete = True
else:
geometry = extra["value"]

if ((geometry is None or geometry == "" or delete)
and update
and self.use_postgis):
from ckanext.spatial.postgis.model import save_package_extent
save_package_extent(dataset_id, None)
return
elif not geometry:
geometry = extra["value"]

if not geometry:
return

# Check valid JSON
Expand All @@ -151,16 +117,6 @@ def check_spatial_extra(self, dataset_dict, update=False):
error_dict = {"spatial": [msg]}
raise tk.ValidationError(error_dict)

if self.use_postgis:
from ckanext.spatial.postgis.model import save_package_extent
try:
save_package_extent(dataset_id, geometry)
except Exception as e:
if bool(os.getenv('DEBUG')):
raise
error_dict = {"spatial": ["Error: {}".format(six.text_type(e))]}
raise tk.ValidationError(error_dict)

# ITemplateHelpers

def get_helpers(self):
Expand Down Expand Up @@ -194,12 +150,6 @@ def _get_search_backend(self):
)
search_backend = "solr-bbox"

elif search_backend == "postgis":
log.warning(
"The `postgis` spatial search backend is deprecated "
"and will be removed in future versions"
)

return search_backend

# IConfigure
Expand Down Expand Up @@ -259,28 +209,6 @@ def before_dataset_search(self, search_params):

return search_params

def after_dataset_search(self, search_results, search_params):
"""
Note: The PostGIS search functionality will be removed in future versions
"""
from ckan.lib.search import PackageSearchQuery

search_backend = self._get_search_backend()
if search_backend == "postgis":
# Note: This will be deprecated at some point in favour of the
# Solr 4 spatial sorting capabilities
if search_params.get('extras', {}).get('ext_spatial') and \
tk.asbool(config.get('ckanext.spatial.use_postgis_sorting', 'False')):
# Apply the spatial sort
querier = PackageSearchQuery()
pkgs = []
for package_id, spatial_ranking in search_params['extras']['ext_spatial']:
# get package from SOLR
pkg = querier.get_index(package_id)['data_dict']
pkgs.append(json.loads(pkg))
search_results['results'] = pkgs
return search_results


class HarvestMetadataApi(HarvestMetadataApiMixin, p.SingletonPlugin):
'''
Expand Down
Loading

0 comments on commit b4e9d97

Please sign in to comment.