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 read-only raster driver, SNAP_TIFF, for Sentinel Application Processing GeoTIFF files #10867

Merged
merged 1 commit into from
Oct 9, 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Supported Formats: (ro:read-only, rw:read-write, +:update, v:virtual-I/O s:subda
VRT -raster,multidimensional raster- (rw+v): Virtual Raster (*.vrt)
DERIVED -raster- (ro): Derived datasets using VRT pixel functions
GTI -raster- (rov): GDAL Raster Tile Index (*.gti.gpkg, *.gti.fgb, *.gti)
SNAP_TIFF -raster- (rov): Sentinel Application Processing GeoTIFF (*.tif, *.tiff)
GTiff -raster- (rw+vs): GeoTIFF (*.tif, *.tiff)
COG -raster- (wv): Cloud optimized GeoTIFF generator (*.tif, *.tiff)
NITF -raster- (rw+vs): National Imagery Transmission Format (*.ntf)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Supported Formats: (ro:read-only, rw:read-write, +:update, v:virtual-I/O s:subda
VRT -raster,multidimensional raster- (rw+v): Virtual Raster (*.vrt)
DERIVED -raster- (ro): Derived datasets using VRT pixel functions
GTI -raster- (rov): GDAL Raster Tile Index (*.gti.gpkg, *.gti.fgb, *.gti)
SNAP_TIFF -raster- (rov): Sentinel Application Processing GeoTIFF (*.tif, *.tiff)
GTiff -raster- (rw+vs): GeoTIFF (*.tif, *.tiff)
COG -raster- (wv): Cloud optimized GeoTIFF generator (*.tif, *.tiff)
NITF -raster- (rw+vs): National Imagery Transmission Format (*.ntf)
Expand Down
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ repos:
autotest/cpp/data/|
autotest/gdrivers/data/|
swig/|
third_party/|
third_party/fast_float/|
third_party/LercLib/|
autotest/ogr/data/|
alg/internal_libqhull/|
apps/argparse/|
Expand Down
Binary file not shown.
134 changes: 134 additions & 0 deletions autotest/gdrivers/snap_tiff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#!/usr/bin/env pytest
# -*- coding: utf-8 -*-
###############################################################################
# Project: GDAL/OGR Test Suite
# Purpose: SNAP_TIFF driver testing.
# Author: Even Rouault <even.rouault at spatialys.com>
#
###############################################################################
# Copyright (c) 2024, Even Rouault <even.rouault at spatialys.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
###############################################################################

import pytest

from osgeo import gdal

pytestmark = pytest.mark.require_driver("SNAP_TIFF")


def test_snap_tiff():
ds = gdal.Open(
"/vsizip/vsizip/data/snap_tiff/S1A_IW_GRDH_1SDV_20171009T141532_20171009T141557_018737_01F9E2_E974_tnr_empty_truncated.tif.zip.zip"
)
assert ds.GetDriver().GetDescription() == "SNAP_TIFF"
assert ds.RasterXSize == 25548
assert ds.RasterYSize == 16716
assert ds.RasterCount == 1
assert ds.GetRasterBand(1).DataType == gdal.GDT_Float32
assert ds.GetGCPCount() == 4
assert ds.GetGCPSpatialRef().GetAuthorityCode(None) == "4326"
gcps = ds.GetGCPs()
assert len(gcps) == 4
assert gcps[0].GCPPixel == 0.5
assert gcps[0].GCPLine == 0.5
assert gcps[0].GCPX == -121.18662152623274
assert gcps[0].GCPY == 39.655540466308594
assert gcps[3].GCPPixel == 25547.5
assert gcps[3].GCPLine == 16715.5
assert gcps[3].GCPX == -124.43485147116212
assert gcps[3].GCPY == 38.550738598352105
assert ds.GetRasterBand(1).GetNoDataValue() == 0
assert ds.GetRasterBand(1).GetDescription() == "Intensity_VV"
assert ds.GetRasterBand(1).GetUnitType() == "intensity"
assert ds.GetRasterBand(1).GetScale() == 1
assert ds.GetRasterBand(1).GetOffset() == 0
assert ds.GetMetadataDomainList() == [
"",
"DERIVED_SUBDATASETS",
"GEOLOCATION",
"SUBDATASETS",
"xml:DIMAP",
]
assert ds.GetMetadata() == {
"IMAGE_DESCRIPTION": "S1A_IW_GRDH_1SDV_20171009T141532_20171009T141557_018737_01F9E2_E974_tnr"
}
assert (
ds.GetMetadataItem("IMAGE_DESCRIPTION")
== "S1A_IW_GRDH_1SDV_20171009T141532_20171009T141557_018737_01F9E2_E974_tnr"
)
assert ds.GetMetadata("GEOLOCATION") == {
"LINE_OFFSET": "0",
"LINE_STEP": "16.025886864813039",
"PIXEL_OFFSET": "0",
"PIXEL_STEP": "16.02697616060226",
"SRS": 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS '
'84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]',
"X_BAND": "1",
"X_DATASET": 'SNAP_TIFF:"/vsizip/vsizip/data/snap_tiff/S1A_IW_GRDH_1SDV_20171009T141532_20171009T141557_018737_01F9E2_E974_tnr_empty_truncated.tif.zip.zip":GEOLOCATION',
"Y_BAND": "2",
"Y_DATASET": 'SNAP_TIFF:"/vsizip/vsizip/data/snap_tiff/S1A_IW_GRDH_1SDV_20171009T141532_20171009T141557_018737_01F9E2_E974_tnr_empty_truncated.tif.zip.zip":GEOLOCATION',
}
assert ds.GetMetadataItem("LINE_OFFSET", "GEOLOCATION") == "0"
assert ds.GetMetadata("SUBDATASETS") == {
"SUBDATASET_1_DESC": "Main content of "
"/vsizip/vsizip/data/snap_tiff/S1A_IW_GRDH_1SDV_20171009T141532_20171009T141557_018737_01F9E2_E974_tnr_empty_truncated.tif.zip.zip",
"SUBDATASET_1_NAME": 'SNAP_TIFF:"/vsizip/vsizip/data/snap_tiff/S1A_IW_GRDH_1SDV_20171009T141532_20171009T141557_018737_01F9E2_E974_tnr_empty_truncated.tif.zip.zip":MAIN',
"SUBDATASET_2_DESC": "Geolocation array of "
"/vsizip/vsizip/data/snap_tiff/S1A_IW_GRDH_1SDV_20171009T141532_20171009T141557_018737_01F9E2_E974_tnr_empty_truncated.tif.zip.zip",
"SUBDATASET_2_NAME": 'SNAP_TIFF:"/vsizip/vsizip/data/snap_tiff/S1A_IW_GRDH_1SDV_20171009T141532_20171009T141557_018737_01F9E2_E974_tnr_empty_truncated.tif.zip.zip":GEOLOCATION',
}
assert ds.GetMetadata("xml:DIMAP")[0].startswith("<?xml")

subds = gdal.Open(ds.GetMetadataItem("SUBDATASET_1_NAME", "SUBDATASETS"))
assert subds.RasterXSize == ds.RasterXSize

subds = gdal.Open(ds.GetMetadataItem("SUBDATASET_2_NAME", "SUBDATASETS"))
assert subds.RasterXSize == 1595
assert subds.RasterYSize == 1044
assert subds.RasterCount == 2
assert subds.GetRasterBand(1).DataType == gdal.GDT_Float64
assert subds.GetMetadata("SUBDATASETS") == {}
subds.GetRasterBand(1).SetNoDataValue(0)
assert subds.GetRasterBand(1).ComputeRasterMinMax() == (
-124.43485147116212,
-121.18662152623274,
)
subds.GetRasterBand(2).SetNoDataValue(0)
assert subds.GetRasterBand(2).ComputeRasterMinMax() == (
38.15253672014443,
40.05228536834884,
)
with gdal.quiet_errors():
subds.Close()

with pytest.raises(Exception):
gdal.Open("SNAP_TIFF:")

with pytest.raises(Exception):
gdal.Open("SNAP_TIFF:data/byte.tif:MAIN")

with pytest.raises(Exception):
gdal.Open("SNAP_TIFF:data/non_existing.tif:MAIN")

with pytest.raises(Exception):
gdal.Open(
"SNAP_TIFF:/vsizip/vsizip/data/snap_tiff/S1A_IW_GRDH_1SDV_20171009T141532_20171009T141557_018737_01F9E2_E974_tnr_empty_truncated.tif.zip.zip:INVALID"
)
1 change: 1 addition & 0 deletions doc/source/drivers/raster/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ Raster drivers
sentinel2
sgi
sigdem
snap_tiff
snodas
srp
srtmhgt
Expand Down
39 changes: 39 additions & 0 deletions doc/source/drivers/raster/snap_tiff.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.. _raster.snap_tiff:

================================================================================
SNAP_TIFF -- Sentinel Application Processing GeoTIFF
================================================================================

.. versionadded:: 3.10

.. shortname:: SNAP_TIFF

.. built_in_by_default::

This driver deals specifically with GeoTIFF files produced by the
Sentinel Application Processing (SNAP) toolbox.

Such files are formulated in a way that makes it difficult to read them with the
generic :ref:`raster.gtiff` driver.

Driver capabilities
-------------------

.. supports_georeferencing::

.. supports_virtualio::

Georeferencing
--------------

SNAP GeoTIFF files contain a geolocation array (stored as a regular grid of
GeoTIFF tie points). It is reported in the ``GEOLOCATION`` metadata domain.

The 4 corners of the geolocation array are also reported as ground control points
for faster (but less accurate) georeferencing.

Metadata
--------

Extensive metadata following DIMAP conventions is reported in the ``xml:DIMAP``
metadata domain.
1 change: 1 addition & 0 deletions frmts/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ gdal_optional_format(grib "WMO General Regularly-distributed Information in Bina
gdal_optional_format(bmp "Microsoft Windows Device Independent Bitmap")
gdal_optional_format(tga "TGA")
gdal_optional_format(stacta "STACTA")
gdal_optional_format(snap_tiff "SNAP TIFF")

# optional Formats
gdal_optional_format(bsb "Maptech/NOAA BSB Nautical Chart Format")
Expand Down
1 change: 1 addition & 0 deletions frmts/drivers.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
VRT
Derived
GTI
SNAP_TIFF
GTiff
COG
NITF
Expand Down
4 changes: 4 additions & 0 deletions frmts/gdalallregister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ void CPL_STDCALL GDALAllRegister()
GDALRegister_GTI();
#endif

#ifdef FRMT_snap_tiff
GDALRegister_SNAP_TIFF();
#endif

#ifdef FRMT_gtiff
GDALRegister_GTiff();
GDALRegister_COG();
Expand Down
9 changes: 9 additions & 0 deletions frmts/snap_tiff/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
add_gdal_driver(
TARGET gdal_SNAP_TIFF
SOURCES snaptiffdriver.cpp
PLUGIN_CAPABLE
NO_DEPS
STRONG_CXX_FLAGS
)

gdal_standard_includes(gdal_SNAP_TIFF)
Loading
Loading