Skip to content

Commit

Permalink
Merge pull request #6525 from rouault/remove_GetProjectionRef_in_raw
Browse files Browse the repository at this point in the history
frmts/raw: remove use of compatibility wrappers _GetProjectionRef / _…
  • Loading branch information
rouault committed Oct 14, 2022
2 parents 7a01c0d + 806b2ba commit 845102e
Show file tree
Hide file tree
Showing 26 changed files with 443 additions and 853 deletions.
2 changes: 2 additions & 0 deletions autotest/gdrivers/data/paux/small16.aux
Expand Up @@ -6,3 +6,5 @@ UpLeftX: 440720.000
UpLeftY: 3751320.000
LoRightX: 442580.000
LoRightY: 3749220.000
MapUnits: LCC D-01 METRE
ProjParams: 0.0 0.0 -117.474542888889 33.7644620277778 33.9036340277778 33.6252900277778 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
11 changes: 11 additions & 0 deletions autotest/gdrivers/mff2.py
Expand Up @@ -39,3 +39,14 @@ def test_mff2_1():

tst = gdaltest.GDALTest("MFF2", "mff2/bytemff2", 1, 4672)
return tst.testOpen()


###############################################################################
# Test writing a MFF2 file


def test_mff2_write():

with gdaltest.config_option("GDAL_PAM_ENABLED", "NO"):
tst = gdaltest.GDALTest("MFF2", "mff2/bytemff2", 1, 4672)
return tst.testCreateCopy(check_srs=True)
23 changes: 19 additions & 4 deletions autotest/pymod/gdaltest.py
Expand Up @@ -443,7 +443,6 @@ def testCreateCopy(
if self.band > 0:
minmax = src_ds.GetRasterBand(self.band).ComputeRasterMinMax()

src_prj = src_ds.GetProjection()
src_gt = src_ds.GetGeoTransform()

if new_filename is None:
Expand Down Expand Up @@ -565,11 +564,27 @@ def testCreateCopy(
print("new = ", new_gt)
pytest.fail("Geotransform differs.")

# Do we need to check the geotransform?
if check_srs is not None:
# Do we need to check the SRS?
if check_srs == True:
src_srs = src_ds.GetSpatialRef()
new_srs = new_ds.GetSpatialRef()
if src_srs is None and new_srs is not None:
pytest.fail("src_srs is None and new_srs is not None")
elif src_srs is not None and new_srs is None:
pytest.fail("src_srs is not None and new_srs is None")
elif (
src_srs is not None
and new_srs is not None
and not src_srs.IsSame(new_srs)
):
print("")
print("old = %s" % src_srs.ExportToPrettyWkt())
print("new = %s" % new_srs.ExportToPrettyWkt())
pytest.fail("Projections differ")
elif check_srs is not None:
new_prj = new_ds.GetProjection()

src_osr = osr.SpatialReference(wkt=src_prj)
src_osr = osr.SpatialReference(wkt=src_ds.GetProjection())
new_osr = osr.SpatialReference(wkt=new_prj)

if not src_osr.IsSame(new_osr):
Expand Down
21 changes: 5 additions & 16 deletions frmts/raw/ace2dataset.cpp
Expand Up @@ -95,16 +95,13 @@ class ACE2Dataset final: public GDALPamDataset
{
friend class ACE2RasterBand;

OGRSpatialReference m_oSRS{};
double adfGeoTransform[6];

public:
ACE2Dataset();
~ACE2Dataset() override {}

const char *_GetProjectionRef(void) override;
const OGRSpatialReference* GetSpatialRef() const override {
return GetSpatialRefFromOldGetProjectionRef();
}
const OGRSpatialReference* GetSpatialRef() const override { return &m_oSRS; }
CPLErr GetGeoTransform( double * ) override;

static GDALDataset *Open( GDALOpenInfo * );
Expand All @@ -123,7 +120,6 @@ class ACE2RasterBand final: public RawRasterBand
ACE2RasterBand( VSILFILE* fpRaw,
GDALDataType eDataType,
int nXSize, int nYSize );
~ACE2RasterBand() override {}

const char *GetUnitType() override;
char **GetCategoryNames() override;
Expand All @@ -141,6 +137,9 @@ class ACE2RasterBand final: public RawRasterBand

ACE2Dataset::ACE2Dataset()
{
m_oSRS.SetFromUserInput(SRS_WKT_WGS84_LAT_LONG);
m_oSRS.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);

adfGeoTransform[0] = 0.0;
adfGeoTransform[1] = 1.0;
adfGeoTransform[2] = 0.0;
Expand All @@ -160,16 +159,6 @@ CPLErr ACE2Dataset::GetGeoTransform( double * padfTransform )
return CE_None;
}

/************************************************************************/
/* GetProjectionRef() */
/************************************************************************/

const char *ACE2Dataset::_GetProjectionRef()

{
return SRS_WKT_WGS84_LAT_LONG;
}

/************************************************************************/
/* ACE2RasterBand() */
/************************************************************************/
Expand Down
87 changes: 39 additions & 48 deletions frmts/raw/btdataset.cpp
Expand Up @@ -51,7 +51,7 @@ class BTDataset final: public GDALPamDataset
int bGeoTransformValid;
double adfGeoTransform[6];

char *pszProjection;
OGRSpatialReference m_oSRS{};

int nVersionCode; // version times 10.

Expand All @@ -66,14 +66,9 @@ class BTDataset final: public GDALPamDataset
BTDataset();
~BTDataset() override;

const char *_GetProjectionRef(void) override;
const OGRSpatialReference* GetSpatialRef() const override {
return GetSpatialRefFromOldGetProjectionRef();
}
CPLErr _SetProjection( const char * ) override;
CPLErr SetSpatialRef(const OGRSpatialReference* poSRS) override {
return OldSetProjectionFromSetSpatialRef(poSRS);
}
const OGRSpatialReference* GetSpatialRef() const override
{ return m_oSRS.IsEmpty() ? nullptr : &m_oSRS; }
CPLErr SetSpatialRef(const OGRSpatialReference* poSRS) override;
CPLErr GetGeoTransform( double * ) override;
CPLErr SetGeoTransform( double * ) override;

Expand Down Expand Up @@ -369,11 +364,12 @@ CPLErr BTRasterBand::SetUnitType(const char* psz)
BTDataset::BTDataset() :
fpImage(nullptr),
bGeoTransformValid(FALSE),
pszProjection(nullptr),
nVersionCode(0),
bHeaderModified(FALSE),
m_fVscale(0.0)
{
m_oSRS.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);

adfGeoTransform[0] = 0.0;
adfGeoTransform[1] = 1.0;
adfGeoTransform[2] = 0.0;
Expand All @@ -398,7 +394,6 @@ BTDataset::~BTDataset()
CPLError(CE_Failure, CPLE_FileIO, "I/O error");
}
}
CPLFree( pszProjection );
}

/************************************************************************/
Expand Down Expand Up @@ -478,48 +473,36 @@ CPLErr BTDataset::SetGeoTransform( double *padfTransform )
}

/************************************************************************/
/* GetProjectionRef() */
/* SetSpatialRef() */
/************************************************************************/

const char *BTDataset::_GetProjectionRef()

{
if( pszProjection == nullptr )
return "";
else
return pszProjection;
}

/************************************************************************/
/* SetProjection() */
/************************************************************************/

CPLErr BTDataset::_SetProjection( const char *pszNewProjection )
CPLErr BTDataset::SetSpatialRef(const OGRSpatialReference* poSRS)

{
CPLErr eErr = CE_None;

CPLFree( pszProjection );
pszProjection = CPLStrdup( pszNewProjection );
if( poSRS )
m_oSRS = *poSRS;
else
m_oSRS.Clear();

bHeaderModified = TRUE;

/* -------------------------------------------------------------------- */
/* Parse projection. */
/* -------------------------------------------------------------------- */
OGRSpatialReference oSRS( pszProjection );

/* -------------------------------------------------------------------- */
/* Linear units. */
/* -------------------------------------------------------------------- */
#if 0
if( oSRS.IsGeographic() )
if( m_oSRS.IsGeographic() )
{
// nShortTemp = 0;
}
else
{
const double dfLinear = oSRS.GetLinearUnits();
const double dfLinear = m_oSRS.GetLinearUnits();

if( std::abs(dfLinear - 0.3048) < 0.0000001 )
nShortTemp = 2;
Expand All @@ -538,7 +521,7 @@ CPLErr BTDataset::_SetProjection( const char *pszNewProjection )
/* -------------------------------------------------------------------- */
int bNorth = FALSE;

nShortTemp = static_cast<GInt16>(oSRS.GetUTMZone( &bNorth ));
nShortTemp = static_cast<GInt16>(m_oSRS.GetUTMZone( &bNorth ));
if( bNorth )
nShortTemp = -nShortTemp;

Expand All @@ -548,10 +531,10 @@ CPLErr BTDataset::_SetProjection( const char *pszNewProjection )
/* -------------------------------------------------------------------- */
/* Datum */
/* -------------------------------------------------------------------- */
if( oSRS.GetAuthorityName( "GEOGCS|DATUM" ) != nullptr
&& EQUAL(oSRS.GetAuthorityName( "GEOGCS|DATUM" ),"EPSG") )
if( m_oSRS.GetAuthorityName( "GEOGCS|DATUM" ) != nullptr
&& EQUAL(m_oSRS.GetAuthorityName( "GEOGCS|DATUM" ),"EPSG") )
nShortTemp = static_cast<GInt16>(
atoi(oSRS.GetAuthorityCode( "GEOGCS|DATUM" )) + 2000);
atoi(m_oSRS.GetAuthorityCode( "GEOGCS|DATUM" )) + 2000);
else
nShortTemp = -2;
CPL_LSBPTR16(&nShortTemp); /* datum unknown */
Expand All @@ -560,19 +543,26 @@ CPLErr BTDataset::_SetProjection( const char *pszNewProjection )
/* -------------------------------------------------------------------- */
/* Write out the projection to a .prj file. */
/* -------------------------------------------------------------------- */
const char *pszPrjFile = CPLResetExtension( GetDescription(), "prj" );
VSILFILE * fp = VSIFOpenL( pszPrjFile, "wt" );
if( fp != nullptr )
char* pszProjection = nullptr;
const char* const apszOptions[] = { "FORMAT=WKT1", nullptr };
m_oSRS.exportToWkt(&pszProjection, apszOptions);
if( pszProjection )
{
CPL_IGNORE_RET_VAL(VSIFPrintfL( fp, "%s\n", pszProjection ));
CPL_IGNORE_RET_VAL(VSIFCloseL( fp ));
abyHeader[60] = 1;
}
else
{
CPLError( CE_Failure, CPLE_AppDefined,
"Unable to write out .prj file." );
eErr = CE_Failure;
const char *pszPrjFile = CPLResetExtension( GetDescription(), "prj" );
VSILFILE * fp = VSIFOpenL( pszPrjFile, "wt" );
if( fp != nullptr )
{
CPL_IGNORE_RET_VAL(VSIFPrintfL( fp, "%s\n", pszProjection ));
CPL_IGNORE_RET_VAL(VSIFCloseL( fp ));
abyHeader[60] = 1;
}
else
{
CPLError( CE_Failure, CPLE_AppDefined,
"Unable to write out .prj file." );
eErr = CE_Failure;
}
CPLFree(pszProjection);
}

return eErr;
Expand Down Expand Up @@ -662,6 +652,7 @@ GDALDataset *BTDataset::Open( GDALOpenInfo * poOpenInfo )
/* Try to read a .prj file if it is indicated. */
/* -------------------------------------------------------------------- */
OGRSpatialReference oSRS;
oSRS.SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER);

if( poDS->nVersionCode >= 12 && poDS->abyHeader[60] != 0 )
{
Expand Down Expand Up @@ -765,7 +756,7 @@ GDALDataset *BTDataset::Open( GDALOpenInfo * poOpenInfo )
/* Convert coordinate system back to WKT. */
/* -------------------------------------------------------------------- */
if( oSRS.GetRoot() != nullptr )
oSRS.exportToWkt( &poDS->pszProjection );
poDS->m_oSRS = oSRS;

/* -------------------------------------------------------------------- */
/* Get georeferencing bounds. */
Expand Down

0 comments on commit 845102e

Please sign in to comment.