Skip to content

Commit 2231508

Browse files
authored
Merge pull request #11549 from OSGeo/backport-11543-to-release/3.10
[Backport release/3.10] OGR VRT: fix SrcRegion.clip at OGRVRTLayer level
2 parents 15047a3 + bfcbe18 commit 2231508

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

autotest/ogr/ogr_vrt.py

+29
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,35 @@ def test_ogr_vrt_16(tmp_path):
625625
vrt_ds = None
626626

627627

628+
###############################################################################
629+
# Test SrcRegion.clip
630+
631+
632+
@pytest.mark.require_driver("CSV")
633+
@pytest.mark.require_geos
634+
def test_ogr_vrt_SrcRegion_clip(tmp_path):
635+
636+
f = open(tmp_path / "test.csv", "wb")
637+
f.write("wkt_geom,val1,val2\n".encode("ascii"))
638+
f.write('"LINESTRING (-1 0.5,1.5 0.5)",,\n'.encode("ascii"))
639+
f.close()
640+
641+
vrt_xml = f"""
642+
<OGRVRTDataSource>
643+
<OGRVRTLayer name="test">
644+
<SrcDataSource relativeToVRT="0">{tmp_path}/test.csv</SrcDataSource>
645+
<SrcLayer>test</SrcLayer>
646+
<GeometryField encoding="WKT" field="wkt_geom"/>
647+
<SrcRegion clip="true">POLYGON((0 0,0 1,1 1,1 0,0 0))</SrcRegion>
648+
</OGRVRTLayer>
649+
</OGRVRTDataSource>"""
650+
vrt_ds = ogr.Open(vrt_xml)
651+
vrt_lyr = vrt_ds.GetLayerByName("test")
652+
feat = vrt_lyr.GetNextFeature()
653+
geom = feat.GetGeometryRef()
654+
assert geom.ExportToWkt() == "LINESTRING (0.0 0.5,1.0 0.5)"
655+
656+
628657
###############################################################################
629658
# Test explicit field definitions.
630659

ogr/ogrsf_frmts/vrt/ogrvrtlayer.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,10 @@ bool OGRVRTLayer::ParseGeometryField(CPLXMLNode *psNode,
461461
}
462462

463463
// Do we have a SrcRegion?
464-
const char *pszSrcRegion = CPLGetXMLValue(psNode, "SrcRegion", nullptr);
465-
if (pszSrcRegion == nullptr && poProps == apoGeomFieldProps[0])
466-
pszSrcRegion = CPLGetXMLValue(psNodeParent, "SrcRegion", nullptr);
464+
const CPLXMLNode *psSrcRegionNode = CPLGetXMLNode(psNode, "SrcRegion");
465+
if (psSrcRegionNode == nullptr && poProps == apoGeomFieldProps[0])
466+
psSrcRegionNode = CPLGetXMLNode(psNodeParent, "SrcRegion");
467+
const char *pszSrcRegion = CPLGetXMLValue(psSrcRegionNode, "", nullptr);
467468
if (pszSrcRegion != nullptr)
468469
{
469470
OGRGeometryFactory::createFromWkt(pszSrcRegion, nullptr,
@@ -475,7 +476,7 @@ bool OGRVRTLayer::ParseGeometryField(CPLXMLNode *psNode,
475476
}
476477

477478
poProps->bSrcClip =
478-
CPLTestBool(CPLGetXMLValue(psNode, "SrcRegion.clip", "FALSE"));
479+
CPLTestBool(CPLGetXMLValue(psSrcRegionNode, "clip", "FALSE"));
479480
}
480481

481482
// Set Extent if provided.

0 commit comments

Comments
 (0)