Skip to content

MiraMonRaster driver (reading part) #12841

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AbelPau
Copy link
Contributor

@AbelPau AbelPau commented Aug 1, 2025

What does this PR do?

Implements reading part for the MiraMonRaster driver.

I hope the code is clear. I’ve reused some logic from the vector side, particularly for reading DBF files and certain metadata handling.

AI assistance was used only for consultation purposes — mainly for generating small Python snippets, which I subsequently reviewed and fully understood, as well as for improving the clarity of the English writing.

New code is in C++.
If any part is unclear or needs adjustment, I’ll be available in September to answer questions or consider any suggestions reviewers may have.

Tests covers a 98.7% of functions (missing test for GetColorInterpretation() and AssignRGBColorDirectly()) and a 82.2% of the lines. I have made an effort in "error cases" but sometimes you would need very bad data to get one.

What are related issues/pull requests?

#12293

Tasklist

  • Make sure code is correctly formatted (cf pre-commit configuration)
  • Add test case(s)
  • Add documentation
  • Review
  • All CI builds and checks have passed

@AbelPau AbelPau force-pushed the MiraMonRasterDriver(ReadPart) branch from 845dc38 to a5bf252 Compare August 1, 2025 08:32
@AbelPau AbelPau marked this pull request as ready for review August 1, 2025 09:46
MiraMon Raster
==============

.. shortname:: MiraMonRaster
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.. shortname:: MiraMonRaster
.. versionadded:: 3.12
.. shortname:: MiraMonRaster

/************************************************************************/
/* MMRBand() */
/************************************************************************/
MMRBand::MMRBand(MMRRel &fRel, CPLString osBandSectionIn)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
MMRBand::MMRBand(MMRRel &fRel, CPLString osBandSectionIn)
MMRBand::MMRBand(MMRRel &fRel, const CPLString &osBandSectionIn)

nHeight = 0;
CPLError(CE_Failure, CPLE_AssertionFailed,
"The REL file '%s' contains a documented \
band with no explicit name. Section [%s] or [%s:%s].\n",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
band with no explicit name. Section [%s] or [%s:%s].\n",
band with no explicit name. Section [%s] or [%s:%s].",

{
osBandName = CPLGetBasenameSafe(osRawBandFileName);
CPLString osAux =
CPLGetPathSafe(static_cast<const char *>(pfRel->GetRELNameChar()));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
CPLGetPathSafe(static_cast<const char *>(pfRel->GetRELNameChar()));
CPLGetPathSafe(pfRel->GetRELNameChar());

nHeight = 0;
CPLError(CE_Failure, CPLE_AssertionFailed,
"The REL file '%s' contains a documented \
band with no explicit name. Section [%s] or [%s:%s].\n",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
band with no explicit name. Section [%s] or [%s:%s].\n",
band with no explicit name. Section [%s] or [%s:%s].",

Comment on lines +190 to +191
int nBands = 0;
MMRBand **papoBand = nullptr;
Copy link
Member

Choose a reason for hiding this comment

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

using a std::vector<std::unique_ptr<MMRBand>> could avoid manual memory management

// Preserving metadata

// Domain
const char *kMetadataDomain = "MIRAMON";
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const char *kMetadataDomain = "MIRAMON";
static constexpr const char *kMetadataDomain = "MIRAMON";


// Used to join Section and Key in a single
// name for SetMetadataItem(Name, Value)
const char *SecKeySeparator = "[$$$]";
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const char *SecKeySeparator = "[$$$]";
static constexpr const char *SecKeySeparator = "[$$$]";

@@ -482,6 +482,13 @@ if ((GDAL_BUILD_OPTIONAL_DRIVERS AND NOT DEFINED GDAL_ENABLE_DRIVER_ADRG AND NOT
add_subdirectory(frmts/iso8211)
endif()

# Build frmts/miramon_common conditionally to drivers requiring it
if ((GDAL_BUILD_OPTIONAL_DRIVERS AND NOT DEFINED GDAL_ENABLE_DRIVER_MIRAMONVECTOR AND NOT DEFINED GDAL_ENABLE_DRIVER_MIRAMONRASTER) OR
Copy link
Member

Choose a reason for hiding this comment

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

there's likely something wrong in this condition, as the variable for the vector driver is OGR_ENABLE_DRIVER_MIRAMONRASTER . You should likely test OGR_BUILD_OPTIONAL_DRIVERS too. See above test for frmts/iso8211

Comment on lines +21 to +27
#ifdef MSVC
#include "..\..\..\frmts\miramon_common\mm_gdal_functions.h"
#include "..\..\..\frmts\miramon_common\mm_gdal_constants.h"
#else
#include "../../../frmts/miramon_common/mm_gdal_functions.h"
#include "../../../frmts/miramon_common/mm_gdal_constants.h"
#endif
Copy link
Member

Choose a reason for hiding this comment

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

I believe MSVC test is not needed:

Suggested change
#ifdef MSVC
#include "..\..\..\frmts\miramon_common\mm_gdal_functions.h"
#include "..\..\..\frmts\miramon_common\mm_gdal_constants.h"
#else
#include "../../../frmts/miramon_common/mm_gdal_functions.h"
#include "../../../frmts/miramon_common/mm_gdal_constants.h"
#endif
#include "../../../frmts/miramon_common/mm_gdal_functions.h"
#include "../../../frmts/miramon_common/mm_gdal_constants.h"

Copy link
Member

Choose a reason for hiding this comment

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

same in other locations

@rouault
Copy link
Member

rouault commented Aug 1, 2025

gdalinfo autotest/gdrivers/data/miramon/normal/uinteger_2x3_6_categs_RLE.img reports ColorInterp=Palette, but no color palette is attached to the band. This is quite unusual

import pytest

from osgeo import gdal

Copy link
Member

Choose a reason for hiding this comment

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

you can remove all @pytest.mark.require_driver("MiraMonRaster") if you just add

Suggested change
pytestmark = pytest.mark.require_driver("MiraMonRaster")

Comment on lines +23 to +24

gdal_target_link_libraries(gdal_MiraMon PRIVATE PROJ::proj)
Copy link
Member

Choose a reason for hiding this comment

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

should not be needed:

Suggested change
gdal_target_link_libraries(gdal_MiraMon PRIVATE PROJ::proj)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants