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 OSGeo#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 f0bd7cb
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
11 changes: 5 additions & 6 deletions apps/ogr2ogr_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4099,12 +4099,11 @@ bool SetupTargetLayer::CanUseWriteArrowBatch(
{
return false;
}
auto poSrcSRS = m_poUserSourceSRS ? m_poUserSourceSRS
: poSrcLayer->GetLayerDefn()
->GetGeomFieldDefn(0)
->GetSpatialRef();
if (!poSrcSRS ||
!OGRGeometryFactory::isTransformWithOptionsRegularTransform(
const auto poSrcSRS = m_poUserSourceSRS ? m_poUserSourceSRS
: poSrcLayer->GetLayerDefn()
->GetGeomFieldDefn(0)
->GetSpatialRef();
if (!OGRGeometryFactory::isTransformWithOptionsRegularTransform(
poSrcSRS, m_poOutputSRS, nullptr))
{
return false;
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
3 changes: 2 additions & 1 deletion ogr/ogrgeometryfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3886,7 +3886,8 @@ bool OGRGeometryFactory::isTransformWithOptionsRegularTransform(
return false;

#ifdef HAVE_GEOS
if (poSourceCRS->IsProjected() && poTargetCRS->IsGeographic() &&
if (poSourceCRS && poTargetCRS && poSourceCRS->IsProjected() &&
poTargetCRS->IsGeographic() &&
poTargetCRS->GetAxisMappingStrategy() == OAMS_TRADITIONAL_GIS_ORDER &&
// check that angular units is degree
std::fabs(poTargetCRS->GetAngularUnits(nullptr) -
Expand Down

0 comments on commit f0bd7cb

Please sign in to comment.