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

Update geotiff preview for clowder v2 #29

Merged
merged 3 commits into from
Sep 8, 2023
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
2 changes: 1 addition & 1 deletion preview.geotiff/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM alpine:3.12
FROM alpine:3.13

LABEL maintainer="Yong Wook Kim <[email protected]>"

Expand Down
74 changes: 47 additions & 27 deletions preview.geotiff/ncsa.geo.tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import logging
import os
import json
import subprocess
import tempfile
from urllib.parse import urlparse, urljoin
Expand Down Expand Up @@ -110,37 +111,50 @@ def process_message(self, connector, host, secret_key, resource, parameters):
result['errorMsg'][i])
self.logger.info('[%s] : %s', fileid, result['errorMsg'][i], extra={'fileid': fileid})
else:
# Context URL
context_url = "https://clowder.ncsa.illinois.edu/contexts/metadata.jsonld"
metadata = {
"@context": [
context_url,
{
'WMS Layer Name': 'http://clowder.ncsa.illinois.edu/metadata/ncsa.geotiff.preview#WMS Layer Name',
'WMS Service URL': 'http://clowder.ncsa.illinois.edu/metadata/ncsa.geotiff.preview#WMS Service URL',
'WMS Layer URL': 'http://clowder.ncsa.illinois.edu/metadata/ncsa.geotiff.preview#WMS Layer URL'
}
],
'attachedTo': {'resourceType': 'file', 'id': parameters["id"]},
'agent': {
'@type': 'cat:extractor',
'extractor_id': 'https://clowder.ncsa.illinois.edu/clowder/api/extractors/' + self.extractorName},
'content': {
# While running in docker, might need some magic to fix docker URL vs. external URL in metadata entries
metadata_geo_host = os.getenv("EXTERNAL_GEOSERVER_URL", "")
if len(metadata_geo_host) > 0:
internal_geo_host = os.getenv("GEOSERVER_URL", "")
result = {
'WMS Layer Name': result['WMS Layer Name'],
'WMS Service URL': result['WMS Service URL'].replace(internal_geo_host, metadata_geo_host),
'WMS Layer URL': result['WMS Layer URL'].replace(internal_geo_host, metadata_geo_host)
}
else:
result = {
'WMS Layer Name': result['WMS Layer Name'],
'WMS Service URL': result['WMS Service URL'],
'WMS Layer URL': result['WMS Layer URL']
}
}

# register geotiff preview
(_, ext) = os.path.splitext(inputfile)
(_, tmpfile) = tempfile.mkstemp(suffix=ext)
# extractors.upload_preview(previewfile=tmpfile, parameters=parameters)
# logger.debug("upload previewer")
# extractors.upload_file_metadata_jsonld(mdata=metadata, parameters=parameters)
# logger.debug("upload file metadata")
pyclowder.files.upload_metadata(connector, host, secret_key, fileid, metadata)
self.logger.debug("upload file metadata")
metadata = self.get_metadata(result, 'file', fileid, host)

# register geotiff WMS layers with Clowder
CLOWDER_VERSION = os.getenv("CLOWDER_VERSION", 1)
if int(CLOWDER_VERSION) == 2:
# upload visualization URL
payload = json.dumps({
"resource": {
"collection": "files",
"resource_id": fileid
},
"client": host,
"parameters": result,
"visualization_mimetype": "image/tiff",
"visualization_component_id": "geoserver-viewer-component"
})
headers = {
"X-API-KEY": secret_key,
"Content-Type": "application/json"
}
host = os.getenv("CLOWDER_URL", host)
connector.post('%sapi/v2/visualizations/config' % host, headers=headers, data=payload,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be able to use pyclowder method

verify=connector.ssl_verify if connector else True)
else:
(_, ext) = os.path.splitext(inputfile)
(_, tmpfile) = tempfile.mkstemp(suffix=ext)
host = os.getenv("CLOWDER_URL", host)
pyclowder.files.upload_metadata(connector, host, secret_key, fileid, metadata)
self.logger.debug("upload file metadata")

except:
self.logger.exception("Error uploading metadata")
Expand Down Expand Up @@ -199,6 +213,12 @@ def extractGeotiff(self, inputfile, fileid, filename, secret_key):
else:
geoserver_rest = self.geoServer

if not geoserver_rest.endswith("rest"):
if geoserver_rest.endswith("/"):
geoserver_rest += "rest"
else:
geoserver_rest += "/rest"

epsg = "EPSG:" + str(geotiffUtil.getEpsg())
style = None

Expand Down
2 changes: 1 addition & 1 deletion preview.geotiff/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ gsconfig-py3==1.0.8
pika>=1.0.0
requests>=2.10.0
wheel>=0.24.0
pyclowder==2.5.1
pyclowder==3.0.1