OGR_SRSNode *OGR_SRSNode::Clone() const { OGR_SRSNode *poNew = new OGR_SRSNode( pszValue ); for( int i = 0; i < nChildren; i++ ) { poNew->AddChild( papoChildNodes[i]->Clone() ); } return poNew; }
static void importXMLUnits(CPLXMLNode *psSrcXML, const char *pszClass, OGRSpatialReference *poSRS, const char *pszTarget) { const char *pszUnitName, *pszUnitsPer; OGR_SRSNode *poNode = poSRS->GetAttrNode(pszTarget); OGR_SRSNode *poUnits; CPLAssert(EQUAL(pszClass, "AngularUnit") || EQUAL(pszClass, "LinearUnit")); psSrcXML = CPLGetXMLNode(psSrcXML, pszClass); if (psSrcXML == NULL) goto DefaultTarget; pszUnitName = CPLGetXMLValue(psSrcXML, "NameSet.name", "unnamed"); if (EQUAL(pszClass, "AngularUnit")) pszUnitsPer = CPLGetXMLValue(psSrcXML, "radiansPerUnit", NULL); else pszUnitsPer = CPLGetXMLValue(psSrcXML, "metresPerUnit", NULL); if (pszUnitsPer == NULL) { CPLDebug("OGR_SRS_XML", "Missing PerUnit value for %s.", pszClass); goto DefaultTarget; } if (poNode == NULL) { CPLDebug("OGR_SRS_XML", "Can't find %s in importXMLUnits.", pszTarget); goto DefaultTarget; } if (poNode->FindChild("UNIT") != -1) { poUnits = poNode->GetChild(poNode->FindChild("UNIT")); poUnits->GetChild(0)->SetValue(pszUnitName); poUnits->GetChild(1)->SetValue(pszUnitsPer); } else { poUnits = new OGR_SRSNode("UNIT"); poUnits->AddChild(new OGR_SRSNode(pszUnitName)); poUnits->AddChild(new OGR_SRSNode(pszUnitsPer)); poNode->AddChild(poUnits); } return; DefaultTarget: poUnits = new OGR_SRSNode("UNIT"); if (EQUAL(pszClass, "AngularUnit")) { poUnits->AddChild(new OGR_SRSNode(SRS_UA_DEGREE)); poUnits->AddChild(new OGR_SRSNode(SRS_UA_DEGREE_CONV)); } else { poUnits->AddChild(new OGR_SRSNode(SRS_UL_METER)); poUnits->AddChild(new OGR_SRSNode("1.0")); } poNode->AddChild(poUnits); }