gmlfeatureclass.cpp

来自「支持各种栅格图像和矢量图像读取的库」· C++ 代码 · 共 456 行 · 第 1/2 页

CPP
456
字号
/************************************************************************/int GMLFeatureClass::InitializeFromXML( CPLXMLNode *psRoot ){/* -------------------------------------------------------------------- *//*      Do some rudimentary checking that this is a well formed         *//*      node.                                                           *//* -------------------------------------------------------------------- */    if( psRoot == NULL         || psRoot->eType != CXT_Element         || !EQUAL(psRoot->pszValue,"GMLFeatureClass") )    {        CPLError( CE_Failure, CPLE_AppDefined,                   "GMLFeatureClass::InitializeFromXML() called on %s node!",                  psRoot->pszValue );        return FALSE;    }    if( CPLGetXMLValue( psRoot, "Name", NULL ) == NULL )    {        CPLError( CE_Failure, CPLE_AppDefined,                   "GMLFeatureClass has no <Name> element." );        return FALSE;    }/* -------------------------------------------------------------------- *//*      Collect base info.                                              *//* -------------------------------------------------------------------- */    CPLFree( m_pszName );    m_pszName = CPLStrdup( CPLGetXMLValue( psRoot, "Name", NULL ) );        SetElementName( CPLGetXMLValue( psRoot, "ElementPath", m_pszName ) );    const char *pszGPath = CPLGetXMLValue( psRoot, "GeometryElementPath", "" );        if( strlen( pszGPath ) > 0 )        SetGeometryElement( pszGPath );/* -------------------------------------------------------------------- *//*      Collect dataset specific info.                                  *//* -------------------------------------------------------------------- */    CPLXMLNode *psDSI = CPLGetXMLNode( psRoot, "DatasetSpecificInfo" );    if( psDSI != NULL )    {        const char *pszValue;        pszValue = CPLGetXMLValue( psDSI, "FeatureCount", NULL );        if( pszValue != NULL )            SetFeatureCount( atoi(pszValue) );        // Eventually we should support XML subtrees.        pszValue = CPLGetXMLValue( psDSI, "ExtraInfo", NULL );        if( pszValue != NULL )            SetExtraInfo( pszValue );        if( CPLGetXMLValue( psDSI, "ExtentXMin", NULL ) != NULL             && CPLGetXMLValue( psDSI, "ExtentXMax", NULL ) != NULL            && CPLGetXMLValue( psDSI, "ExtentYMin", NULL ) != NULL            && CPLGetXMLValue( psDSI, "ExtentYMax", NULL ) != NULL )        {            SetExtents( atof(CPLGetXMLValue( psDSI, "ExtentXMin", "0.0" )),                        atof(CPLGetXMLValue( psDSI, "ExtentXMax", "0.0" )),                        atof(CPLGetXMLValue( psDSI, "ExtentYMin", "0.0" )),                        atof(CPLGetXMLValue( psDSI, "ExtentYMax", "0.0" )) );        }    }    /* -------------------------------------------------------------------- *//*      Collect property definitions.                                   *//* -------------------------------------------------------------------- */    for( CPLXMLNode *psThis = psRoot->psChild;         psThis != NULL; psThis = psThis->psNext )    {        if( EQUAL(psThis->pszValue, "PropertyDefn") )        {            const char *pszName = CPLGetXMLValue( psThis, "Name", NULL );            const char *pszType = CPLGetXMLValue( psThis, "Type", "Untyped" );            GMLPropertyDefn *poPDefn;            if( pszName == NULL )            {                CPLError( CE_Failure, CPLE_AppDefined,                           "GMLFeatureClass %s has a PropertyDefn without a <Name>..",                          m_pszName );                return FALSE;            }            poPDefn = new GMLPropertyDefn(                 pszName, CPLGetXMLValue( psThis, "ElementPath", NULL ) );                        if( EQUAL(pszType,"Untyped") )                poPDefn->SetType( GMLPT_Untyped );            else if( EQUAL(pszType,"String") )             {                poPDefn->SetType( GMLPT_String );                poPDefn->SetWidth( atoi( CPLGetXMLValue( psThis, "Width", "0" ) ) );            }            else if( EQUAL(pszType,"Integer") )                poPDefn->SetType( GMLPT_Integer );            else if( EQUAL(pszType,"Real") )                poPDefn->SetType( GMLPT_Real );            else if( EQUAL(pszType,"Complex") )                poPDefn->SetType( GMLPT_Complex );            else            {                CPLError( CE_Failure, CPLE_AppDefined,                           "Unrecognised property type %s.",                           pszType );                return FALSE;            }            AddProperty( poPDefn );        }    }    return TRUE;}/************************************************************************//*                           SerializeToXML()                           *//************************************************************************/CPLXMLNode *GMLFeatureClass::SerializeToXML(){    CPLXMLNode  *psRoot;    int         iProperty;/* -------------------------------------------------------------------- *//*      Set feature class and core information.                         *//* -------------------------------------------------------------------- */    psRoot = CPLCreateXMLNode( NULL, CXT_Element, "GMLFeatureClass" );    CPLCreateXMLElementAndValue( psRoot, "Name", GetName() );    CPLCreateXMLElementAndValue( psRoot, "ElementPath", GetElementName() );    if( GetGeometryElement() != NULL && strlen(GetGeometryElement()) > 0 )        CPLCreateXMLElementAndValue( psRoot, "GeometryElementPath",                                      GetGeometryElement() );/* -------------------------------------------------------------------- *//*      Write out dataset specific information.                         *//* -------------------------------------------------------------------- */    CPLXMLNode *psDSI;    if( m_bHaveExtents || m_nFeatureCount != -1 || m_pszExtraInfo != NULL )    {        psDSI = CPLCreateXMLNode( psRoot, CXT_Element, "DatasetSpecificInfo" );        if( m_nFeatureCount != -1 )        {            char szValue[128];            sprintf( szValue, "%d", m_nFeatureCount );            CPLCreateXMLElementAndValue( psDSI, "FeatureCount", szValue );        }        if( m_bHaveExtents )        {            char szValue[128];            sprintf( szValue, "%.5f", m_dfXMin );            CPLCreateXMLElementAndValue( psDSI, "ExtentXMin", szValue );            sprintf( szValue, "%.5f", m_dfXMax );            CPLCreateXMLElementAndValue( psDSI, "ExtentXMax", szValue );            sprintf( szValue, "%.5f", m_dfYMin );            CPLCreateXMLElementAndValue( psDSI, "ExtentYMin", szValue );            sprintf( szValue, "%.5f", m_dfYMax );            CPLCreateXMLElementAndValue( psDSI, "ExtentYMax", szValue );        }        if( m_pszExtraInfo )            CPLCreateXMLElementAndValue( psDSI, "ExtraInfo", m_pszExtraInfo );    }    /* -------------------------------------------------------------------- *//*      emit property information.                                      *//* -------------------------------------------------------------------- */    for( iProperty = 0; iProperty < GetPropertyCount(); iProperty++ )    {        GMLPropertyDefn *poPDefn = GetProperty( iProperty );        CPLXMLNode *psPDefnNode;        const char *pszTypeName = "Unknown";        psPDefnNode = CPLCreateXMLNode( psRoot, CXT_Element, "PropertyDefn" );        CPLCreateXMLElementAndValue( psPDefnNode, "Name",                                      poPDefn->GetName() );        CPLCreateXMLElementAndValue( psPDefnNode, "ElementPath",                                      poPDefn->GetSrcElement() );        switch( poPDefn->GetType() )        {          case GMLPT_Untyped:            pszTypeName = "Untyped";            break;                      case GMLPT_String:            pszTypeName = "String";            break;                      case GMLPT_Integer:            pszTypeName = "Integer";            break;                      case GMLPT_Real:            pszTypeName = "Real";            break;                      case GMLPT_Complex:            pszTypeName = "Complex";            break;        }        CPLCreateXMLElementAndValue( psPDefnNode, "Type", pszTypeName );        if( EQUAL(pszTypeName,"String") )        {            char szMaxLength[48];            sprintf(szMaxLength, "%d", poPDefn->GetWidth());            CPLCreateXMLElementAndValue ( psPDefnNode, "Width", szMaxLength );        }    }    return psRoot;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?