Skip to content

Commit

Permalink
Merge branch 'OSGeo:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
a0x8o authored Jun 17, 2024
2 parents 8b6f82a + 5481008 commit 3557d66
Show file tree
Hide file tree
Showing 27 changed files with 703 additions and 110 deletions.
188 changes: 170 additions & 18 deletions apps/test_ogrsf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2001,7 +2001,7 @@ static int TestOGRLayerRandomWrite(OGRLayer *poLayer)

{
int bRet = TRUE;
OGRFeature *papoFeatures[5], *poFeature;
OGRFeature *papoFeatures[5];

memset(papoFeatures, 0, sizeof(papoFeatures));

Expand Down Expand Up @@ -2086,25 +2086,27 @@ static int TestOGRLayerRandomWrite(OGRLayer *poLayer)
/* -------------------------------------------------------------------- */
/* Now re-read feature 2 to verify the effect stuck. */
/* -------------------------------------------------------------------- */
poFeature = LOG_ACTION(poLayer->GetFeature(nFID5));
if (poFeature == nullptr)
{
bRet = FALSE;
printf("ERROR: Attempt to GetFeature( nFID5 ) failed.\n");
goto end;
}
if (!poFeature->Equal(papoFeatures[1]))
{
bRet = FALSE;
poFeature->DumpReadable(stderr);
papoFeatures[1]->DumpReadable(stderr);
printf("ERROR: Written feature didn't seem to retain value.\n");
}
else if (bVerbose)
{
printf("INFO: Random write test passed.\n");
auto poFeature =
std::unique_ptr<OGRFeature>(LOG_ACTION(poLayer->GetFeature(nFID5)));
if (poFeature == nullptr)
{
bRet = FALSE;
printf("ERROR: Attempt to GetFeature( nFID5 ) failed.\n");
goto end;
}
if (!poFeature->Equal(papoFeatures[1]))
{
bRet = FALSE;
poFeature->DumpReadable(stderr);
papoFeatures[1]->DumpReadable(stderr);
printf("ERROR: Written feature didn't seem to retain value.\n");
}
else if (bVerbose)
{
printf("INFO: Random write test passed.\n");
}
}
DestroyFeatureAndNullify(poFeature);

/* -------------------------------------------------------------------- */
/* Re-invert the features to restore to original state */
Expand All @@ -2130,6 +2132,156 @@ static int TestOGRLayerRandomWrite(OGRLayer *poLayer)
printf("ERROR: Attempt to restore SetFeature(4) failed.\n");
}

/* -------------------------------------------------------------------- */
/* Test UpdateFeature() */
/* -------------------------------------------------------------------- */

if (bRet)
{
int nOldVal = 0;
std::string osOldVal;
int iUpdatedFeature = -1;
int iUpdatedField = -1;
std::unique_ptr<OGRFeature> poUpdatedFeature;

for (int iFeature = 0; iUpdatedFeature < 0 && iFeature < 5; iFeature++)
{
for (int iField = 0;
iField < poLayer->GetLayerDefn()->GetFieldCount(); ++iField)
{
if (papoFeatures[iFeature]->IsFieldSetAndNotNull(iField))
{
if (poLayer->GetLayerDefn()
->GetFieldDefn(iField)
->GetType() == OFTInteger)
{
iUpdatedFeature = iFeature;
iUpdatedField = iField;
nOldVal =
papoFeatures[iFeature]->GetFieldAsInteger(iField);
poUpdatedFeature.reset(papoFeatures[iFeature]->Clone());
poUpdatedFeature->SetField(iField, 0xBEEF);
break;
}
else if (poLayer->GetLayerDefn()
->GetFieldDefn(iField)
->GetType() == OFTString)
{
iUpdatedFeature = iFeature;
iUpdatedField = iField;
osOldVal =
papoFeatures[iFeature]->GetFieldAsString(iField);
poUpdatedFeature.reset(papoFeatures[iFeature]->Clone());
poUpdatedFeature->SetField(iField, "0xBEEF");
break;
}
}
}
}

if (poUpdatedFeature)
{
if (LOG_ACTION(poLayer->UpdateFeature(poUpdatedFeature.get(), 1,
&iUpdatedField, 0, nullptr,
false)) != OGRERR_NONE)
{
bRet = FALSE;
printf("ERROR: UpdateFeature() failed.\n");
}
if (bRet)
{
LOG_ACTION(poLayer->ResetReading());
for (int iFeature = 0; iFeature < 5; iFeature++)
{
auto poFeature = std::unique_ptr<OGRFeature>(LOG_ACTION(
poLayer->GetFeature(papoFeatures[iFeature]->GetFID())));
if (iFeature != iUpdatedFeature)
{
if (!poFeature ||
!poFeature->Equal(papoFeatures[iFeature]))
{
bRet = false;
printf("ERROR: UpdateFeature() test: "
"!poFeature->Equals(papoFeatures[iFeature]) "
"unexpected.\n");
if (poFeature)
poFeature->DumpReadable(stdout);
papoFeatures[iFeature]->DumpReadable(stdout);
}
}
}

auto poFeature =
std::unique_ptr<OGRFeature>(LOG_ACTION(poLayer->GetFeature(
papoFeatures[iUpdatedFeature]->GetFID())));
if (!poFeature)
{
bRet = FALSE;
printf("ERROR: at line %d", __LINE__);
goto end;
}
if (poLayer->GetLayerDefn()
->GetFieldDefn(iUpdatedField)
->GetType() == OFTInteger)
{
if (poFeature->GetFieldAsInteger(iUpdatedField) != 0xBEEF)
{
bRet = FALSE;
printf("ERROR: Did not get expected field value after "
"UpdateFeature().\n");
}
poFeature->SetField(iUpdatedField, nOldVal);
}
else if (poLayer->GetLayerDefn()
->GetFieldDefn(iUpdatedField)
->GetType() == OFTString)
{
if (!EQUAL(poFeature->GetFieldAsString(iUpdatedField),
"0xBEEF"))
{
bRet = FALSE;
printf("ERROR: Did not get expected field value after "
"UpdateFeature().\n");
}
poFeature->SetField(iUpdatedField, osOldVal.c_str());
}
else
{
CPLAssert(false);
}

if (LOG_ACTION(poLayer->UpdateFeature(
poFeature.get(), 1, &iUpdatedField, 0, nullptr,
false)) != OGRERR_NONE)
{
bRet = FALSE;
printf("ERROR: UpdateFeature() failed.\n");
}

poFeature.reset(LOG_ACTION(poLayer->GetFeature(
papoFeatures[iUpdatedFeature]->GetFID())));
if (!poFeature)
{
bRet = FALSE;
printf("ERROR: at line %d", __LINE__);
goto end;
}
if (!poFeature->Equal(papoFeatures[iUpdatedFeature]))
{
bRet = false;
printf("ERROR: UpdateFeature() test: "
"!poFeature->Equals(papoFeatures[iUpdatedFeature]) "
"unexpected.\n");
}
}
}
else
{
if (bVerbose)
printf("INFO: Could not test UpdateFeature().\n");
}
}

end:
/* -------------------------------------------------------------------- */
/* Cleanup. */
Expand Down
Binary file modified autotest/gdrivers/data/hdf5/fwhm.h5
Binary file not shown.
19 changes: 4 additions & 15 deletions autotest/gdrivers/fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import gdaltest
import pytest

from osgeo import gdal
from osgeo import gdal, osr

pytestmark = pytest.mark.require_driver("FAST")

Expand Down Expand Up @@ -185,20 +185,9 @@ def test_fast_7():
gt = (676565.09, 5, 0, 5348341.5, 0, -5)

# Expected definition of the projection
proj = """PROJCS["UTM Zone 32, Northern Hemisphere",
GEOGCS["Unknown datum based upon the WGS 84 ellipsoid",
DATUM["Not specified (based on WGS 84 spheroid)",
SPHEROID["WGS 84",6378137,298.257223563,
AUTHORITY["EPSG","7030"]]],
PRIMEM["Greenwich",0],
UNIT["degree",0.0174532925199433]],
PROJECTION["Transverse_Mercator"],
PARAMETER["latitude_of_origin",0],
PARAMETER["central_meridian",9],
PARAMETER["scale_factor",0.9996],
PARAMETER["false_easting",500000],
PARAMETER["false_northing",0],
UNIT["Meter",1]]"""
srs = osr.SpatialReference()
srs.ImportFromEPSG(32632)
proj = srs.ExportToWkt()

tst.testOpen(check_gt=gt, check_prj=proj)

Expand Down
6 changes: 6 additions & 0 deletions autotest/gdrivers/hdf5.py
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,8 @@ def test_hdf5_band_specific_attribute():
ds.attrs["fwhm"] = [0.01, 0.02]
ds.attrs["fwhm_units"] = "Micrometers"
ds.attrs["bad_band_list"] = [0, 1]
ds.attrs["center_wavelengths"] = [300, 400]
ds.attrs["my_coefficients"] = [1, 2]
f.close()

ds = gdal.Open("data/hdf5/fwhm.h5")
Expand All @@ -1315,11 +1317,15 @@ def test_hdf5_band_specific_attribute():
"fwhm": "0.01",
"fwhm_units": "Micrometers",
"bad_band": "0",
"center_wavelength": "300",
"my_coefficient": "1",
}
assert ds.GetRasterBand(2).GetMetadata_Dict() == {
"fwhm": "0.02",
"fwhm_units": "Micrometers",
"bad_band": "1",
"center_wavelength": "400",
"my_coefficient": "2",
}
ds = None

Expand Down
64 changes: 64 additions & 0 deletions autotest/ogr/data/dxf/closed_polyline_with_bulge.dxf
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
0
SECTION
2
ENTITIES
0
LWPOLYLINE
5
215
330
1F
100
AcDbEntity
8
test
100
AcDbPolyline
90
8
70
129
43
0.5
10
40585366.70650577
20
3433935.538090975
10
40585329.92564863
20
3433998.440817071
42
0.2621272319479089
10
40585297.73920335
20
3434017.254552271
10
40585271.13131783
20
3434017.686781913
10
40585252.16981492
20
3433885.990375476
10
40585256.74147
20
3433885.916111596
42
0.1393571566538866
10
40585329.65156154
20
3433905.365607637
10
40585364.24837356
20
3433925.992208718
42
0.4117239835866821
0
ENDSEC
0
EOF
18 changes: 18 additions & 0 deletions autotest/ogr/ogr_dxf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3993,3 +3993,21 @@ def test_ogr_dxf_read_broken_file_2():
lyr = ds.GetLayer(0)
for f in lyr:
pass


###############################################################################


def test_ogr_dxf_read_closed_polyline_with_bulge():
"""Test https://github.com/OSGeo/gdal/issues/10153"""

ds = ogr.Open("data/dxf/closed_polyline_with_bulge.dxf")
lyr = ds.GetLayer(0)
f = lyr.GetNextFeature()
g = f.GetGeometryRef()
assert g.GetX(0) == g.GetX(g.GetPointCount() - 1)
assert g.GetY(0) == g.GetY(g.GetPointCount() - 1)
assert (
g.ExportToWkt()
== "LINESTRING (40585366.7065058 3433935.53809098,40585329.9256486 3433998.44081707,40585329.9256486 3433998.44081707,40585328.5387678 3434000.63680805,40585327.0051198 3434002.73293274,40585325.3318693 3434004.71939884,40585323.526833 3434006.58692634,40585321.5984435 3434008.32679087,40585319.5557093 3434009.93086443,40585317.4081735 3434011.39165342,40585315.1658683 3434012.70233358,40585312.8392691 3434013.85678191,40585310.4392448 3434014.84960528,40585307.9770074 3434015.67616559,40585305.4640596 3434016.33260146,40585302.9121409 3434016.81584629,40585300.3331728 3434017.12364253,40585297.7392033 3434017.25455227,40585271.1313178 3434017.68678191,40585252.1698149 3433885.99037548,40585256.74147 3433885.9161116,40585256.74147 3433885.9161116,40585266.2920614 3433886.0916242,40585275.8076317 3433886.92740148,40585285.2425893 3433888.41943902,40585294.551729 3433890.56058809,40585303.6904483 3433893.34058991,40585312.6149614 3433896.74612477,40585321.2825086 3433900.76087591,40585329.6515615 3433905.36560764,40585364.2483736 3433925.99220872,40585364.2483736 3433925.99220872,40585364.6481964 3433926.24937651,40585365.0296424 3433926.53308859,40585365.3909523 3433926.84203644,40585365.7304596 3433927.17479516,40585366.0465985 3433927.52983003,40585366.337911 3433927.90550359,40585366.6030535 3433928.30008319,40585366.840803 3433928.71174899,40585367.0500632 3433929.13860232,40585367.2298688 3433929.5786745,40585367.3793906 3433930.02993587,40585367.4979389 3433930.49030515,40585367.5849671 3433930.95765907,40585367.6400736 3433931.42984214,40585367.6630045 3433931.9046766,40585367.6536538 3433932.37997246,40585367.6120647 3433932.85353759,40585367.5384291 3433933.32318787,40585367.4330866 3433933.7867572,40585367.2965229 3433934.24210757,40585367.129368 3433934.68713883,40585366.9323928 3433935.11979846,40585366.7065058 3433935.53809098)"
)
Loading

0 comments on commit 3557d66

Please sign in to comment.