Ejemplo n.º 1
0
CPLErr GNMGenericNetwork::CheckLayerDriver(const char* pszDefaultDriverName,
                                        char **papszOptions)
{
    if(NULL == m_poLayerDriver)
    {
        const char* pszDriverName = CSLFetchNameValueDef(papszOptions,
                                                         GNM_MD_FORMAT,
                                                         pszDefaultDriverName);

        if(!CheckStorageDriverSupport(pszDriverName))
        {
            CPLError( CE_Failure, CPLE_IllegalArg, "%s driver not supported as network storage",
                      pszDriverName );
            return CE_Failure;
        }

        m_poLayerDriver = GetGDALDriverManager()->GetDriverByName(pszDriverName );
        if(NULL == m_poLayerDriver)
        {
            CPLError( CE_Failure, CPLE_IllegalArg, "%s driver not available",
                      pszDriverName );
            return CE_Failure;
        }
    }
    return CE_None;
}
Ejemplo n.º 2
0
CPLErr GNMDatabaseNetwork::Create( const char* pszFilename, char** papszOptions )
{
    FormName(pszFilename, papszOptions);

    if(m_soName.empty() || m_soNetworkFullName.empty())
    {
        CPLError( CE_Failure, CPLE_IllegalArg,
                  "The network name should be present" );
        return CE_Failure;
    }

    if(NULL == m_poDS)
    {
        m_poDS = (GDALDataset*) GDALOpenEx( m_soNetworkFullName, GDAL_OF_VECTOR |
                                       GDAL_OF_UPDATE, NULL, NULL, papszOptions );
    }

    if( NULL == m_poDS )
    {
        CPLError( CE_Failure, CPLE_OpenFailed, "Open '%s' failed",
                  m_soNetworkFullName.c_str() );
        return CE_Failure;
    }

    GDALDriver *l_poDriver = m_poDS->GetDriver();
    if(NULL == l_poDriver)
    {
        CPLError( CE_Failure, CPLE_OpenFailed, "Get dataset driver failed");
        return CE_Failure;
    }

    if(!CheckStorageDriverSupport(l_poDriver->GetDescription()))
    {
        return CE_Failure;
    }

    // check required options

    const char* pszNetworkDescription = CSLFetchNameValue(papszOptions,
                                                         GNM_MD_DESCR);
    if(NULL != pszNetworkDescription)
        sDescription = pszNetworkDescription;

    // check Spatial reference
    const char* pszSRS = CSLFetchNameValue(papszOptions, GNM_MD_SRS);
    if( NULL == pszSRS )
    {
        CPLError( CE_Failure, CPLE_IllegalArg,
                  "The network spatial reference should be present" );
        return CE_Failure;
    }
    else
    {
        OGRSpatialReference spatialRef;
        if (spatialRef.SetFromUserInput(pszSRS) != OGRERR_NONE)
        {
            CPLError( CE_Failure, CPLE_IllegalArg,
                      "The network spatial reference should be present" );
            return CE_Failure;
        }

        char *wktSrs = NULL;
        if (spatialRef.exportToWkt(&wktSrs) != OGRERR_NONE)
        {
            CPLError( CE_Failure, CPLE_IllegalArg,
                      "The network spatial reference should be present" );
            return CE_Failure;
        }
        m_soSRS = wktSrs;

        CPLFree(wktSrs);
    }

    int nResult = CheckNetworkExist(pszFilename, papszOptions);

    if(TRUE == nResult)
    {
        CPLError( CE_Failure, CPLE_IllegalArg, "The network already exist" );
        return CE_Failure;
    }

    // Create the necessary system layers and fields

    // Create meta layer

    CPLErr eResult = CreateMetadataLayer(m_poDS, GNM_VERSION_NUM);

    if(CE_None != eResult)
    {
        //an error message should come from function
        return CE_Failure;    }

    // Create graph layer

    eResult = CreateGraphLayer(m_poDS);

    if(CE_None != eResult)
    {
        DeleteMetadataLayer();
        return CE_Failure;
    }

    // Create features layer

    eResult = CreateFeaturesLayer(m_poDS);

    if(CE_None != eResult)
    {
        DeleteMetadataLayer();
        DeleteGraphLayer();
        return CE_Failure;
    }

    return CE_None;
}