Line data Source code
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 13 : OGRXODRLayerReferenceLine::OGRXODRLayerReferenceLine( 19 13 : const RoadElements &xodrRoadElements, const std::string &proj4Defn) 20 13 : : OGRXODRLayer(xodrRoadElements, proj4Defn) 21 : { 22 : m_poFeatureDefn = 23 13 : std::make_unique<OGRFeatureDefn>(FEATURE_CLASS_NAME.c_str()); 24 13 : m_poFeatureDefn->Reference(); 25 13 : SetDescription(FEATURE_CLASS_NAME.c_str()); 26 : 27 13 : OGRwkbGeometryType wkbLineStringWithZ = OGR_GT_SetZ(wkbLineString); 28 13 : m_poFeatureDefn->SetGeomType(wkbLineStringWithZ); 29 13 : if (!m_oSRS.IsEmpty()) 30 12 : m_poFeatureDefn->GetGeomFieldDefn(0)->SetSpatialRef(&m_oSRS); 31 : 32 26 : OGRFieldDefn oFieldID("ID", OFTString); 33 13 : m_poFeatureDefn->AddFieldDefn(&oFieldID); 34 : 35 26 : OGRFieldDefn oFieldLen("Length", OFTReal); 36 13 : m_poFeatureDefn->AddFieldDefn(&oFieldLen); 37 : 38 26 : OGRFieldDefn oFieldJunction("Junction", OFTString); 39 13 : m_poFeatureDefn->AddFieldDefn(&oFieldJunction); 40 13 : } 41 : 42 36 : int OGRXODRLayerReferenceLine::TestCapability(const char *pszCap) 43 : { 44 36 : int result = FALSE; 45 : 46 36 : if (EQUAL(pszCap, OLCZGeometries)) 47 3 : result = TRUE; 48 : 49 36 : return result; 50 : } 51 : 52 1685 : OGRFeature *OGRXODRLayerReferenceLine::GetNextRawFeature() 53 : { 54 1685 : std::unique_ptr<OGRFeature> feature; 55 : 56 1685 : if (m_roadIter != m_roadElements.roads.end()) 57 : { 58 1645 : feature = std::make_unique<OGRFeature>(m_poFeatureDefn.get()); 59 : 60 3290 : odr::Road road = (*m_roadIter).second; 61 3290 : odr::Line3D refLine = *m_referenceLineIter; 62 : 63 : // Populate geometry field 64 3290 : auto lineString = std::make_unique<OGRLineString>(); 65 30662 : for (const auto &lineVertex : refLine) 66 : { 67 29017 : lineString->addPoint(lineVertex[0], lineVertex[1], lineVertex[2]); 68 : } 69 1645 : if (!m_oSRS.IsEmpty()) 70 1645 : lineString->assignSpatialReference(&m_oSRS); 71 1645 : feature->SetGeometryDirectly(lineString.release()); 72 : 73 : // Populate other fields 74 1645 : feature->SetField("ID", road.id.c_str()); 75 1645 : feature->SetField("Length", road.length); 76 1645 : feature->SetField("Junction", road.junction.c_str()); 77 1645 : feature->SetFID(m_nNextFID++); 78 : 79 1645 : ++m_roadIter; 80 1645 : ++m_referenceLineIter; 81 : } 82 : 83 1685 : if (feature) 84 : { 85 1645 : return feature.release(); 86 : } 87 : else 88 : { 89 : // End of features for the given layer reached. 90 40 : return nullptr; 91 : } 92 : }