Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: OpenGIS Simple Features for OpenDRIVE 4 : * Purpose: Implementation of RoadObject 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 : OGRXODRLayerRoadObject::OGRXODRLayerRoadObject( 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 : m_poFeatureDefn->SetGeomType(wkbTINZ); 28 13 : if (!m_oSRS.IsEmpty()) 29 12 : m_poFeatureDefn->GetGeomFieldDefn(0)->SetSpatialRef(&m_oSRS); 30 : 31 26 : OGRFieldDefn oFieldObjectID("ObjectID", OFTString); 32 13 : m_poFeatureDefn->AddFieldDefn(&oFieldObjectID); 33 : 34 26 : OGRFieldDefn oFieldRoadID("RoadID", OFTString); 35 13 : m_poFeatureDefn->AddFieldDefn(&oFieldRoadID); 36 : 37 26 : OGRFieldDefn oFieldType("Type", OFTString); 38 13 : m_poFeatureDefn->AddFieldDefn(&oFieldType); 39 : 40 26 : OGRFieldDefn oFieldObjectName("Name", OFTString); 41 13 : m_poFeatureDefn->AddFieldDefn(&oFieldObjectName); 42 13 : } 43 : 44 32 : int OGRXODRLayerRoadObject::TestCapability(const char *pszCap) 45 : { 46 32 : int result = FALSE; 47 : 48 32 : if (EQUAL(pszCap, OLCZGeometries)) 49 3 : result = TRUE; 50 : 51 32 : return result; 52 : } 53 : 54 7438 : OGRFeature *OGRXODRLayerRoadObject::GetNextRawFeature() 55 : { 56 7438 : std::unique_ptr<OGRFeature> feature; 57 : 58 7438 : if (m_roadObjectIter != m_roadElements.roadObjects.end()) 59 : { 60 7410 : feature = std::make_unique<OGRFeature>(m_poFeatureDefn.get()); 61 : 62 14820 : odr::RoadObject roadObject = *m_roadObjectIter; 63 14820 : odr::Mesh3D roadObjectMesh = *m_roadObjectMeshesIter; 64 : 65 : // Populate geometry field 66 : // In contrast to other XODR layers, dissolving of RoadObject TINs is not an option, because faces of "true" 3D objects might collapse. 67 : std::unique_ptr<OGRTriangulatedSurface> tin = 68 14820 : triangulateSurface(roadObjectMesh); 69 7410 : if (!m_oSRS.IsEmpty()) 70 7410 : tin->assignSpatialReference(&m_oSRS); 71 7410 : feature->SetGeometryDirectly(tin.release()); 72 : 73 : // Populate other fields 74 7410 : feature->SetField(m_poFeatureDefn->GetFieldIndex("ObjectID"), 75 : roadObject.id.c_str()); 76 7410 : feature->SetField(m_poFeatureDefn->GetFieldIndex("RoadID"), 77 : roadObject.road_id.c_str()); 78 7410 : feature->SetField(m_poFeatureDefn->GetFieldIndex("Type"), 79 : roadObject.type.c_str()); 80 7410 : feature->SetField(m_poFeatureDefn->GetFieldIndex("Name"), 81 : roadObject.name.c_str()); 82 7410 : feature->SetFID(m_nNextFID++); 83 : 84 7410 : ++m_roadObjectIter; 85 7410 : ++m_roadObjectMeshesIter; 86 : } 87 : 88 7438 : if (feature) 89 : { 90 7410 : return feature.release(); 91 : } 92 : else 93 : { 94 : // End of features for the given layer reached. 95 28 : return nullptr; 96 : } 97 : }