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

VICAR: add read/write support for GeoTIFF encoding of CRS and geotransform #4596

Merged
merged 1 commit into from
Oct 6, 2021
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
27 changes: 23 additions & 4 deletions autotest/gdrivers/vicar.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,26 +294,45 @@ def test_vicar_create_label_option_as_filename_error():
gdal.Unlink(filename)


def test_vicar_create_georeferencing():
@pytest.mark.parametrize("georef_format", ["MIPL", "GEOTIFF"])
def test_vicar_create_georeferencing(georef_format):

src_ds = gdal.Open('data/vicar/test_vicar_truncated.bin')
filename = '/vsimem/test.vic'
ds = gdal.GetDriverByName('VICAR').Create(filename, src_ds.RasterXSize, src_ds.RasterYSize)
ds = gdal.GetDriverByName('VICAR').Create(filename, src_ds.RasterXSize, src_ds.RasterYSize,
options = ['GEOREF_FORMAT=' + georef_format])
ds.SetGeoTransform(src_ds.GetGeoTransform())
ds.SetSpatialRef(src_ds.GetSpatialRef())
ds = None

ds = gdal.Open(filename)
assert ds.GetGeoTransform() == src_ds.GetGeoTransform()
assert ds.GetSpatialRef().IsSame(src_ds.GetSpatialRef())
lbl = ds.GetMetadata_List('json:VICAR')[0]
lbl = json.loads(lbl)
if georef_format == 'MIPL':
assert 'MAP' in lbl['PROPERTY']
assert 'GEOTIFF' not in lbl['PROPERTY']
else:
assert 'GEOTIFF' in lbl['PROPERTY']
assert 'MAP' not in lbl['PROPERTY']

filename2 = '/vsimem/test2.vic'
assert gdal.GetDriverByName('VICAR').CreateCopy(filename2, ds)
assert gdal.GetDriverByName('VICAR').CreateCopy(filename2, ds,
options = ['GEOREF_FORMAT=' + georef_format])
ds = None

ds = gdal.Open(filename2)
assert ds.GetGeoTransform() == src_ds.GetGeoTransform()
assert ds.GetSpatialRef().IsSame(src_ds.GetSpatialRef())
lbl = ds.GetMetadata_List('json:VICAR')[0]
lbl = json.loads(lbl)
if georef_format == 'MIPL':
assert 'MAP' in lbl['PROPERTY']
assert 'GEOTIFF' not in lbl['PROPERTY']
else:
assert 'GEOTIFF' in lbl['PROPERTY']
assert 'MAP' not in lbl['PROPERTY']
ds = None

gdal.GetDriverByName('VICAR').Delete(filename)
Expand Down Expand Up @@ -353,7 +372,7 @@ def test_vicar_write_basic():
assert ds.GetRasterBand(1).Checksum() == 4672
lbl = ds.GetMetadata_List('json:VICAR')[0]
lbl = json.loads(lbl)
assert lbl['EOCI1'] == 1160
assert lbl['EOCI1'] == 1040
assert lbl['EOCI2'] == 0
ds = None
gdal.GetDriverByName('VICAR').Delete(filename)
Expand Down
5 changes: 5 additions & 0 deletions gdal/doc/source/drivers/raster/vicar.rst
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ creation option.

The available creation options are:

- **GEOREF_FORMAT**\ =MIPL/GEOTIFF. (GDAL >= 3.4) How to encode georeferencing
information. Defaults to MIPL using the ``MAP`` property group. When setting to
GEOTIFF, a ``GEOTIFF`` property group will be used using GeoTIFF keys and tags.
The COORDINATE_SYSTEM_NAME, POSITIVE_LONGITUDE_DIRECTION and TARGET_NAME
options will be ignored when selectin the GEOTIFF encoding.
- **COORDINATE_SYSTEM_NAME**\ =PLANETOCENTRIC/PLANETOGRAPHIC. Value of
MAP.COORDINATE_SYSTEM_NAME. Defaults to PLANETOCENTRIC. If specified, and
USE_SRC_MAP is in effect, this will be taken into account to
Expand Down
17 changes: 16 additions & 1 deletion gdal/frmts/pds/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,22 @@ OBJ = pdsdataset.o isis2dataset.o isis3dataset.o vicardataset.o \
vicarkeywordhandler.o \
pds4dataset.o pds4vector.o

CPPFLAGS := -iquote ../vrt -iquote ../../ogr/ogrsf_frmts/geojson -iquote ../../ogr/ogrsf_frmts/generic -iquote ../../ogr/ogrsf_frmts/vrt $(JSON_INCLUDE) $(CPPFLAGS)
ifeq ($(GEOTIFF_SETTING),internal)
GEOTIFF_INCLUDE = -iquote ../gtiff/libgeotiff
ifeq ($(RENAME_INTERNAL_LIBGEOTIFF_SYMBOLS),yes)
CPPFLAGS := -DRENAME_INTERNAL_LIBGEOTIFF_SYMBOLS $(CPPFLAGS)
endif
endif

LIBTIFF_OPTS =
ifeq ($(TIFF_SETTING),internal)
LIBTIFF_OPTS := -iquote ../gtiff/libtiff $(LIBTIFF_OPTS)
ifeq ($(RENAME_INTERNAL_LIBTIFF_SYMBOLS),yes)
LIBTIFF_OPTS := -DRENAME_INTERNAL_LIBTIFF_SYMBOLS $(LIBTIFF_OPTS)
endif
endif

CPPFLAGS := -iquote ../vrt -iquote ../../ogr/ogrsf_frmts/geojson -iquote ../../ogr/ogrsf_frmts/generic -iquote ../../ogr/ogrsf_frmts/vrt $(JSON_INCLUDE) $(GEOTIFF_INCLUDE) $(LIBTIFF_OPTS) -iquote ../gtiff $(CPPFLAGS)

default: $(OBJ:.o=.$(OBJ_EXT))

Expand Down
10 changes: 9 additions & 1 deletion gdal/frmts/pds/makefile.vc
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ OBJ = pdsdataset.obj isis2dataset.obj isis3dataset.obj \

GDAL_ROOT = ..\..

EXTRAFLAGS = -I..\..\gcore -I..\vrt -I..\..\ogr\ogrsf_frmts\geojson -I..\..\ogr\ogrsf_frmts\geojson\libjson -I..\..\ogr\ogrsf_frmts\generic -I..\..\ogr\ogrsf_frmts\vrt
EXTRAFLAGS = -I..\..\gcore -I..\vrt -I..\..\ogr\ogrsf_frmts\geojson -I..\..\ogr\ogrsf_frmts\geojson\libjson -I..\..\ogr\ogrsf_frmts\generic -I..\..\ogr\ogrsf_frmts\vrt $(GEOTIFF_INC) $(TIFF_INC) -I..\gtiff

!INCLUDE $(GDAL_ROOT)\nmake.opt

!IFNDEF GEOTIFF_INC
GEOTIFF_INC = -I..\gtiff\libgeotiff
!ENDIF

!IFNDEF TIFF_INC
TIFF_INC = -I..\gtiff\libtiff
!ENDIF

default: $(OBJ)
xcopy /D /Y *.obj ..\o

Expand Down
Loading