CPLErr GNMDatabaseNetwork::Open(GDALOpenInfo *poOpenInfo) { FormName(poOpenInfo->pszFilename, poOpenInfo->papszOpenOptions); if(CSLFindName(poOpenInfo->papszOpenOptions, "LIST_ALL_TABLES") == -1) poOpenInfo->papszOpenOptions = CSLAddNameValue( poOpenInfo->papszOpenOptions, "LIST_ALL_TABLES", "YES"); m_poDS = (GDALDataset*) GDALOpenEx( m_soNetworkFullName, GDAL_OF_VECTOR | GDAL_OF_UPDATE, NULL, NULL, poOpenInfo->papszOpenOptions ); if( NULL == m_poDS ) { CPLError( CE_Failure, CPLE_OpenFailed, "Open '%s' failed", m_soNetworkFullName.c_str() ); return CE_Failure; } // There should be only one schema so no schema name can be in table name if(LoadMetadataLayer(m_poDS) != CE_None) { return CE_Failure; } if(LoadGraphLayer(m_poDS) != CE_None) { return CE_Failure; } if(LoadFeaturesLayer(m_poDS) != CE_None) { return CE_Failure; } return CE_None; }
CPLErr GNMFileNetwork::Open(GDALOpenInfo *poOpenInfo) { m_soNetworkFullName = poOpenInfo->pszFilename; char **papszFiles = CPLReadDir( m_soNetworkFullName ); if( CSLCount(papszFiles) == 0 ) { CPLError( CE_Failure, CPLE_OpenFailed, "Open '%s' file failed", m_soNetworkFullName.c_str() ); return CE_Failure; } // search for metadata file CPLString soMetadatafile; for( int i = 0; papszFiles[i] != NULL; i++ ) { if( EQUAL(papszFiles[i],".") || EQUAL(papszFiles[i],"..") ) continue; if( EQUAL(CPLGetBasename(papszFiles[i]), GNM_SYSLAYER_META) ) { soMetadatafile = CPLFormFilename(m_soNetworkFullName, papszFiles[i], NULL); break; } } CSLDestroy( papszFiles ); m_pMetadataDS = (GDALDataset*) GDALOpenEx( soMetadatafile, GDAL_OF_VECTOR | GDAL_OF_UPDATE, NULL, NULL, NULL ); if( NULL == m_pMetadataDS ) { CPLError( CE_Failure, CPLE_OpenFailed, "Open '%s' file failed", m_soNetworkFullName.c_str() ); return CE_Failure; } if(LoadMetadataLayer(m_pMetadataDS) != CE_None) { return CE_Failure; } m_poLayerDriver = m_pMetadataDS->GetDriver(); const char* pszExt = CPLGetExtension(soMetadatafile); CPLString soGraphfile = CPLFormFilename(m_soNetworkFullName, GNM_SYSLAYER_GRAPH, pszExt); m_pGraphDS = (GDALDataset*) GDALOpenEx( soGraphfile, GDAL_OF_VECTOR | GDAL_OF_UPDATE, NULL, NULL, NULL ); if( NULL == m_pGraphDS ) { CPLError( CE_Failure, CPLE_OpenFailed, "Open '%s' file failed", m_soNetworkFullName.c_str() ); return CE_Failure; } if(LoadGraphLayer(m_pGraphDS) != CE_None) { return CE_Failure; } CPLString soFeaturesfile = CPLFormFilename(m_soNetworkFullName, GNM_SYSLAYER_FEATURES, pszExt); m_pFeaturesDS = (GDALDataset*) GDALOpenEx( soFeaturesfile, GDAL_OF_VECTOR | GDAL_OF_UPDATE, NULL, NULL, NULL ); if( NULL == m_pFeaturesDS ) { CPLError( CE_Failure, CPLE_OpenFailed, "Open '%s' file failed", m_soNetworkFullName.c_str() ); return CE_Failure; } if(LoadFeaturesLayer(m_pFeaturesDS) != CE_None) { return CE_Failure; } return CE_None; }