Skip to content

Commit

Permalink
Fix shape 3D extent (set NaN on 2D)
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Nov 28, 2023
1 parent e66ca6c commit e877373
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion autotest/ogr/ogr_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -2967,7 +2967,7 @@ def test_ogr_csv_getextent3d(tmp_vsimem):
)
assert gdal.GetLastErrorMsg() == ""
lyr = ds.GetLayer(0)
assert not lyr.TestCapability(ogr.OLCFastGetExtent)
assert not lyr.TestCapability(ogr.OLCFastGetExtent3D)
dfn = lyr.GetLayerDefn()
assert dfn.GetGeomFieldCount() == 1
ext2d = lyr.GetExtent()
Expand Down
2 changes: 1 addition & 1 deletion autotest/ogr/ogr_geojson.py
Original file line number Diff line number Diff line change
Expand Up @@ -4687,7 +4687,7 @@ def test_ogr_json_getextent3d(tmp_vsimem):

assert gdal.GetLastErrorMsg() == ""
lyr = ds.GetLayer(0)
assert not lyr.TestCapability(ogr.OLCFastGetExtent)
assert not lyr.TestCapability(ogr.OLCFastGetExtent3D)
dfn = lyr.GetLayerDefn()
assert dfn.GetGeomFieldCount() == 1
ext2d = lyr.GetExtent()
Expand Down
8 changes: 7 additions & 1 deletion autotest/ogr/ogr_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
# Boston, MA 02111-1307, USA.
###############################################################################

import math
import os
import shutil
import struct
Expand Down Expand Up @@ -1853,6 +1854,11 @@ def test_ogr_shape_48(tmp_vsimem):
lyr.SetFeature(feat)
extent = lyr.GetExtent()
assert extent == (1, 3, 2, 4), "did not get expected extent (1)"
extent3D = lyr.GetExtent3D()
assert lyr.TestCapability(ogr.OLCFastGetExtent3D)
assert extent3D[:4] == (1, 3, 2, 4), "did not get expected extent 3D"
assert math.isnan(extent3D[4])
assert math.isnan(extent3D[5])

ds.ExecuteSQL("RECOMPUTE EXTENT ON ogr_shape_48")
extent = lyr.GetExtent()
Expand Down Expand Up @@ -1905,7 +1911,7 @@ def test_ogr_shape_48(tmp_vsimem):
extent = lyr.GetExtent()
assert extent == (0, 1, 0, 1), "did not get expected extent (4)"
extent3D = lyr.GetExtent3D()
assert lyr.TestCapability(ogr.OLCFastGetExtent)
assert lyr.TestCapability(ogr.OLCFastGetExtent3D)
assert extent3D == (0, 1, 0, 1, 1, 3), "did not get expected extent 3D"
ds = None
ogr.GetDriverByName("ESRI Shapefile").DeleteDataSource(
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogr_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ extern "C++"
OGREnvelope3D &operator=(const OGREnvelope3D &) = default;

/** Returns TRUE if MinZ and MaxZ are both valid numbers. */
int Is3D() const
bool Is3D() const
{
return !std::isnan(MinZ) && !std::isnan(MaxZ);
}
Expand Down
13 changes: 11 additions & 2 deletions ogr/ogrsf_frmts/shape/ogrshapelayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1699,10 +1699,19 @@ OGRErr OGRShapeLayer::GetExtent3D(int, OGREnvelope3D *psExtent3D, int bForce)

psExtent3D->MinX = adMin[0];
psExtent3D->MinY = adMin[1];
psExtent3D->MinZ = adMin[2];
psExtent3D->MaxX = adMax[0];
psExtent3D->MaxY = adMax[1];
psExtent3D->MaxZ = adMax[2];

if (OGR_GT_HasZ(poFeatureDefn->GetGeomType()))
{
psExtent3D->MinZ = adMin[2];
psExtent3D->MaxZ = adMax[2];
}
else
{
psExtent3D->MinZ = std::numeric_limits<double>::quiet_NaN();
psExtent3D->MaxZ = std::numeric_limits<double>::quiet_NaN();
}

if (CPLIsNan(adMin[0]) || CPLIsNan(adMin[1]) || CPLIsNan(adMax[0]) ||
CPLIsNan(adMax[1]))
Expand Down
1 change: 1 addition & 0 deletions swig/include/ogr.i
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ typedef void retGetPoints;
%constant char *OLCFastSpatialFilter = "FastSpatialFilter";
%constant char *OLCFastFeatureCount = "FastFeatureCount";
%constant char *OLCFastGetExtent = "FastGetExtent";
%constant char *OLCFastGetExtent3D = "FastGetExtent3D";
%constant char *OLCCreateField = "CreateField";
%constant char *OLCDeleteField = "DeleteField";
%constant char *OLCReorderFields = "ReorderFields";
Expand Down

0 comments on commit e877373

Please sign in to comment.