From d1882776f4e97ba60767e53dc9c17809f70a0f56 Mon Sep 17 00:00:00 2001 From: Brian Kelly Date: Tue, 5 Nov 2024 13:21:06 -0600 Subject: [PATCH 1/2] Adds supports for GeoServer previewers of GeoTIFF files --- README.rst | 6 ++-- .../extensions/geotiff_geoserver.py | 32 +++++++++++++++++++ .../{geoserver.py => shapefile_geoserver.py} | 4 +-- .../geoserver.html | 2 +- setup.cfg | 3 +- 5 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 invenio_previewer_geospatial/extensions/geotiff_geoserver.py rename invenio_previewer_geospatial/extensions/{geoserver.py => shapefile_geoserver.py} (86%) diff --git a/README.rst b/README.rst index 0141888..c88d7c5 100644 --- a/README.rst +++ b/README.rst @@ -29,7 +29,8 @@ package: :: PREVIEWER_PREVIEWERS_ORDER = [ - "invenio_previewer.extensions.geoserver", + "invenio_previewer.extensions.shapefile_geoserver", + "invenio_previewer.extensions.geotiff_geoserver", "invenio_previewer.extensions.gpx", "invenio_previewer.extensions.csv_papaparsejs", "invenio_previewer.extensions.json_prismjs", @@ -46,7 +47,8 @@ package: ] PREVIEWER_PREFERENCE = [ - "geoserver", + "shapefile_geoserver", + "geotiff_geoserver", "gpx", "csv_papaparsejs", "json_prismjs", diff --git a/invenio_previewer_geospatial/extensions/geotiff_geoserver.py b/invenio_previewer_geospatial/extensions/geotiff_geoserver.py new file mode 100644 index 0000000..a6f1e5d --- /dev/null +++ b/invenio_previewer_geospatial/extensions/geotiff_geoserver.py @@ -0,0 +1,32 @@ +"""GeoServer Previewer.""" + +from flask import current_app, render_template +from invenio_previewer.proxies import current_previewer +from invenio_previewer.utils import dotted_exts + +previewable_extensions = ["tif", "tiff", "gtiff"] + + +def can_preview(file): + """Check if file can be previewed.""" + return file.is_local() and file.has_extensions(*dotted_exts(previewable_extensions)) + + +def preview(file): + """Render the Geoserver template.""" + return render_template( + "invenio_previewer_geospatial/geoserver.html", + record=file.record, + wms_url_field=( + current_app.config.get( + "PREVIEWER_GEOSPATIAL_CUSTOM_FIELDS_GEOSERVER_WMS_URL" + ) + ), + layer_name_field=( + current_app.config.get( + "PREVIEWER_GEOSPATIAL_CUSTOM_FIELDS_GEOSERVER_LAYER_NAME" + ) + ), + js_bundles=current_previewer.js_bundles + ["geoserver_js.js"], + css_bundles=current_previewer.css_bundles + ["geoserver_css.css"], + ) diff --git a/invenio_previewer_geospatial/extensions/geoserver.py b/invenio_previewer_geospatial/extensions/shapefile_geoserver.py similarity index 86% rename from invenio_previewer_geospatial/extensions/geoserver.py rename to invenio_previewer_geospatial/extensions/shapefile_geoserver.py index b1e67b7..f6f1856 100644 --- a/invenio_previewer_geospatial/extensions/geoserver.py +++ b/invenio_previewer_geospatial/extensions/shapefile_geoserver.py @@ -2,20 +2,20 @@ from flask import current_app, render_template from invenio_previewer.proxies import current_previewer +from invenio_previewer.utils import dotted_exts previewable_extensions = ["shp"] def can_preview(file): """Check if file can be previewed.""" - return file.is_local() and file.has_extensions(".shp") + return file.is_local() and file.has_extensions(*dotted_exts(previewable_extensions)) def preview(file): """Render the Geoserver template.""" return render_template( "invenio_previewer_geospatial/geoserver.html", - file=file, record=file.record, wms_url_field=( current_app.config.get( diff --git a/invenio_previewer_geospatial/templates/semantic-ui/invenio_previewer_geospatial/geoserver.html b/invenio_previewer_geospatial/templates/semantic-ui/invenio_previewer_geospatial/geoserver.html index 155575d..9600aac 100644 --- a/invenio_previewer_geospatial/templates/semantic-ui/invenio_previewer_geospatial/geoserver.html +++ b/invenio_previewer_geospatial/templates/semantic-ui/invenio_previewer_geospatial/geoserver.html @@ -7,6 +7,6 @@ data-layer-name="{{ record.custom_fields[layer_name_field] }}" > {% else %} -

Sorry, this Shapefile has no associated GeoServer layer.

+

Sorry, this file has no associated GeoServer layer.

{% endif %} {% endblock %} diff --git a/setup.cfg b/setup.cfg index 824c5ba..373bf07 100644 --- a/setup.cfg +++ b/setup.cfg @@ -49,7 +49,8 @@ invenio_assets.webpack = invenio_previewer_geospatial = invenio_previewer_geospatial.webpack:theme invenio_previewer.previewers = gpx = invenio_previewer_geospatial.extensions.gpx - geoserver = invenio_previewer_geospatial.extensions.geoserver + shapefile_geoserver = invenio_previewer_geospatial.extensions.shapefile_geoserver + geotiff_geoserver = invenio_previewer_geospatial.extensions.geotiff_geoserver [build_sphinx] source-dir = docs/ From beb5add175099fdbd5b4391ff0134bb3b3764870 Mon Sep 17 00:00:00 2001 From: Brian Kelly Date: Tue, 5 Nov 2024 13:30:29 -0600 Subject: [PATCH 2/2] Fix descrptions of extension files --- invenio_previewer_geospatial/extensions/geotiff_geoserver.py | 2 +- invenio_previewer_geospatial/extensions/shapefile_geoserver.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/invenio_previewer_geospatial/extensions/geotiff_geoserver.py b/invenio_previewer_geospatial/extensions/geotiff_geoserver.py index a6f1e5d..8be42a0 100644 --- a/invenio_previewer_geospatial/extensions/geotiff_geoserver.py +++ b/invenio_previewer_geospatial/extensions/geotiff_geoserver.py @@ -1,4 +1,4 @@ -"""GeoServer Previewer.""" +"""GeoTIFF previews via GeoServer.""" from flask import current_app, render_template from invenio_previewer.proxies import current_previewer diff --git a/invenio_previewer_geospatial/extensions/shapefile_geoserver.py b/invenio_previewer_geospatial/extensions/shapefile_geoserver.py index f6f1856..1145e1c 100644 --- a/invenio_previewer_geospatial/extensions/shapefile_geoserver.py +++ b/invenio_previewer_geospatial/extensions/shapefile_geoserver.py @@ -1,4 +1,4 @@ -"""GeoServer Previewer.""" +"""Shapefile previews via GeoServer.""" from flask import current_app, render_template from invenio_previewer.proxies import current_previewer