Skip to content

Commit

Permalink
ogr2ogr: fix crash with -ct and using Arrow code path (e.g source is …
Browse files Browse the repository at this point in the history
…GeoPackage) (3.10.0 regression)

Fixes #11438

Passing "--config OGR2OGR_USE_ARROW_API=NO" or "-t_srs {srs_def}" can be used as a workaround
  • Loading branch information
rouault committed Dec 5, 2024
1 parent 79ffe0a commit 91e2b01
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apps/ogr2ogr_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4103,7 +4103,7 @@ bool SetupTargetLayer::CanUseWriteArrowBatch(
: poSrcLayer->GetLayerDefn()
->GetGeomFieldDefn(0)
->GetSpatialRef();
if (!poSrcSRS ||
if (poSrcSRS && m_poOutputSRS &&
!OGRGeometryFactory::isTransformWithOptionsRegularTransform(
poSrcSRS, m_poOutputSRS, nullptr))
{
Expand Down
40 changes: 40 additions & 0 deletions autotest/utilities/test_ogr2ogr_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2924,6 +2924,46 @@ def my_handler(errorClass, errno, msg):
assert f.GetGeometryRef().GetGeometryCount() == 2


###############################################################################
# Test -ct in Arrow code path
# Cf https://github.com/OSGeo/gdal/issues/11438


@gdaltest.enable_exceptions()
def test_ogr2ogr_lib_reproject_arrow_optim_ct(tmp_vsimem):

srcDS = gdal.GetDriverByName("Memory").Create("", 0, 0, 0, gdal.GDT_Unknown)
srs = osr.SpatialReference()
srs.ImportFromEPSG(32632)
srcLayer = srcDS.CreateLayer("test", srs=srs)
f = ogr.Feature(srcLayer.GetLayerDefn())
f.SetGeometry(ogr.CreateGeometryFromWkt("POINT (1 2)"))
srcLayer.CreateFeature(f)

got_msg = []

def my_handler(errorClass, errno, msg):
got_msg.append(msg)
return

config_options = {"CPL_DEBUG": "ON", "OGR2OGR_USE_ARROW_API": "YES"}
with gdaltest.error_handler(my_handler), gdaltest.config_options(config_options):
ds = gdal.VectorTranslate(
"",
srcDS,
format="Memory",
reproject=True,
coordinateOperation="+proj=affine +s11=-1",
)

assert "OGR2OGR: Using WriteArrowBatch()" in got_msg

lyr = ds.GetLayer(0)
assert lyr.GetSpatialRef().GetAuthorityCode(None) == "32632"
f = lyr.GetNextFeature()
assert f.GetGeometryRef().ExportToWkt() == "POINT (-1 2)"


###############################################################################
# Test -explodecollections on empty geometries

Expand Down

0 comments on commit 91e2b01

Please sign in to comment.