Skip to content

Commit

Permalink
Merge pull request #2 from nyudlts/geotiff-geoserver
Browse files Browse the repository at this point in the history
Adds GeoTIFF previews via GeoServer
  • Loading branch information
spilth authored Nov 5, 2024
2 parents 98bf508 + beb5add commit f39aa8d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
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

0 comments on commit f39aa8d

Please sign in to comment.