| 1 |
/****************************************************************************** |
| 2 |
* |
| 3 |
* Project: OpenGIS Simple Features for OpenDRIVE |
| 4 |
* Purpose: Implementation of ReferenceLine layer. |
| 5 |
* Author: Michael Scholz, German Aerospace Center (DLR) |
| 6 |
* Gülsen Bardak, German Aerospace Center (DLR) |
| 7 |
* |
| 8 |
****************************************************************************** |
| 9 |
* Copyright 2024 German Aerospace Center (DLR), Institute of Transportation Systems |
| 10 |
* |
| 11 |
* SPDX-License-Identifier: MIT |
| 12 |
****************************************************************************/ |
| 13 |
|
| 14 |
#include "ogr_api.h" |
| 15 |
#include "ogr_geometry.h" |
| 16 |
#include "ogr_xodr.h" |
| 17 |
|
| 18 |
OGRXODRLayerReferenceLine::OGRXODRLayerReferenceLine( |
| 19 |
const RoadElements &xodrRoadElements, const std::string &proj4Defn) |
| 20 |
: OGRXODRLayer(xodrRoadElements, proj4Defn) |
| 21 |
{ |
| 22 |
m_poFeatureDefn = |
| 23 |
std::make_unique<OGRFeatureDefn>(FEATURE_CLASS_NAME.c_str()); |
| 24 |
m_poFeatureDefn->Reference(); |
| 25 |
SetDescription(FEATURE_CLASS_NAME.c_str()); |
| 26 |
|
| 27 |
OGRwkbGeometryType wkbLineStringWithZ = OGR_GT_SetZ(wkbLineString); |
| 28 |
m_poFeatureDefn->SetGeomType(wkbLineStringWithZ); |
| 29 |
if (!m_oSRS.IsEmpty()) |
| 30 |
m_poFeatureDefn->GetGeomFieldDefn(0)->SetSpatialRef(&m_oSRS); |
| 31 |
|
| 32 |
OGRFieldDefn oFieldID("ID", OFTString); |
| 33 |
m_poFeatureDefn->AddFieldDefn(&oFieldID); |
| 34 |
|
| 35 |
OGRFieldDefn oFieldLen("Length", OFTReal); |
| 36 |
m_poFeatureDefn->AddFieldDefn(&oFieldLen); |
| 37 |
|
| 38 |
OGRFieldDefn oFieldJunction("Junction", OFTString); |
| 39 |
m_poFeatureDefn->AddFieldDefn(&oFieldJunction); |
| 40 |
} |
| 41 |
|
| 42 |
int OGRXODRLayerReferenceLine::TestCapability(const char *pszCap) const |
| 43 |
{ |
| 44 |
int result = FALSE; |
| 45 |
|
| 46 |
if (EQUAL(pszCap, OLCZGeometries)) |
| 47 |
result = TRUE; |
| 48 |
|
| 49 |
return result; |
| 50 |
} |
| 51 |
|
| 52 |
OGRFeature *OGRXODRLayerReferenceLine::GetNextRawFeature() |
| 53 |
{ |
| 54 |
std::unique_ptr<OGRFeature> feature; |
| 55 |
|
| 56 |
if (m_roadIter != m_roadElements.roads.end()) |
| 57 |
{ |
| 58 |
feature = std::make_unique<OGRFeature>(m_poFeatureDefn.get()); |
| 59 |
|
| 60 |
odr::Road road = (*m_roadIter).second; |
| 61 |
odr::Line3D refLine = *m_referenceLineIter; |
| 62 |
|
| 63 |
// Populate geometry field |
| 64 |
auto lineString = std::make_unique<OGRLineString>(); |
| 65 |
for (const auto &lineVertex : refLine) |
| 66 |
{ |
| 67 |
lineString->addPoint(lineVertex[0], lineVertex[1], lineVertex[2]); |
| 68 |
} |
| 69 |
if (!m_oSRS.IsEmpty()) |
| 70 |
lineString->assignSpatialReference(&m_oSRS); |
| 71 |
feature->SetGeometryDirectly(lineString.release()); |
| 72 |
|
| 73 |
// Populate other fields |
| 74 |
feature->SetField("ID", road.id.c_str()); |
| 75 |
feature->SetField("Length", road.length); |
| 76 |
feature->SetField("Junction", road.junction.c_str()); |
| 77 |
feature->SetFID(m_nNextFID++); |
| 78 |
|
| 79 |
++m_roadIter; |
| 80 |
++m_referenceLineIter; |
| 81 |
} |
| 82 |
|
| 83 |
if (feature) |
| 84 |
{ |
| 85 |
return feature.release(); |
| 86 |
} |
| 87 |
else |
| 88 |
{ |
| 89 |
// End of features for the given layer reached. |
| 90 |
return nullptr; |
| 91 |
} |
| 92 |
} |