Skip to content

Commit 6ea9158

Browse files
committed
MiraMonVector: fix a case of mutirecord (lists) in some fields
1 parent 0332c83 commit 6ea9158

File tree

3 files changed

+160
-4
lines changed

3 files changed

+160
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"type": "Feature",
3+
"stac_version": "1.0.0",
4+
"stac_extensions": [
5+
"https://landsat.usgs.gov/stac/landsat-extension/v1.1.1/schema.json",
6+
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
7+
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
8+
"https://stac-extensions.github.io/file/v1.0.0/schema.json",
9+
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
10+
"https://stac-extensions.github.io/alternate-assets/v1.1.0/schema.json",
11+
"https://stac-extensions.github.io/storage/v1.0.0/schema.json"
12+
],
13+
"id": "LT05_L2SP_038037_20120505_20200820_02_T1_ST",
14+
"description": "Landsat Collection 2 Level-2 Surface Temperature Product",
15+
"bbox": [
16+
-115.36191290268081,
17+
32.24471141532095,
18+
-112.88724647545278,
19+
34.131291778950825
20+
],
21+
"geometry": {
22+
"type": "Polygon",
23+
"coordinates": [
24+
[
25+
[
26+
-114.94540659929078,
27+
34.131291778950825
28+
],
29+
[
30+
-115.36191290268081,
31+
32.54075651753658
32+
],
33+
[
34+
-113.33774064709293,
35+
32.24471141532095
36+
],
37+
[
38+
-112.88724647545278,
39+
33.830888258627866
40+
],
41+
[
42+
-114.94540659929078,
43+
34.131291778950825
44+
]
45+
]
46+
]
47+
},
48+
"properties": {
49+
"datetime": "2012-05-05T17:54:06.781038Z",
50+
"eo:cloud_cover": 3.0,
51+
"view:sun_azimuth": 120.71516953,
52+
"view:sun_elevation": 62.1424525,
53+
"platform": "LANDSAT_5",
54+
"instruments": [
55+
"TM"
56+
],
57+
"landsat:correction": "L2SP",
58+
"proj:epsg": 32611,
59+
"proj:shape": [
60+
6951,
61+
7851
62+
],
63+
"proj:transform": [
64+
30.0,
65+
0.0,
66+
649485.0,
67+
0.0,
68+
-30.0,
69+
3780015.0
70+
]
71+
},
72+
}

autotest/ogr/ogr_miramon_vector.py

+44
Original file line numberDiff line numberDiff line change
@@ -1428,3 +1428,47 @@ def test_ogr_miramon_create_field_after_feature(tmp_path):
14281428
match="Cannot create fields to a layer with already existing features in it",
14291429
):
14301430
create_common_attributes(lyr)
1431+
1432+
1433+
###############################################################################
1434+
# test reading mutirecord JSON file. At some point this test failed
1435+
# it's here to check that it's not failing (due to memory problems)
1436+
1437+
1438+
def test_ogr_miramon_json_import_not_failing(tmp_vsimem):
1439+
1440+
out_filename = str(tmp_vsimem / "out/json_layer_to_mm.pol")
1441+
gdal.VectorTranslate(
1442+
out_filename,
1443+
"data/miramon/reading_test/LT05_L2SP_038037_20120505_20200820_02_T1_ST_stac_minimal.json",
1444+
format="MiraMonVector",
1445+
)
1446+
1447+
ds = gdal.OpenEx(out_filename, gdal.OF_VECTOR)
1448+
1449+
lyr = ds.GetLayer(0)
1450+
assert lyr is not None, "Failed to get layer"
1451+
1452+
assert lyr.GetFeatureCount() == 1
1453+
assert lyr.GetGeomType() == ogr.wkbPolygon
1454+
1455+
f = lyr.GetNextFeature()
1456+
assert f is not None, "Failed to get feature"
1457+
assert f.GetFID() == 0
1458+
1459+
assert f.GetField("id") == [
1460+
"LT05_L2SP_038037_20120505_20200820_02_T1_ST",
1461+
"",
1462+
"",
1463+
"",
1464+
"",
1465+
"",
1466+
]
1467+
assert f.GetFieldAsString("datetime") == "(6:2012/05/05 17:54:06.781+00,,,,,)"
1468+
assert f.GetField("eo:cloud_cover") == [3.0]
1469+
assert f.GetField("proj:epsg") == [32611]
1470+
assert f.GetField("proj:shape") == [6951, 7851]
1471+
assert f.GetField("proj:transform") == [30.0, 0.0, 649485.0, 0.0, -30.0, 3780015.0]
1472+
1473+
f = None
1474+
ds = None

ogr/ogrsf_frmts/miramon/ogrmiramonlayer.cpp

+44-4
Original file line numberDiff line numberDiff line change
@@ -2249,10 +2249,20 @@ OGRErr OGRMiraMonLayer::TranslateFieldsValuesToMM(OGRFeature *poFeature)
22492249
&(hMMFeature.pRecords[nIRecord].pField),
22502250
&hMMFeature.pRecords[nIRecord].nMaxField,
22512251
hMMFeature.pRecords[nIRecord].nNumField,
2252-
MM_INC_NUMBER_OF_FIELDS,
2252+
(nIRecord == 0)
2253+
? MM_INC_NUMBER_OF_FIELDS
2254+
: hMMFeature.pRecords[nIRecord - 1].nMaxField,
22532255
hMMFeature.pRecords[nIRecord].nNumField))
22542256
return OGRERR_NOT_ENOUGH_MEMORY;
22552257

2258+
if (nIRecord > 0)
2259+
{
2260+
// The number of fields of this new record is the same as the
2261+
// last one
2262+
hMMFeature.pRecords[nIRecord].nNumField =
2263+
hMMFeature.pRecords[nIRecord - 1].nNumField;
2264+
}
2265+
22562266
if (phMiraMonLayer->nCharSet != MM_JOC_CARAC_UTF8_DBF)
22572267
{
22582268
// MiraMon encoding is ISO 8859-1 (Latin1) -> Recode from UTF-8
@@ -2311,10 +2321,20 @@ OGRErr OGRMiraMonLayer::TranslateFieldsValuesToMM(OGRFeature *poFeature)
23112321
&(hMMFeature.pRecords[nIRecord].pField),
23122322
&hMMFeature.pRecords[nIRecord].nMaxField,
23132323
hMMFeature.pRecords[nIRecord].nNumField,
2314-
MM_INC_NUMBER_OF_FIELDS,
2324+
(nIRecord == 0)
2325+
? MM_INC_NUMBER_OF_FIELDS
2326+
: hMMFeature.pRecords[nIRecord - 1].nMaxField,
23152327
hMMFeature.pRecords[nIRecord].nNumField))
23162328
return OGRERR_NOT_ENOUGH_MEMORY;
23172329

2330+
if (nIRecord > 0)
2331+
{
2332+
// The number of fields of this new record is the same as the
2333+
// last one
2334+
hMMFeature.pRecords[nIRecord].nNumField =
2335+
hMMFeature.pRecords[nIRecord - 1].nNumField;
2336+
}
2337+
23182338
if (eFSType == OFSTBoolean)
23192339
{
23202340
if (panValues[nIRecord] == 1)
@@ -2382,10 +2402,20 @@ OGRErr OGRMiraMonLayer::TranslateFieldsValuesToMM(OGRFeature *poFeature)
23822402
&(hMMFeature.pRecords[nIRecord].pField),
23832403
&hMMFeature.pRecords[nIRecord].nMaxField,
23842404
hMMFeature.pRecords[nIRecord].nNumField,
2385-
MM_INC_NUMBER_OF_FIELDS,
2405+
(nIRecord == 0)
2406+
? MM_INC_NUMBER_OF_FIELDS
2407+
: hMMFeature.pRecords[nIRecord - 1].nMaxField,
23862408
hMMFeature.pRecords[nIRecord].nNumField))
23872409
return OGRERR_NOT_ENOUGH_MEMORY;
23882410

2411+
if (nIRecord > 0)
2412+
{
2413+
// The number of fields of this new record is the same as the
2414+
// last one
2415+
hMMFeature.pRecords[nIRecord].nNumField =
2416+
hMMFeature.pRecords[nIRecord - 1].nNumField;
2417+
}
2418+
23892419
hMMFeature.pRecords[nIRecord].pField[iField].iValue =
23902420
panValues[nIRecord];
23912421

@@ -2425,10 +2455,20 @@ OGRErr OGRMiraMonLayer::TranslateFieldsValuesToMM(OGRFeature *poFeature)
24252455
&(hMMFeature.pRecords[nIRecord].pField),
24262456
&hMMFeature.pRecords[nIRecord].nMaxField,
24272457
hMMFeature.pRecords[nIRecord].nNumField,
2428-
MM_INC_NUMBER_OF_FIELDS,
2458+
(nIRecord == 0)
2459+
? MM_INC_NUMBER_OF_FIELDS
2460+
: hMMFeature.pRecords[nIRecord - 1].nMaxField,
24292461
hMMFeature.pRecords[nIRecord].nNumField))
24302462
return OGRERR_NOT_ENOUGH_MEMORY;
24312463

2464+
if (nIRecord > 0)
2465+
{
2466+
// The number of fields of this new record is the same as the
2467+
// last one
2468+
hMMFeature.pRecords[nIRecord].nNumField =
2469+
hMMFeature.pRecords[nIRecord - 1].nNumField;
2470+
}
2471+
24322472
char szChain[MAX_SIZE_OF_FIELD_NUMBER_WITH_MINUS];
24332473
MM_SprintfDoubleSignifFigures(
24342474
szChain, sizeof(szChain),

0 commit comments

Comments
 (0)