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

Add a new data type: GeoTiff #4

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
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: 2 additions & 0 deletions lib/galaxy/config/sample/datatypes_conf.xml.sample
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0"?>
<datatypes>
<registration converters_path="lib/galaxy/datatypes/converters" display_path="display_applications">
<datatype extension="geo.tiff" type="galaxy.datatypes.gis:GeoTiff" display_in_upload="true"/>
<datatype extension="jp2" type="galaxy.datatypes.binary:JP2" mimetype="application/octet-stream" display_in_upload="true"/>
<datatype extension="ab1" type="galaxy.datatypes.binary:Ab1" mimetype="application/octet-stream" display_in_upload="true" description="A binary sequence file in 'ab1' format with a '.ab1' file extension. You must manually select this 'File Format' when uploading the file." description_url="https://wiki.galaxyproject.org/Learn/Datatypes#Ab1"/>
<datatype extension="afg" type="galaxy.datatypes.assembly:Amos" display_in_upload="false"/>
Expand Down Expand Up @@ -1076,6 +1077,7 @@
<sniffer type="galaxy.datatypes.images:Mrc2014"/>
<sniffer type="galaxy.datatypes.images:Jpg"/>
<sniffer type="galaxy.datatypes.images:Png"/>
<sniffer type="galaxy.datatypes.gis:GeoTiff"/>
<sniffer type="galaxy.datatypes.images:OMETiff"/>
<sniffer type="galaxy.datatypes.images:Tiff"/>
<sniffer type="galaxy.datatypes.images:Bmp"/>
Expand Down
46 changes: 46 additions & 0 deletions lib/galaxy/datatypes/gis.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
GIS classes
"""

import rasterio

from galaxy.datatypes.binary import Binary
from galaxy.datatypes.images import Tiff
from galaxy.util import nice_size


class Shapefile(Binary):
Expand Down Expand Up @@ -61,3 +65,45 @@ def display_peek(self, dataset):
return dataset.peek
except Exception:
return "Shapefile data"


class GeoTiff(Tiff):
""" The GeoTiff data format:
For more information please see http://en.wikipedia.org/wiki/GeoTIFF
GeoTiff image format
>>> from galaxy.datatypes.sniff import get_test_fname
>>> fname = get_test_fname('test.geo.tif')
>>> GeoTiff().sniff(fname)
True
>>> fname = get_test_fname('interval.interval')
>>> GeoTiff().sniff(fname)
False
"""
file_ext = "geo.tiff"
edam_format = "format_webprotege_012"
edam_data = "data_webprotege_001"

def __init__(self, **kwd):
super().__init__(**kwd)

def sniff(self, filename):
# A GeoTiff file contains a coordinate reference system (CRS) that is identified by an EPSG code.
try:
filedata = rasterio.open(filename)
return (filedata.meta['driver'] == 'GTiff') and (filedata.meta['crs'] is not None)
except Exception:
return False

def set_peek(self, dataset, is_multi_byte=False):
if not dataset.dataset.purged:
dataset.peek = "Image GeoTiff file"
dataset.blurb = nice_size(dataset.get_size())
else:
dataset.peek = 'file does not exist'
dataset.blurb = 'file purged from disk'

def display_peek(self, dataset):
try:
return dataset.peek
except Exception:
return "Image GeoTiff file (%s)" % (nice_size(dataset.get_size()))
Binary file added lib/galaxy/datatypes/test/test.geo.tif
Binary file not shown.