Skip to content

Commit

Permalink
OGRWarpedVRT: use faster SetFrom() implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Sep 12, 2024
1 parent 63ed1ea commit 62c0a6c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions autotest/ogr/ogr_vrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -1331,11 +1331,13 @@ def test_ogr_vrt_29(tmp_path):
sr.ImportFromEPSG(4326)
lyr = ds.CreateLayer("ogr_vrt_29", srs=sr)
lyr.CreateField(ogr.FieldDefn("id", ogr.OFTInteger))
lyr.CreateField(ogr.FieldDefn("str", ogr.OFTString))

for i in range(5):
for j in range(5):
feat = ogr.Feature(lyr.GetLayerDefn())
feat.SetField(0, i * 5 + j)
feat["str"] = f"{j}-{i}"
feat.SetGeometry(
ogr.CreateGeometryFromWkt("POINT(%f %f)" % (2 + i / 5.0, 49 + j / 5.0))
)
Expand Down Expand Up @@ -1483,11 +1485,15 @@ def test_ogr_vrt_29(tmp_path):
), "did not get expected extent"

feat = lyr.GetNextFeature()
assert feat["id"] == 0
assert feat["str"] == "0-0"
ogrtest.check_feature_geometry(
feat, "POINT(426857.987717275274917 5427937.523466162383556)"
)

feat = lyr.GetNextFeature()
assert feat["id"] == 1
assert feat["str"] == "1-0"

feat.SetGeometry(None)
assert lyr.SetFeature(feat) == 0
Expand Down
8 changes: 6 additions & 2 deletions ogr/ogrsf_frmts/generic/ogrwarpedlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void OGRWarpedLayer::SetSpatialFilterRect(int iGeomField, double dfMinX,
OGRFeature *OGRWarpedLayer::SrcFeatureToWarpedFeature(OGRFeature *poSrcFeature)
{
OGRFeature *poFeature = new OGRFeature(GetLayerDefn());
poFeature->SetFrom(poSrcFeature);
poFeature->SetFrom(poSrcFeature, m_anMapSrcFieldsToDstFields.data());
poFeature->SetFID(poSrcFeature->GetFID());

OGRGeometry *poGeom = poFeature->GetGeomFieldRef(m_iGeomField);
Expand All @@ -181,7 +181,7 @@ OGRFeature *OGRWarpedLayer::WarpedFeatureToSrcFeature(OGRFeature *poFeature)
{
OGRFeature *poSrcFeature =
new OGRFeature(m_poDecoratedLayer->GetLayerDefn());
poSrcFeature->SetFrom(poFeature);
poSrcFeature->SetFrom(poFeature, m_anMapSrcFieldsToDstFields.data());
poSrcFeature->SetFID(poFeature->GetFID());

OGRGeometry *poGeom = poSrcFeature->GetGeomFieldRef(m_iGeomField);
Expand Down Expand Up @@ -342,6 +342,10 @@ OGRFeatureDefn *OGRWarpedLayer::GetLayerDefn()
if (m_poFeatureDefn->GetGeomFieldCount() > 0)
m_poFeatureDefn->GetGeomFieldDefn(m_iGeomField)->SetSpatialRef(m_poSRS);

const int nFieldCount = m_poFeatureDefn->GetFieldCount();
for (int i = 0; i < nFieldCount; ++i)
m_anMapSrcFieldsToDstFields.push_back(i);

return m_poFeatureDefn;
}

Expand Down
1 change: 1 addition & 0 deletions ogr/ogrsf_frmts/generic/ogrwarpedlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class OGRWarpedLayer : public OGRLayerDecorator
OGRCoordinateTransformation *m_poCT;
OGRCoordinateTransformation *m_poReversedCT; /* may be NULL */
OGRSpatialReference *m_poSRS;
std::vector<int> m_anMapSrcFieldsToDstFields{};

OGREnvelope sStaticEnvelope{};

Expand Down

0 comments on commit 62c0a6c

Please sign in to comment.