Skip to content

Commit

Permalink
Merge pull request #11084 from OSGeo/backport-11054-to-release/3.10
Browse files Browse the repository at this point in the history
[Backport release/3.10] XODR: check that a .xodr filename is a 'real' file, and do not try to…
  • Loading branch information
rouault authored Oct 22, 2024
2 parents 7385648 + ea30cd1 commit 211fff6
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 32 deletions.
7 changes: 7 additions & 0 deletions autotest/ogr/data/xodr/empty.xodr
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<OpenDRIVE>
<header>
</header>
<road>
</road>
</OpenDRIVE>
13 changes: 13 additions & 0 deletions autotest/ogr/ogr_xodr.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@
xodr_file = "data/xodr/5g_living_lab_A39_Wolfsburg-West.xodr"


def test_ogr_xodr_i_do_not_exist():

assert gdal.IdentifyDriverEx("i_do_not_exist.xodr") is None


def test_ogr_xodr_empty():

gdal.ErrorReset()
with ogr.Open("data/xodr/empty.xodr") as ds:
assert gdal.GetLastErrorMsg() == ""
assert ds.GetLayerCount() == 6


def test_ogr_xodr_test_ogrsf():

import test_cli_utilities
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/xodr/ogr_xodr.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class OGRXODRLayer : public OGRLayer
protected:
RoadElements m_roadElements{};
bool m_bDissolveTIN{false};
OGRSpatialReference m_poSRS{};
OGRSpatialReference m_oSRS{};
/* Unique feature ID which is automatically incremented for any new road feature creation. */
int m_nNextFID{0};

Expand Down
4 changes: 3 additions & 1 deletion ogr/ogrsf_frmts/xodr/ogrxodrdrivercore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

int OGRXODRDriverIdentify(GDALOpenInfo *poOpenInfo)
{
return EQUAL(CPLGetExtension(poOpenInfo->pszFilename), "xodr");
return poOpenInfo->fpL != nullptr &&
EQUAL(CPLGetExtension(poOpenInfo->pszFilename), "xodr") &&
!STARTS_WITH(poOpenInfo->pszFilename, "/vsi");
}

/************************************************************************/
Expand Down
9 changes: 6 additions & 3 deletions ogr/ogrsf_frmts/xodr/ogrxodrlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Project: OpenGIS Simple Features for OpenDRIVE
* Purpose: Implementation of OGRXODRLayer.
* Author: Michael Scholz, German Aerospace Center (DLR)
* Gülsen Bardak, German Aerospace Center (DLR)
* Gülsen Bardak, German Aerospace Center (DLR)
*
******************************************************************************
* Copyright 2024 German Aerospace Center (DLR), Institute of Transportation Systems
Expand Down Expand Up @@ -34,7 +34,10 @@ OGRXODRLayer::OGRXODRLayer(const RoadElements &xodrRoadElements,
: m_roadElements(xodrRoadElements),
m_bDissolveTIN(dissolveTriangulatedSurface)
{
m_poSRS.importFromProj4(proj4Defn.c_str());
if (!proj4Defn.empty())
{
m_oSRS.importFromProj4(proj4Defn.c_str());
}
resetRoadElementIterators();
}

Expand Down Expand Up @@ -96,4 +99,4 @@ OGRXODRLayer::triangulateSurface(const odr::Mesh3D &mesh)
}

return tin;
}
}
15 changes: 10 additions & 5 deletions ogr/ogrsf_frmts/xodr/ogrxodrlayerlane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Project: OpenGIS Simple Features for OpenDRIVE
* Purpose: Implementation of Lane layer.
* Author: Michael Scholz, German Aerospace Center (DLR)
* Gülsen Bardak, German Aerospace Center (DLR)
* Gülsen Bardak, German Aerospace Center (DLR)
*
******************************************************************************
* Copyright 2024 German Aerospace Center (DLR), Institute of Transportation Systems
Expand Down Expand Up @@ -34,7 +34,10 @@ OGRXODRLayerLane::OGRXODRLayerLane(const RoadElements &xodrRoadElements,
{
m_poFeatureDefn->SetGeomType(wkbTINZ);
}
m_poFeatureDefn->GetGeomFieldDefn(0)->SetSpatialRef(&m_poSRS);
if (!m_oSRS.IsEmpty())
{
m_poFeatureDefn->GetGeomFieldDefn(0)->SetSpatialRef(&m_oSRS);
}

OGRFieldDefn oFieldLaneID("LaneID", OFTInteger);
m_poFeatureDefn->AddFieldDefn(&oFieldLaneID);
Expand Down Expand Up @@ -91,7 +94,8 @@ OGRFeature *OGRXODRLayerLane::GetNextRawFeature()
OGRGeometry *dissolvedPolygon = tin->UnaryUnion();
if (dissolvedPolygon != nullptr)
{
dissolvedPolygon->assignSpatialReference(&m_poSRS);
if (!m_oSRS.IsEmpty())
dissolvedPolygon->assignSpatialReference(&m_oSRS);
feature->SetGeometryDirectly(dissolvedPolygon);
}
else
Expand All @@ -104,7 +108,8 @@ OGRFeature *OGRXODRLayerLane::GetNextRawFeature()
}
else
{
tin->assignSpatialReference(&m_poSRS);
if (!m_oSRS.IsEmpty())
tin->assignSpatialReference(&m_oSRS);
feature->SetGeometryDirectly(tin.release());
}

Expand Down Expand Up @@ -134,4 +139,4 @@ OGRFeature *OGRXODRLayerLane::GetNextRawFeature()
// End of features for the given layer reached.
return nullptr;
}
}
}
10 changes: 6 additions & 4 deletions ogr/ogrsf_frmts/xodr/ogrxodrlayerlaneborder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Project: OpenGIS Simple Features for OpenDRIVE
* Purpose: Implementation of LaneBorder layer.
* Author: Michael Scholz, German Aerospace Center (DLR)
* Gülsen Bardak, German Aerospace Center (DLR)
* Gülsen Bardak, German Aerospace Center (DLR)
*
******************************************************************************
* Copyright 2024 German Aerospace Center (DLR), Institute of Transportation Systems
Expand All @@ -26,7 +26,8 @@ OGRXODRLayerLaneBorder::OGRXODRLayerLaneBorder(

OGRwkbGeometryType wkbLineStringWithZ = OGR_GT_SetZ(wkbLineString);
m_poFeatureDefn->SetGeomType(wkbLineStringWithZ);
m_poFeatureDefn->GetGeomFieldDefn(0)->SetSpatialRef(&m_poSRS);
if (!m_oSRS.IsEmpty())
m_poFeatureDefn->GetGeomFieldDefn(0)->SetSpatialRef(&m_oSRS);

OGRFieldDefn oFieldID("ID", OFTInteger);
m_poFeatureDefn->AddFieldDefn(&oFieldID);
Expand Down Expand Up @@ -73,7 +74,8 @@ OGRFeature *OGRXODRLayerLaneBorder::GetNextRawFeature()
lineString->addPoint(borderVertex[0], borderVertex[1],
borderVertex[2]);
}
lineString->assignSpatialReference(&m_poSRS);
if (!m_oSRS.IsEmpty())
lineString->assignSpatialReference(&m_oSRS);
feature->SetGeometryDirectly(lineString.release());

// Populate other fields
Expand Down Expand Up @@ -103,4 +105,4 @@ OGRFeature *OGRXODRLayerLaneBorder::GetNextRawFeature()
// End of features for the given layer reached.
return nullptr;
}
}
}
10 changes: 6 additions & 4 deletions ogr/ogrsf_frmts/xodr/ogrxodrlayerreferenceline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Project: OpenGIS Simple Features for OpenDRIVE
* Purpose: Implementation of ReferenceLine layer.
* Author: Michael Scholz, German Aerospace Center (DLR)
* Gülsen Bardak, German Aerospace Center (DLR)
* Gülsen Bardak, German Aerospace Center (DLR)
*
******************************************************************************
* Copyright 2024 German Aerospace Center (DLR), Institute of Transportation Systems
Expand All @@ -26,7 +26,8 @@ OGRXODRLayerReferenceLine::OGRXODRLayerReferenceLine(

OGRwkbGeometryType wkbLineStringWithZ = OGR_GT_SetZ(wkbLineString);
m_poFeatureDefn->SetGeomType(wkbLineStringWithZ);
m_poFeatureDefn->GetGeomFieldDefn(0)->SetSpatialRef(&m_poSRS);
if (!m_oSRS.IsEmpty())
m_poFeatureDefn->GetGeomFieldDefn(0)->SetSpatialRef(&m_oSRS);

OGRFieldDefn oFieldID("ID", OFTString);
m_poFeatureDefn->AddFieldDefn(&oFieldID);
Expand Down Expand Up @@ -65,7 +66,8 @@ OGRFeature *OGRXODRLayerReferenceLine::GetNextRawFeature()
{
lineString->addPoint(lineVertex[0], lineVertex[1], lineVertex[2]);
}
lineString->assignSpatialReference(&m_poSRS);
if (!m_oSRS.IsEmpty())
lineString->assignSpatialReference(&m_oSRS);
feature->SetGeometryDirectly(lineString.release());

// Populate other fields
Expand All @@ -87,4 +89,4 @@ OGRFeature *OGRXODRLayerReferenceLine::GetNextRawFeature()
// End of features for the given layer reached.
return nullptr;
}
}
}
13 changes: 8 additions & 5 deletions ogr/ogrsf_frmts/xodr/ogrxodrlayerroadmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Project: OpenGIS Simple Features for OpenDRIVE
* Purpose: Implementation of RoadMark layer.
* Author: Michael Scholz, German Aerospace Center (DLR)
* Gülsen Bardak, German Aerospace Center (DLR)
* Gülsen Bardak, German Aerospace Center (DLR)
*
******************************************************************************
* Copyright 2024 German Aerospace Center (DLR), Institute of Transportation Systems
Expand Down Expand Up @@ -34,7 +34,8 @@ OGRXODRLayerRoadMark::OGRXODRLayerRoadMark(
{
m_poFeatureDefn->SetGeomType(wkbTINZ);
}
m_poFeatureDefn->GetGeomFieldDefn(0)->SetSpatialRef(&m_poSRS);
if (!m_oSRS.IsEmpty())
m_poFeatureDefn->GetGeomFieldDefn(0)->SetSpatialRef(&m_oSRS);

OGRFieldDefn oFieldRoadID("RoadID", OFTString);
m_poFeatureDefn->AddFieldDefn(&oFieldRoadID);
Expand Down Expand Up @@ -75,7 +76,8 @@ OGRFeature *OGRXODRLayerRoadMark::GetNextRawFeature()
OGRGeometry *dissolvedPolygon = tin->UnaryUnion();
if (dissolvedPolygon != nullptr)
{
dissolvedPolygon->assignSpatialReference(&m_poSRS);
if (!m_oSRS.IsEmpty())
dissolvedPolygon->assignSpatialReference(&m_oSRS);
feature->SetGeometryDirectly(dissolvedPolygon);
}
else
Expand All @@ -88,7 +90,8 @@ OGRFeature *OGRXODRLayerRoadMark::GetNextRawFeature()
}
else
{
tin->assignSpatialReference(&m_poSRS);
if (!m_oSRS.IsEmpty())
tin->assignSpatialReference(&m_oSRS);
feature->SetGeometryDirectly(tin.release());
}

Expand All @@ -114,4 +117,4 @@ OGRFeature *OGRXODRLayerRoadMark::GetNextRawFeature()
// End of features for the given layer reached.
return nullptr;
}
}
}
10 changes: 6 additions & 4 deletions ogr/ogrsf_frmts/xodr/ogrxodrlayerroadobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Project: OpenGIS Simple Features for OpenDRIVE
* Purpose: Implementation of RoadObject layer.
* Author: Michael Scholz, German Aerospace Center (DLR)
* Gülsen Bardak, German Aerospace Center (DLR)
* Gülsen Bardak, German Aerospace Center (DLR)
*
******************************************************************************
* Copyright 2024 German Aerospace Center (DLR), Institute of Transportation Systems
Expand All @@ -25,7 +25,8 @@ OGRXODRLayerRoadObject::OGRXODRLayerRoadObject(
SetDescription(FEATURE_CLASS_NAME.c_str());

m_poFeatureDefn->SetGeomType(wkbTINZ);
m_poFeatureDefn->GetGeomFieldDefn(0)->SetSpatialRef(&m_poSRS);
if (!m_oSRS.IsEmpty())
m_poFeatureDefn->GetGeomFieldDefn(0)->SetSpatialRef(&m_oSRS);

OGRFieldDefn oFieldObjectID("ObjectID", OFTString);
m_poFeatureDefn->AddFieldDefn(&oFieldObjectID);
Expand Down Expand Up @@ -65,7 +66,8 @@ OGRFeature *OGRXODRLayerRoadObject::GetNextRawFeature()
// In contrast to other XODR layers, dissolving of RoadObject TINs is not an option, because faces of "true" 3D objects might collapse.
std::unique_ptr<OGRTriangulatedSurface> tin =
triangulateSurface(roadObjectMesh);
tin->assignSpatialReference(&m_poSRS);
if (!m_oSRS.IsEmpty())
tin->assignSpatialReference(&m_oSRS);
feature->SetGeometryDirectly(tin.release());

// Populate other fields
Expand All @@ -92,4 +94,4 @@ OGRFeature *OGRXODRLayerRoadObject::GetNextRawFeature()
// End of features for the given layer reached.
return nullptr;
}
}
}
13 changes: 8 additions & 5 deletions ogr/ogrsf_frmts/xodr/ogrxodrlayerroadsignal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Project: OpenGIS Simple Features for OpenDRIVE
* Purpose: Implementation of RoadSignal layer.
* Author: Michael Scholz, German Aerospace Center (DLR)
* Gülsen Bardak, German Aerospace Center (DLR)
* Gülsen Bardak, German Aerospace Center (DLR)
*
******************************************************************************
* Copyright 2024 German Aerospace Center (DLR), Institute of Transportation Systems
Expand Down Expand Up @@ -34,7 +34,8 @@ OGRXODRLayerRoadSignal::OGRXODRLayerRoadSignal(
{
m_poFeatureDefn->SetGeomType(wkbTINZ);
}
m_poFeatureDefn->GetGeomFieldDefn(0)->SetSpatialRef(&m_poSRS);
if (!m_oSRS.IsEmpty())
m_poFeatureDefn->GetGeomFieldDefn(0)->SetSpatialRef(&m_oSRS);

OGRFieldDefn oFieldSignalID("SignalID", OFTString);
m_poFeatureDefn->AddFieldDefn(&oFieldSignalID);
Expand Down Expand Up @@ -102,14 +103,16 @@ OGRFeature *OGRXODRLayerRoadSignal::GetNextRawFeature()
odr::Vec3D xyz = road.get_xyz(s, t, h);

auto point = std::make_unique<OGRPoint>(xyz[0], xyz[1], xyz[2]);
point->assignSpatialReference(&m_poSRS);
if (!m_oSRS.IsEmpty())
point->assignSpatialReference(&m_oSRS);
feature->SetGeometryDirectly(point.release());
}
else
{
std::unique_ptr<OGRTriangulatedSurface> tin =
triangulateSurface(roadSignalMesh);
tin->assignSpatialReference(&m_poSRS);
if (!m_oSRS.IsEmpty())
tin->assignSpatialReference(&m_oSRS);
feature->SetGeometryDirectly(tin.release());
}

Expand Down Expand Up @@ -149,4 +152,4 @@ OGRFeature *OGRXODRLayerRoadSignal::GetNextRawFeature()
// End of features for the given layer reached.
return nullptr;
}
}
}

0 comments on commit 211fff6

Please sign in to comment.