Skip to content

Commit

Permalink
First approach to write the precision on some real fields
Browse files Browse the repository at this point in the history
  • Loading branch information
AbelPau committed Apr 15, 2024
1 parent 02b1d26 commit 010e83f
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 17 deletions.
6 changes: 6 additions & 0 deletions ogr/ogrsf_frmts/miramon/mm_gdal_driver_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,12 @@ struct MiraMonVectLayerInfo
char *pSRS;
int nSRS_EPSG; // Ref. system if has EPSG code.

// Used to write the precision of the reserved fields in the DBF
#define MM_SRS_LAYER_IS_UNKNOWN_TYPE 0
#define MM_SRS_LAYER_IS_PROJECTED_TYPE 1
#define MM_SRS_LAYER_IS_GEOGRAPHIC_TYPE 2
int nSRSType;

// In GDAL->MiraMon sense:
// Transformed table from input layer to a MiraMon table.
// This table has to be merged with private MiraMon fields to obtain
Expand Down
15 changes: 10 additions & 5 deletions ogr/ogrsf_frmts/miramon/mm_gdal_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,9 @@ static MM_BOOLEAN MM_FillFieldDB_XP(
return TRUE;
}

size_t MM_DefineFirstPolygonFieldsDB_XP(struct MM_DATA_BASE_XP *bd_xp)
size_t MM_DefineFirstPolygonFieldsDB_XP(struct MM_DATA_BASE_XP *bd_xp,
MM_BYTE n_perimeter_decimals,
MM_BYTE n_area_decimals_decimals)
{
MM_EXT_DBF_N_FIELDS i_camp = 0;

Expand All @@ -2026,13 +2028,15 @@ size_t MM_DefineFirstPolygonFieldsDB_XP(struct MM_DATA_BASE_XP *bd_xp)

MM_FillFieldDB_XP(bd_xp->pField + i_camp, szMMNomCampPerimetreDefecte,
szPerimeterOfThePolygonEng, szPerimeterOfThePolygonCat,
szPerimeterOfThePolygonSpa, 'N', MM_MIN_WIDTH_LONG, 9);
szPerimeterOfThePolygonSpa, 'N', MM_MIN_WIDTH_LONG,
n_perimeter_decimals);
(bd_xp->pField + i_camp)->GeoTopoTypeField = (MM_BYTE)MM_CAMP_ES_PERIMETRE;
i_camp++;

MM_FillFieldDB_XP(bd_xp->pField + i_camp, szMMNomCampAreaDefecte,
szAreaOfThePolygonEng, szAreaOfThePolygonCat,
szAreaOfThePolygonSpa, 'N', MM_MIN_WIDTH_AREA, 12);
szAreaOfThePolygonSpa, 'N', MM_MIN_WIDTH_AREA,
n_area_decimals_decimals);
(bd_xp->pField + i_camp)->GeoTopoTypeField = (MM_BYTE)MM_CAMP_ES_AREA;
i_camp++;

Expand All @@ -2052,7 +2056,8 @@ size_t MM_DefineFirstPolygonFieldsDB_XP(struct MM_DATA_BASE_XP *bd_xp)
return i_camp;
}

size_t MM_DefineFirstArcFieldsDB_XP(struct MM_DATA_BASE_XP *bd_xp)
size_t MM_DefineFirstArcFieldsDB_XP(struct MM_DATA_BASE_XP *bd_xp,
MM_BYTE n_decimals)
{
MM_EXT_DBF_N_FIELDS i_camp;

Expand All @@ -2073,7 +2078,7 @@ size_t MM_DefineFirstArcFieldsDB_XP(struct MM_DATA_BASE_XP *bd_xp)

MM_FillFieldDB_XP(bd_xp->pField + i_camp, szMMNomCampLongitudArcDefecte,
szLengthOfAarcEng, szLengthOfAarcCat, szLengthOfAarcSpa,
'N', MM_MIN_WIDTH_LONG, 9);
'N', MM_MIN_WIDTH_LONG, n_decimals);
(bd_xp->pField + i_camp)->GeoTopoTypeField = (MM_BYTE)MM_CAMP_ES_LONG_ARC;
i_camp++;

Expand Down
7 changes: 5 additions & 2 deletions ogr/ogrsf_frmts/miramon/mm_gdal_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,11 @@ int MM_DuplicateFieldDBXP(struct MM_FIELD *camp_final,
const struct MM_FIELD *camp_inicial);
int MM_WriteNRecordsMMBD_XPFile(struct MMAdmDatabase *MMAdmDB);

size_t MM_DefineFirstPolygonFieldsDB_XP(struct MM_DATA_BASE_XP *bd_xp);
size_t MM_DefineFirstArcFieldsDB_XP(struct MM_DATA_BASE_XP *bd_xp);
size_t MM_DefineFirstPolygonFieldsDB_XP(struct MM_DATA_BASE_XP *bd_xp,
MM_BYTE n_perimeter_decimals,
MM_BYTE n_area_decimals_decimals);
size_t MM_DefineFirstArcFieldsDB_XP(struct MM_DATA_BASE_XP *bd_xp,
MM_BYTE n_decimals);
size_t MM_DefineFirstNodeFieldsDB_XP(struct MM_DATA_BASE_XP *bd_xp);
size_t MM_DefineFirstPointFieldsDB_XP(struct MM_DATA_BASE_XP *bd_xp);
int MM_ModifyFieldNameAndDescriptorIfPresentBD_XP(
Expand Down
20 changes: 16 additions & 4 deletions ogr/ogrsf_frmts/miramon/mm_wrlayr.c
Original file line number Diff line number Diff line change
Expand Up @@ -6344,7 +6344,10 @@ int MMCreateMMDB(struct MiraMonVectLayerInfo *hMiraMonLayer)
return 1;

if (0 == (nIField = (MM_EXT_DBF_N_FIELDS)MM_DefineFirstArcFieldsDB_XP(
pBD_XP)))
pBD_XP,
hMiraMonLayer->nSRSType == MM_SRS_LAYER_IS_PROJECTED_TYPE
? 3
: 9)))
return 1;

pBD_XP_Aux = hMiraMonLayer->MMArc.MMNode.MMAdmDB.pMMBDXP =
Expand All @@ -6371,8 +6374,13 @@ int MMCreateMMDB(struct MiraMonVectLayerInfo *hMiraMonLayer)
return 1;

if (0 ==
(nIField =
(MM_EXT_DBF_N_FIELDS)MM_DefineFirstPolygonFieldsDB_XP(pBD_XP)))
(nIField = (MM_EXT_DBF_N_FIELDS)MM_DefineFirstPolygonFieldsDB_XP(
pBD_XP,
hMiraMonLayer->nSRSType == MM_SRS_LAYER_IS_PROJECTED_TYPE ? 3
: 9,
hMiraMonLayer->nSRSType == MM_SRS_LAYER_IS_PROJECTED_TYPE
? 3
: 12)))
return 1;

pBD_XP_Aux = hMiraMonLayer->MMPolygon.MMArc.MMAdmDB.pMMBDXP =
Expand All @@ -6381,7 +6389,11 @@ int MMCreateMMDB(struct MiraMonVectLayerInfo *hMiraMonLayer)
if (!pBD_XP_Aux)
return 1;

if (0 == MM_DefineFirstArcFieldsDB_XP(pBD_XP_Aux))
if (0 == MM_DefineFirstArcFieldsDB_XP(
pBD_XP_Aux,
hMiraMonLayer->nSRSType == MM_SRS_LAYER_IS_PROJECTED_TYPE
? 3
: 9))
return 1;

pBD_XP_Aux = hMiraMonLayer->MMPolygon.MMArc.MMNode.MMAdmDB.pMMBDXP =
Expand Down
30 changes: 24 additions & 6 deletions ogr/ogrsf_frmts/miramon/ogrmiramonlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,24 @@ OGRMiraMonLayer::OGRMiraMonLayer(GDALDataset *poDS, const char *pszFilename,
hMiraMonLayerARC.pSRS = CPLStrdup(pszAuthorityCode);
hMiraMonLayerPOL.pSRS = CPLStrdup(pszAuthorityCode);
}
// In the DBF, there are some reserved fields that need to
// know if the layer is geographic or not to write the
// precision (they are real)
if (poSRS->IsGeographic())
{
hMiraMonLayerPNT.nSRSType = hMiraMonLayerARC.nSRSType =
hMiraMonLayerPOL.nSRSType = MM_SRS_LAYER_IS_GEOGRAPHIC_TYPE;
}
else
{
hMiraMonLayerPNT.nSRSType = hMiraMonLayerARC.nSRSType =
hMiraMonLayerPOL.nSRSType = MM_SRS_LAYER_IS_PROJECTED_TYPE;
}
}
else
{
hMiraMonLayerPNT.nSRSType = hMiraMonLayerARC.nSRSType =
hMiraMonLayerPOL.nSRSType = MM_SRS_LAYER_IS_UNKNOWN_TYPE;
}
}
else
Expand Down Expand Up @@ -1936,7 +1954,7 @@ OGRErr OGRMiraMonLayer::TranslateFieldsToMM()
if (phMiraMonLayer->pLayerDB->pFields[iField]
.nFieldSize == 0)
phMiraMonLayer->pLayerDB->pFields[iField]
.nFieldSize = 1;
.nFieldSize = 3;
}
}
else
Expand Down Expand Up @@ -2207,12 +2225,10 @@ OGRErr OGRMiraMonLayer::TranslateFieldsValuesToMM(OGRFeature *poFeature)
hMMFeature.pRecords[nIRecord].pField[iField].dValue =
padfRLValues[nIRecord];

// TODO: decide how many decimals use. If possible.
//CPLStrlcpy(format, CPLSPrintf("%f", padfRLValues[nIRecord]),23);

if (MM_SecureCopyStringFieldValue(
&hMMFeature.pRecords[nIRecord].pField[iField].pDinValue,
CPLSPrintf("%f", padfRLValues[nIRecord]),
CPLSPrintf("%.*f", MAX_RELIABLE_SF_DOUBLE,
padfRLValues[nIRecord]),
&hMMFeature.pRecords[nIRecord]
.pField[iField]
.nNumDinValue))
Expand Down Expand Up @@ -2358,9 +2374,11 @@ OGRErr OGRMiraMonLayer::TranslateFieldsValuesToMM(OGRFeature *poFeature)

hMMFeature.pRecords[0].pField[iField].dValue =
poFeature->GetFieldAsDouble(iField);

if (MM_SecureCopyStringFieldValue(
&hMMFeature.pRecords[0].pField[iField].pDinValue,
poFeature->GetFieldAsString(iField),
CPLSPrintf("%.*f", MAX_RELIABLE_SF_DOUBLE,
poFeature->GetFieldAsDouble(iField)),
&hMMFeature.pRecords[0].pField[iField].nNumDinValue))
return OGRERR_NOT_ENOUGH_MEMORY;
hMMFeature.pRecords[0].pField[iField].bIsValid = 1;
Expand Down

0 comments on commit 010e83f

Please sign in to comment.