Merge pull request #11543 from rouault/fix_11519

OGR VRT: fix SrcRegion.clip at OGRVRTLayer level
This commit is contained in:
Even Rouault 2024-12-26 16:31:59 +01:00 committed by GitHub
commit c904cbc7ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 4 deletions

View File

@ -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"""
<OGRVRTDataSource>
<OGRVRTLayer name="test">
<SrcDataSource relativeToVRT="0">{tmp_path}/test.csv</SrcDataSource>
<SrcLayer>test</SrcLayer>
<GeometryField encoding="WKT" field="wkt_geom"/>
<SrcRegion clip="true">POLYGON((0 0,0 1,1 1,1 0,0 0))</SrcRegion>
</OGRVRTLayer>
</OGRVRTDataSource>"""
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.

View File

@ -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,
@ -475,7 +476,7 @@ bool OGRVRTLayer::ParseGeometryField(CPLXMLNode *psNode,
}
poProps->bSrcClip =
CPLTestBool(CPLGetXMLValue(psNode, "SrcRegion.clip", "FALSE"));
CPLTestBool(CPLGetXMLValue(psSrcRegionNode, "clip", "FALSE"));
}
// Set Extent if provided.