Skip to content

Commit a8f6f96

Browse files
rouaultGrok Compression
authored and
Grok Compression
committed
OGR VRT: fix SrcRegion.clip at OGRVRTLayer level
Fixes OSGeo#11519
1 parent 46e2295 commit a8f6f96

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
@@ -624,6 +624,35 @@ def test_ogr_vrt_16(tmp_path):
624624
vrt_ds = None
625625

626626

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

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)