OGRLayer *GNMDatabaseNetwork::ICreateLayer(const char *pszName, CPL_UNUSED OGRSpatialReference *poSpatialRef, OGRwkbGeometryType eGType, char **papszOptions) { //check if layer with such name exist for(int i = 0; i < GetLayerCount(); ++i) { OGRLayer* pLayer = GetLayer(i); if(NULL == pLayer) continue; if(EQUAL(pLayer->GetName(), pszName)) { CPLError( CE_Failure, CPLE_IllegalArg, "The network layer '%s' already exist.", pszName ); return NULL; } } OGRSpatialReference oSpaRef(m_soSRS); OGRLayer *poLayer = m_poDS->CreateLayer( pszName, &oSpaRef, eGType, papszOptions ); if( poLayer == NULL ) { CPLError( CE_Failure, CPLE_FileIO, "Layer creation failed." ); return NULL; } OGRFieldDefn oField( GNM_SYSFIELD_GFID, GNMGFIDInt ); if( poLayer->CreateField( &oField ) != OGRERR_NONE ) { CPLError( CE_Failure, CPLE_FileIO, "Creating global identificator field failed." ); return NULL; } OGRFieldDefn oFieldBlock(GNM_SYSFIELD_BLOCKED, OFTInteger); if( poLayer->CreateField( &oFieldBlock ) != OGRERR_NONE ) { CPLError( CE_Failure, CPLE_FileIO, "Creating is blocking field failed." ); return NULL; } GNMGenericLayer* pGNMLayer = new GNMGenericLayer(poLayer, this); m_apoLayers.push_back(pGNMLayer); return pGNMLayer; }
OGRLayer *GNMFileNetwork::ICreateLayer(const char *pszName, CPL_UNUSED OGRSpatialReference *poSpatialRef, OGRwkbGeometryType eGType, char **papszOptions) { if(NULL == m_poLayerDriver) { CPLError( CE_Failure, CPLE_AppDefined, "The network storage format driver is not defined." ); return NULL; } //check if layer with such name exist for(int i = 0; i < GetLayerCount(); ++i) { OGRLayer* pLayer = GetLayer(i); if(NULL == pLayer) continue; if(EQUAL(pLayer->GetName(), pszName)) { CPLError( CE_Failure, CPLE_IllegalArg, "The network layer '%s' already exist.", pszName ); return NULL; } } //form path const char* pszExt = m_poLayerDriver->GetMetadataItem(GDAL_DMD_EXTENSION); CPLString soPath = CPLFormFilename(m_soNetworkFullName, pszName ,pszExt); GDALDataset *poDS = m_poLayerDriver->Create( soPath, 0, 0, 0, GDT_Unknown, papszOptions ); if( poDS == NULL ) { CPLError( CE_Failure, CPLE_FileIO, "Creation of output file failed." ); return NULL; } OGRSpatialReference oSpaRef(m_soSRS); OGRLayer *poLayer = poDS->CreateLayer( pszName, &oSpaRef, eGType, papszOptions ); if( poLayer == NULL ) { CPLError( CE_Failure, CPLE_FileIO, "Layer creation failed." ); GDALClose(poDS); return NULL; } OGRFieldDefn oField( GNM_SYSFIELD_GFID, GNMGFIDInt ); if( poLayer->CreateField( &oField ) != OGRERR_NONE ) { CPLError( CE_Failure, CPLE_FileIO, "Creating global identificator field failed." ); GDALClose(poDS); return NULL; } OGRFieldDefn oFieldBlock(GNM_SYSFIELD_BLOCKED, OFTInteger); if( poLayer->CreateField( &oFieldBlock ) != OGRERR_NONE ) { CPLError( CE_Failure, CPLE_FileIO, "Creating is blocking field failed." ); GDALClose(poDS); return NULL; } GNMGenericLayer* pGNMLayer = new GNMGenericLayer(poLayer, this); m_apoLayers.push_back(pGNMLayer); m_mpLayerDatasetMap[pGNMLayer] = poDS; return pGNMLayer; }