Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds GeoTIFF previews via GeoServer #2

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -46,7 +47,8 @@ package:
]

PREVIEWER_PREFERENCE = [
"geoserver",
"shapefile_geoserver",
"geotiff_geoserver",
"gpx",
"csv_papaparsejs",
"json_prismjs",
Expand Down
32 changes: 32 additions & 0 deletions invenio_previewer_geospatial/extensions/geotiff_geoserver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""GeoTIFF previews via GeoServer."""

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"],
)
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
"""GeoServer Previewer."""
"""Shapefile previews via GeoServer."""

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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
data-layer-name="{{ record.custom_fields[layer_name_field] }}"
></div>
{% else %}
<p>Sorry, this Shapefile has no associated GeoServer layer.</p>
<p>Sorry, this file has no associated GeoServer layer.</p>
{% endif %}
{% endblock %}
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down