diff --git a/autotest/ogr/ogr_vrt.py b/autotest/ogr/ogr_vrt.py index 8c46606b026a..f9a21f5c9f6d 100755 --- a/autotest/ogr/ogr_vrt.py +++ b/autotest/ogr/ogr_vrt.py @@ -624,6 +624,35 @@ def test_ogr_vrt_16(tmp_path): vrt_ds = None +############################################################################### +# Test SrcRegion.clip + + +@pytest.mark.require_driver("CSV") +@pytest.mark.require_geos +def test_ogr_vrt_SrcRegion_clip(tmp_path): + + f = open(tmp_path / "test.csv", "wb") + f.write("wkt_geom,val1,val2\n".encode("ascii")) + f.write('"LINESTRING (-1 0.5,1.5 0.5)",,\n'.encode("ascii")) + f.close() + + vrt_xml = f""" + + + {tmp_path}/test.csv + test + + POLYGON((0 0,0 1,1 1,1 0,0 0)) + +""" + vrt_ds = ogr.Open(vrt_xml) + vrt_lyr = vrt_ds.GetLayerByName("test") + feat = vrt_lyr.GetNextFeature() + geom = feat.GetGeometryRef() + assert geom.ExportToWkt() == "LINESTRING (0.0 0.5,1.0 0.5)" + + ############################################################################### # Test explicit field definitions. diff --git a/ogr/ogrsf_frmts/vrt/ogrvrtlayer.cpp b/ogr/ogrsf_frmts/vrt/ogrvrtlayer.cpp index 98dcfca75fec..c1d0664155d3 100644 --- a/ogr/ogrsf_frmts/vrt/ogrvrtlayer.cpp +++ b/ogr/ogrsf_frmts/vrt/ogrvrtlayer.cpp @@ -461,9 +461,10 @@ bool OGRVRTLayer::ParseGeometryField(CPLXMLNode *psNode, } // Do we have a SrcRegion? - const char *pszSrcRegion = CPLGetXMLValue(psNode, "SrcRegion", nullptr); - if (pszSrcRegion == nullptr && poProps == apoGeomFieldProps[0]) - pszSrcRegion = CPLGetXMLValue(psNodeParent, "SrcRegion", nullptr); + const CPLXMLNode *psSrcRegionNode = CPLGetXMLNode(psNode, "SrcRegion"); + if (psSrcRegionNode == nullptr && poProps == apoGeomFieldProps[0]) + psSrcRegionNode = CPLGetXMLNode(psNodeParent, "SrcRegion"); + const char *pszSrcRegion = CPLGetXMLValue(psSrcRegionNode, "", nullptr); if (pszSrcRegion != nullptr) { OGRGeometryFactory::createFromWkt(pszSrcRegion, nullptr, @@ -478,7 +479,7 @@ bool OGRVRTLayer::ParseGeometryField(CPLXMLNode *psNode, } poProps->bSrcClip = - CPLTestBool(CPLGetXMLValue(psNode, "SrcRegion.clip", "FALSE")); + CPLTestBool(CPLGetXMLValue(psSrcRegionNode, "clip", "FALSE")); } // Set Extent if provided.