Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release/3.10] OGR VRT: fix SrcRegion.clip at OGRVRTLayer level #11549

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions autotest/ogr/ogr_vrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,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.

Expand Down
9 changes: 5 additions & 4 deletions ogr/ogrsf_frmts/vrt/ogrvrtlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down
Loading