Skip to content
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

OpenFileGDB: add partial read-only support for tables with 64-bit ObjectIDs #9980

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
÷^"ѾˆSÁֈ,~ÑcÁ÷^"ÑNYWAֈ,~ÑcA
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
157 changes: 136 additions & 21 deletions autotest/ogr/ogr_openfilegdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,17 +781,13 @@ def test_ogr_openfilegdb_4():
###############################################################################
# Test use of attribute indexes on truncated strings

IDX_NOT_USED = 0
IDX_USED = 1

def test_ogr_openfilegdb_str_indexed_truncated():

ds = ogr.Open("data/filegdb/test_str_indexed_truncated.gdb")

lyr = ds.GetLayerByName("test")

IDX_NOT_USED = 0
IDX_USED = 1

tests = [
@pytest.mark.parametrize(
"where_clause, fids, expected_attr_index_use",
[
("str = 'a'", [1], IDX_USED),
("str = 'aa'", [2], IDX_USED),
("str != 'aa'", [1, 3], IDX_NOT_USED),
Expand All @@ -814,19 +810,26 @@ def test_ogr_openfilegdb_str_indexed_truncated():
("str IN ('aaa ')", [], IDX_USED),
("str IN ('aaaX')", [], IDX_USED),
("str IN ('aaaXX')", [], IDX_USED),
]
for where_clause, fids, expected_attr_index_use in tests:
],
)
def test_ogr_openfilegdb_str_indexed_truncated(
where_clause, fids, expected_attr_index_use
):

lyr.SetAttributeFilter(where_clause)
sql_lyr = ds.ExecuteSQL("GetLayerAttrIndexUse %s" % lyr.GetName())
attr_index_use = int(sql_lyr.GetNextFeature().GetField(0))
ds.ReleaseResultSet(sql_lyr)
assert attr_index_use == expected_attr_index_use, (
where_clause,
fids,
expected_attr_index_use,
)
assert [f.GetFID() for f in lyr] == fids, (where_clause, fids)
ds = ogr.Open("data/filegdb/test_str_indexed_truncated.gdb")

lyr = ds.GetLayerByName("test")

lyr.SetAttributeFilter(where_clause)
sql_lyr = ds.ExecuteSQL("GetLayerAttrIndexUse %s" % lyr.GetName())
attr_index_use = int(sql_lyr.GetNextFeature().GetField(0))
ds.ReleaseResultSet(sql_lyr)
assert attr_index_use == expected_attr_index_use, (
where_clause,
fids,
expected_attr_index_use,
)
assert [f.GetFID() for f in lyr] == fids, (where_clause, fids)


###############################################################################
Expand Down Expand Up @@ -2734,3 +2737,115 @@ def error_handler(klass, type, msg):
"file using Compressed Data Format (CDF) that is unhandled by the OpenFileGDB driver, but could be handled by the FileGDB driver"
in msgs[0]
)


###############################################################################
# Test reading a database with a layer with 64-bit OBJETID, non sparse


def test_ogr_openfilegdb_read_objectid_64bit_non_sparse():

ds = ogr.Open("data/filegdb/objectid64/3features.gdb")
lyr = ds.GetLayer(0)
assert lyr.GetFeatureCount() == 3

f = lyr.GetNextFeature()
assert f.GetFID() == 1
assert f["Shape_Length"] == pytest.approx(3140.05912327677)
assert f["Shape_Area"] == pytest.approx(217981.09775568)
g1 = f.GetGeometryRef()
assert g1 is not None
minx, maxx, miny, maxy = g1.GetEnvelope()

f = lyr.GetNextFeature()
assert f.GetFID() == 2
assert f["Shape_Length"] == pytest.approx(3078.7376875286)
assert f["Shape_Area"] == pytest.approx(538056.426171967)
assert f.GetGeometryRef() is not None

f = lyr.GetNextFeature()
assert f.GetFID() == 3
assert f["Shape_Length"] == pytest.approx(3330.7300497069)
assert f["Shape_Area"] == pytest.approx(631040.074244291)
assert f.GetGeometryRef() is not None

assert lyr.GetNextFeature() is None

x = (minx + maxx) / 2
y = (miny + maxy) / 2
lyr.SetSpatialFilterRect(x, y, x, y)
lyr.ResetReading()
assert lyr.GetFeatureCount() == 1

ds = ogr.Open("data/filegdb/objectid64/3features.gdb", update=1)
lyr = ds.GetLayer(0)
with pytest.raises(Exception, match="Cannot open testpolygon in update mode"):
lyr.TestCapability(ogr.OLCSequentialWrite)


def test_ogr_openfilegdb_read_objectid_64bit_non_sparse_test_ogrsf(ogrsf_path):
ret = gdaltest.runexternal(
ogrsf_path + " -ro data/filegdb/objectid64/3features.gdb"
)

success = "INFO" in ret and "ERROR" not in ret
assert success


###############################################################################
# Test reading a database with layers with 64-bit OBJETID, sparse


def test_ogr_openfilegdb_read_objectid_64bit_sparse():

ds = ogr.Open("data/filegdb/objectid64/with_holes_8.gdb")

lyr = ds.GetLayerByName("with_holes_8_a")
assert lyr.GetFeatureCount() == 1
f = lyr.GetNextFeature()
assert f.GetFID() == 123456

lyr = ds.GetLayerByName("with_holes_8_b")
assert lyr.GetFeatureCount() == 1
f = lyr.GetNextFeature()
assert f.GetFID() == 1234567

lyr = ds.GetLayerByName("with_holes_8_c")
with gdal.quiet_errors():
assert lyr.GetFeatureCount() == 1
assert "Due to partial reverse engineering of the format" in gdal.GetLastErrorMsg()
f = lyr.GetNextFeature()
# This should be 12345678
assert f.GetFID() == 334

lyr = ds.GetLayerByName("with_holes_8_d")
with gdal.quiet_errors():
assert lyr.GetFeatureCount() == 1
assert "Due to partial reverse engineering of the format" in gdal.GetLastErrorMsg()
f = lyr.GetNextFeature()
# This should be 123456789
assert f.GetFID() == 277

lyr = ds.GetLayerByName("with_holes_8_e")
with gdal.quiet_errors():
assert lyr.GetFeatureCount() == 1
assert "Due to partial reverse engineering of the format" in gdal.GetLastErrorMsg()
f = lyr.GetNextFeature()
# This should be 1234567890
assert f.GetFID() == 722

lyr = ds.GetLayerByName("with_holes_8_f")
with gdal.quiet_errors():
assert lyr.GetFeatureCount() == 5
assert "Due to partial reverse engineering of the format" in gdal.GetLastErrorMsg()
# Should be 123456, 1234567, 12345678, 123456789, 1234567890
assert [f.GetFID() for f in lyr] == [576, 1671, 2382, 3349, 4818]


def test_ogr_openfilegdb_read_objectid_64bit_sparse_test_ogrsf(ogrsf_path):
ret, _ = gdaltest.runexternal_out_and_err(
ogrsf_path + " -ro data/filegdb/objectid64/with_holes_8.gdb"
)

success = "INFO" in ret and "ERROR" not in ret
assert success